@@ -78,6 +78,9 @@ pub struct TimerState<Scope: WorkScope> {
78
78
/// before we can get the lifecycle handle.
79
79
#[ allow( unused) ]
80
80
lifecycle : Mutex < Option < WaitableLifecycle > > ,
81
+ /// We optionally hold onto a live node if the timer is depending on node time.
82
+ #[ allow( unused) ]
83
+ node : Option < Node > ,
81
84
_ignore : std:: marker:: PhantomData < Scope > ,
82
85
}
83
86
@@ -115,7 +118,8 @@ impl<Scope: WorkScope> TimerState<Scope> {
115
118
// function call is thread-safe and only requires a valid rcl_timer
116
119
// to be passed in.
117
120
rcl_timer_cancel ( & mut * rcl_timer)
118
- } . ok ( ) ?;
121
+ }
122
+ . ok ( ) ?;
119
123
Ok ( cancel_result)
120
124
}
121
125
@@ -198,7 +202,8 @@ impl<Scope: WorkScope> TimerState<Scope> {
198
202
// function call is thread-safe and only requires a valid rcl_timer
199
203
// to be passed in.
200
204
rcl_timer_reset ( & mut * rcl_timer)
201
- } . ok ( )
205
+ }
206
+ . ok ( )
202
207
}
203
208
204
209
/// Checks if the timer is ready (not canceled)
@@ -257,18 +262,17 @@ impl<Scope: WorkScope> TimerState<Scope> {
257
262
callback : AnyTimerCallback < Scope > ,
258
263
commands : & Arc < WorkerCommands > ,
259
264
context : & ContextHandle ,
265
+ node : Option < Node > ,
260
266
) -> Result < Arc < Self > , RclrsError > {
261
267
let period = period. as_nanos ( ) as i64 ;
262
268
263
269
// Callbacks will be handled at the rclrs layer.
264
270
let rcl_timer_callback: rcl_timer_callback_t = None ;
265
271
266
- let rcl_timer = Arc :: new ( Mutex :: new (
267
- unsafe {
268
- // SAFETY: Zero-initializing a timer is always safe
269
- rcl_get_zero_initialized_timer ( )
270
- } ,
271
- ) ) ;
272
+ let rcl_timer = Arc :: new ( Mutex :: new ( unsafe {
273
+ // SAFETY: Zero-initializing a timer is always safe
274
+ rcl_get_zero_initialized_timer ( )
275
+ } ) ) ;
272
276
273
277
unsafe {
274
278
let mut rcl_clock = clock. get_rcl_clock ( ) . lock ( ) . unwrap ( ) ;
@@ -321,6 +325,7 @@ impl<Scope: WorkScope> TimerState<Scope> {
321
325
callback : Mutex :: new ( Some ( callback) ) ,
322
326
last_elapse : Mutex :: new ( Duration :: ZERO ) ,
323
327
lifecycle : Mutex :: default ( ) ,
328
+ node,
324
329
_ignore : Default :: default ( ) ,
325
330
} ) ;
326
331
@@ -400,7 +405,8 @@ impl<Scope: WorkScope> TimerState<Scope> {
400
405
// function call is thread-safe and only requires a valid rcl_timer
401
406
// to be passed in.
402
407
rcl_timer_call ( & mut * rcl_timer)
403
- } . ok ( )
408
+ }
409
+ . ok ( )
404
410
}
405
411
406
412
/// Used by [`Timer::execute`] to restore the state of the callback if and
@@ -570,6 +576,7 @@ mod tests {
570
576
( || { } ) . into_node_timer_repeating_callback ( ) ,
571
577
executor. commands ( ) . async_worker_commands ( ) ,
572
578
& executor. commands ( ) . context ( ) . handle ,
579
+ None ,
573
580
) ;
574
581
assert ! ( result. is_ok( ) ) ;
575
582
}
@@ -583,6 +590,7 @@ mod tests {
583
590
( || { } ) . into_node_timer_repeating_callback ( ) ,
584
591
executor. commands ( ) . async_worker_commands ( ) ,
585
592
& executor. commands ( ) . context ( ) . handle ,
593
+ None ,
586
594
) ;
587
595
assert ! ( result. is_ok( ) ) ;
588
596
}
@@ -605,6 +613,7 @@ mod tests {
605
613
( || { } ) . into_node_timer_repeating_callback ( ) ,
606
614
executor. commands ( ) . async_worker_commands ( ) ,
607
615
& executor. commands ( ) . context ( ) . handle ,
616
+ None ,
608
617
) ;
609
618
assert ! ( result. is_ok( ) ) ;
610
619
}
@@ -621,6 +630,7 @@ mod tests {
621
630
( || { } ) . into_node_timer_repeating_callback ( ) ,
622
631
executor. commands ( ) . async_worker_commands ( ) ,
623
632
& executor. commands ( ) . context ( ) . handle ,
633
+ None ,
624
634
) ;
625
635
626
636
let timer = result. unwrap ( ) ;
@@ -638,6 +648,7 @@ mod tests {
638
648
( || { } ) . into_node_timer_repeating_callback ( ) ,
639
649
executor. commands ( ) . async_worker_commands ( ) ,
640
650
& executor. commands ( ) . context ( ) . handle ,
651
+ None ,
641
652
) ;
642
653
643
654
let timer = result. unwrap ( ) ;
@@ -656,6 +667,7 @@ mod tests {
656
667
( || { } ) . into_node_timer_repeating_callback ( ) ,
657
668
executor. commands ( ) . async_worker_commands ( ) ,
658
669
& executor. commands ( ) . context ( ) . handle ,
670
+ None ,
659
671
) ;
660
672
let timer = result. unwrap ( ) ;
661
673
@@ -682,6 +694,7 @@ mod tests {
682
694
( || { } ) . into_node_timer_repeating_callback ( ) ,
683
695
executor. commands ( ) . async_worker_commands ( ) ,
684
696
& executor. commands ( ) . context ( ) . handle ,
697
+ None ,
685
698
) ;
686
699
let timer = result. unwrap ( ) ;
687
700
@@ -704,6 +717,7 @@ mod tests {
704
717
( || { } ) . into_node_timer_repeating_callback ( ) ,
705
718
executor. commands ( ) . async_worker_commands ( ) ,
706
719
& executor. commands ( ) . context ( ) . handle ,
720
+ None ,
707
721
)
708
722
. unwrap ( ) ;
709
723
@@ -735,6 +749,7 @@ mod tests {
735
749
( || { } ) . into_node_timer_repeating_callback ( ) ,
736
750
executor. commands ( ) . async_worker_commands ( ) ,
737
751
& executor. commands ( ) . context ( ) . handle ,
752
+ None ,
738
753
)
739
754
. unwrap ( ) ;
740
755
@@ -766,6 +781,7 @@ mod tests {
766
781
( || { } ) . into_node_timer_repeating_callback ( ) ,
767
782
executor. commands ( ) . async_worker_commands ( ) ,
768
783
& executor. commands ( ) . context ( ) . handle ,
784
+ None ,
769
785
)
770
786
. unwrap ( ) ;
771
787
@@ -791,6 +807,7 @@ mod tests {
791
807
create_timer_callback_for_testing ( initial_time, Arc :: clone ( & executed) ) ,
792
808
executor. commands ( ) . async_worker_commands ( ) ,
793
809
& executor. commands ( ) . context ( ) . handle ,
810
+ None ,
794
811
)
795
812
. unwrap ( ) ;
796
813
@@ -812,6 +829,7 @@ mod tests {
812
829
create_timer_callback_for_testing ( initial_time, Arc :: clone ( & executed) ) ,
813
830
executor. commands ( ) . async_worker_commands ( ) ,
814
831
& executor. commands ( ) . context ( ) . handle ,
832
+ None ,
815
833
)
816
834
. unwrap ( ) ;
817
835
@@ -841,6 +859,7 @@ mod tests {
841
859
create_timer_callback_for_testing ( initial_time, Arc :: clone ( & executed) ) ,
842
860
executor. commands ( ) . async_worker_commands ( ) ,
843
861
& executor. commands ( ) . context ( ) . handle ,
862
+ None ,
844
863
)
845
864
. unwrap ( ) ;
846
865
0 commit comments