-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use std::shared_ptr
for gz::transport::NodeShared
#484
Use std::shared_ptr
for gz::transport::NodeShared
#484
Conversation
Signed-off-by: Addisu Z. Taddese <[email protected]>
Currently, `NodeShared` is never destroyed once it's created. This makes it hard for writing tests that do not interfere with each other. This patch uses a reference counted smart pointer (`std::shared_ptr`) to keep track of `NodeShared` instances, so that it gets properly destroyed when when all `Node` instances, which themselves contain `NodeShared` instances are destroyed. Signed-off-by: Addisu Z. Taddese <[email protected]>
`Node::Shared` is a private function but it's used in `details/Node.hh` in templates which means there could be calls to `Node::Shared` embedded in other libraries. Since we're mainly tracking the number of `Node` instances, and since `Node::Shared` is private, it's okay to use raw pointers internal use. Signed-off-by: Addisu Z. Taddese <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## gz-transport13 #484 +/- ##
==================================================
+ Coverage 87.69% 87.85% +0.16%
==================================================
Files 59 59
Lines 5704 5708 +4
==================================================
+ Hits 5002 5015 +13
+ Misses 702 693 -9 ☔ View full report in Codecov by Sentry. |
Signed-off-by: Addisu Z. Taddese <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the approach looks good to me.
Maybe @caguero can take a look as well and see if you are ok with this.
…sim#484)" This reverts commit 42e4210. Signed-off-by: Addisu Z. Taddese <[email protected]>
This reverts commit 42e4210. Signed-off-by: Addisu Z. Taddese <[email protected]>
🦟 Bug fix
Summary
Currently,
NodeShared
is never destroyed once it's created. This makesit hard for writing tests that do not interfere with each other. This
patch uses a reference counted smart pointer (
std::shared_ptr
) to keeptrack of
NodeShared
instances, so that it gets properly destroyed whenwhen all
Node
instances, which themselves containNodeShared
instances are destroyed.
This was brought up in gazebosim/gz-sim#2334. The
INTEGRATION_triggered_publisher
test fails reliably in my local tests without this gz-transport PR.TODO: This is probably not threadsafe. It's possible to lock a mutex before checking the weak_ptr, but that would make the call toNodeSHared::Instance
slower than the previous implementation since it was usingstd::shared_mutex
.Checklist
codecheck
passed (See contributing)Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-by
messages.