Skip to content

Commit 7ad4ece

Browse files
committed
Fix compatibility with kilted and rolling
Signed-off-by: Michael X. Grey <[email protected]>
1 parent c9c2127 commit 7ad4ece

File tree

1 file changed

+35
-10
lines changed

1 file changed

+35
-10
lines changed

rclrs/src/timer.rs

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,41 @@ impl<Scope: WorkScope> TimerState<Scope> {
227227
let allocator = rcutils_get_default_allocator();
228228

229229
let _lifecycle = ENTITY_LIFECYCLE_MUTEX.lock().unwrap();
230-
// SAFETY: We lock the lifecycle mutex since rcl_timer_init is not
231-
// thread-safe.
232-
rcl_timer_init(
233-
&mut *rcl_timer.lock().unwrap(),
234-
&mut *rcl_clock,
235-
&mut *rcl_context,
236-
period,
237-
rcl_timer_callback,
238-
allocator,
239-
)
230+
231+
// The API for initializing timers changed with the kilted releaase.
232+
#[cfg(any(ros_distro = "humble", ros_distro = "jazzy"))]
233+
{
234+
// SAFETY: We lock the lifecycle mutex since rcl_timer_init is not
235+
// thread-safe.
236+
rcl_timer_init(
237+
&mut *rcl_timer.lock().unwrap(),
238+
&mut *rcl_clock,
239+
&mut *rcl_context,
240+
period,
241+
rcl_timer_callback,
242+
allocator,
243+
)
244+
}
245+
246+
// The API for initializing timers changed with the kilted releaase.
247+
// This new API allows you to opt out of automatically starting the
248+
// timer as soon as it is created. We could consider exposing this
249+
// capability to the user, but for now we are just telling it to
250+
// immediately start the timer.
251+
#[cfg(not(any(ros_distro = "humble", ros_distro = "jazzy")))]
252+
{
253+
// SAFETY: We lock the lifecycle mutex since rcl_timer_init is not
254+
// thread-safe.
255+
rcl_timer_init(
256+
&mut *rcl_timer.lock().unwrap(),
257+
&mut *rcl_clock,
258+
&mut *rcl_context,
259+
period,
260+
rcl_timer_callback,
261+
allocator,
262+
true,
263+
)
264+
}
240265
}
241266
.ok()?;
242267

0 commit comments

Comments
 (0)