@@ -15,7 +15,7 @@ use crate::rcl_bindings::*;
15
15
use crate :: {
16
16
Client , ClientBase , Clock , Context , GuardCondition , ParameterBuilder , ParameterInterface ,
17
17
ParameterVariant , Parameters , Publisher , QoSProfile , RclrsError , Service , ServiceBase ,
18
- Subscription , SubscriptionBase , SubscriptionCallback , TimeSource , ToResult ,
18
+ Subscription , SubscriptionBase , SubscriptionCallback , TimeSource , ToResult , ContextHandle ,
19
19
} ;
20
20
21
21
impl Drop for rcl_node_t {
@@ -71,18 +71,21 @@ pub struct Node {
71
71
pub ( crate ) subscriptions_mtx : Mutex < Vec < Weak < dyn SubscriptionBase > > > ,
72
72
time_source : TimeSource ,
73
73
parameter : ParameterInterface ,
74
- // Note: it's important to have those last since `drop` will be called in order of declaration
75
- // in the struct and both `TimeSource` and `ParameterInterface` contain subscriptions /
76
- // services that will fail to be dropped if the context or node is destroyed first.
77
- pub ( crate ) rcl_node_mtx : Arc < Mutex < rcl_node_t > > ,
78
- pub ( crate ) rcl_context_mtx : Arc < Mutex < rcl_context_t > > ,
74
+ pub ( crate ) rcl_node : Arc < NodeHandle > ,
75
+ }
76
+
77
+ /// This struct manages the lifetime of the rcl node, and accounts for its
78
+ /// dependency on the lifetime of its context.
79
+ pub ( crate ) struct NodeHandle {
80
+ handle : Mutex < rcl_node_t > ,
81
+ rcl_context : Arc < ContextHandle > ,
79
82
}
80
83
81
84
impl Eq for Node { }
82
85
83
86
impl PartialEq for Node {
84
87
fn eq ( & self , other : & Self ) -> bool {
85
- Arc :: ptr_eq ( & self . rcl_node_mtx , & other. rcl_node_mtx )
88
+ Arc :: ptr_eq ( & self . rcl_node , & other. rcl_node )
86
89
}
87
90
}
88
91
@@ -182,7 +185,7 @@ impl Node {
182
185
& self ,
183
186
getter : unsafe extern "C" fn ( * const rcl_node_t ) -> * const c_char ,
184
187
) -> String {
185
- unsafe { call_string_getter_with_handle ( & self . rcl_node_mtx . lock ( ) . unwrap ( ) , getter) }
188
+ unsafe { call_string_getter_with_handle ( & self . rcl_node . handle . lock ( ) . unwrap ( ) , getter) }
186
189
}
187
190
188
191
/// Creates a [`Client`][1].
0 commit comments