-
Notifications
You must be signed in to change notification settings - Fork 36
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
Thread-safe access to SubscriptionData #288
Conversation
619b33f
to
71bbb6a
Compare
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.
This generally looks good. I've left some things to improved, and it needs to be rebased. Once those are done, I'll run some more extensive tests on it.
@@ -69,12 +69,14 @@ rmw_publisher_event_init( | |||
rmw_event->event_type = event_type; | |||
|
|||
// Register the event with graph cache. | |||
std::weak_ptr<rmw_zenoh_cpp::PublisherData> data_wp = pub_data; |
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.
Is this a separate bugfix?
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 with capturing the weak_ptr
ensures that if the event callback executes for some reason after the last reference to PublisherData::SharedPtr
goes out of scope, we would safely exit the callback. This is what I want to do with some of the Zenoh callbacks as well once we switch to zenoh-cpp
.
I would have liked to also do it within rmw_subscription_event_init
but given that we're storing the raw_ptr
to SubscriptionData
in rmw_subscription_t->data
and hence not able to retrieve the shared_ptr to the same, we are stuck with potential to dereference a dangling pointer if the scenario above. But this scenario should never occur given the implementation of rcl*
Signed-off-by: Yadunund <yadunund@intrinsic.ai>
…imitation Signed-off-by: Yadunund <yadunund@intrinsic.ai>
Signed-off-by: Yadunund <yadunund@intrinsic.ai>
00a7ce6
to
a4d985e
Compare
Signed-off-by: Yadunund <yadunund@intrinsic.ai>
e8ad4f4
to
f8ea0c3
Compare
rmw_zenoh/yadu/raii-sub
There are some new segfaults
|
This generally looks good to me, and passes my tests locally. We should fix the failing |
Signed-off-by: Yadunund <yadunund@intrinsic.ai>
Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com> Signed-off-by: yadunund <yadunund@gmail.com>
This PR introduces SubscriptionData class that manages the lifetime of Zenoh artifacts. It makes access to class members thread-safe where possible. Some z_closure callbacks still work with type erased raw ptrs but this will be addressed when we migrate to zenoh-cpp.
It seems like it is not feasible to store rmw_node_t * as type erased void * in rmw_subscription_t->data like we did with rmw_publisher_t->data .
The problem is that because rmw_subscriptions_t in rmw_wait contains an array of the type erased subscriptions handles (ie, rmw_subscription_t->data ), there is no way to get the SubscriptionData::SharedPtr here
rmw_zenoh/rmw_zenoh_cpp/src/rmw_zenoh.cpp
Lines 3220 to 3221 in cf8e8a2
The only option we have is storing a rawptr to SubscriptionData in rmw_subscription_t->data but leads to the risk of it becoming a dangling pointer when the SubscriptionData::SharedPtr is deleted.