Skip to content

Commit 3dbd37e

Browse files
committed
Fix executor timeout
Signed-off-by: Michael X. Grey <[email protected]>
1 parent 896b829 commit 3dbd37e

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

rclrs/src/executor.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -491,20 +491,16 @@ impl CreateBasicExecutor for Context {
491491
#[cfg(test)]
492492
mod tests {
493493
use crate::*;
494-
use std::time::{Duration, Instant};
494+
use std::time::Duration;
495495

496496
#[test]
497-
fn test_spin_once() {
497+
fn test_timeout() {
498498
let context = Context::default();
499499
let mut executor = context.create_basic_executor();
500-
let node = executor.create_node("spin_once").unwrap();
501-
let subscription = node.create_subscription("test", |msg: crate::vendor::example_interfaces::msg::Empty| { }).unwrap();
502-
503-
let start = Instant::now();
500+
let _node = executor.create_node(&format!("test_timeout_{}", line!())).unwrap();
504501

505502
for _ in 0..10 {
506-
println!("Spinning exeuctor: {:?}", start.elapsed());
507-
executor.spin(SpinOptions::default().timeout(Duration::from_secs(1)));
503+
executor.spin(SpinOptions::default().timeout(Duration::from_millis(1)));
508504
}
509505
}
510506
}

rclrs/src/wait_set.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,24 +115,15 @@ impl WaitSet {
115115
}
116116
};
117117

118-
dbg!(timeout_ns);
119118
// SAFETY: The comments in rcl mention "This function cannot operate on the same wait set
120119
// in multiple threads, and the wait sets may not share content."
120+
// * The we have exclusive access to rcl_wait_set because this is a
121+
// mutable borrow of WaitSet, which houses rcl_wait_set.
121122
// * We guarantee that the wait sets do not share content by funneling
122-
// the exeuctor of each primitive to one (and only one) WaitSet when
123-
// the primitive gets constructed. The primitive executors are never
124-
// allowed to transfer wait sets.
125-
// * The rcl_wait_set is kept valid by the lifecycle of the WaitSet struct.
126-
match unsafe { rcl_wait(&mut self.handle.rcl_wait_set, timeout_ns) }.ok() {
127-
Ok(_) => (),
128-
Err(error) => match error {
129-
RclrsError::RclError { code, msg } => match code {
130-
RclReturnCode::WaitSetEmpty => (),
131-
_ => return Err(RclrsError::RclError { code, msg }),
132-
},
133-
_ => return Err(error),
134-
},
135-
}
123+
// the waitable of each primitive to one (and only one) WaitSet when
124+
// the primitive gets constructed. The waitables are never allowed to
125+
// move between wait sets.
126+
let r = unsafe { rcl_wait(&mut self.handle.rcl_wait_set, timeout_ns) }.ok();
136127

137128
// Remove any waitables that are no longer being used
138129
for waitable in self.primitives.values_mut() {
@@ -164,7 +155,16 @@ impl WaitSet {
164155
);
165156
}
166157

167-
Ok(())
158+
match r {
159+
Ok(_) => Ok(()),
160+
Err(error) => match error {
161+
RclrsError::RclError { code, msg } => match code {
162+
RclReturnCode::WaitSetEmpty => Ok(()),
163+
_ => Err(RclrsError::RclError { code, msg }),
164+
},
165+
_ => Err(error),
166+
},
167+
}
168168
}
169169

170170
/// Get a count of the different kinds of entities in the wait set.

0 commit comments

Comments
 (0)