@@ -80,25 +80,28 @@ unsafe impl Send for rcl_guard_condition_t {}
80
80
impl GuardCondition {
81
81
/// Creates a new guard condition with no callback.
82
82
pub fn new ( context : & Context ) -> Self {
83
- Self :: new_with_rcl_context ( & mut context. rcl_context_mtx . lock ( ) . unwrap ( ) , None :: < fn ( ) > )
83
+ Self :: new_with_rcl_context ( & mut context. rcl_context_mtx . lock ( ) . unwrap ( ) , None )
84
84
}
85
85
86
86
/// Creates a new guard condition with a callback.
87
87
pub fn new_with_callback < F > ( context : & Context , callback : F ) -> Self
88
88
where
89
89
F : Fn ( ) + Send + Sync + ' static ,
90
90
{
91
- Self :: new_with_rcl_context ( & mut context. rcl_context_mtx . lock ( ) . unwrap ( ) , Some ( callback) )
91
+ Self :: new_with_rcl_context (
92
+ & mut context. rcl_context_mtx . lock ( ) . unwrap ( ) ,
93
+ Some ( Box :: new ( callback) as Box < dyn Fn ( ) + Send + Sync > ) ,
94
+ )
92
95
}
93
96
94
97
/// Creates a new guard condition by providing the rcl_context_t and an optional callback.
95
98
/// Note this function enables calling `Node::create_guard_condition`[1] without providing the Context separately
96
99
///
97
100
/// [1]: Node::create_guard_condition
98
- pub ( crate ) fn new_with_rcl_context < F > ( context : & mut rcl_context_t , callback : Option < F > ) -> Self
99
- where
100
- F : Fn ( ) + Send + Sync + ' static ,
101
- {
101
+ pub ( crate ) fn new_with_rcl_context (
102
+ context : & mut rcl_context_t ,
103
+ callback : Option < Box < dyn Fn ( ) + Send + Sync > > ,
104
+ ) -> Self {
102
105
// SAFETY: Getting a zero initialized value is always safe
103
106
let mut guard_condition = unsafe { rcl_get_zero_initialized_guard_condition ( ) } ;
104
107
unsafe {
@@ -112,7 +115,7 @@ impl GuardCondition {
112
115
113
116
Self {
114
117
rcl_guard_condition : Mutex :: new ( guard_condition) ,
115
- callback : callback . map ( |f| Box :: new ( f ) as Box < dyn Fn ( ) + Send + Sync > ) ,
118
+ callback,
116
119
in_use_by_wait_set : Arc :: new ( AtomicBool :: new ( false ) ) ,
117
120
}
118
121
}
0 commit comments