Skip to content

Commit

Permalink
[#533] Process callbacks immediately on zero timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
orecham committed Dec 3, 2024
1 parent 949d2e0 commit d338238
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
26 changes: 22 additions & 4 deletions iceoryx2-bb/posix/src/deadline_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,28 @@ impl DeadlineQueue {
for attachment in &*self.attachments.borrow() {
let duration_until_last = last.max(attachment.start_time) - attachment.start_time;
let duration_until_now = now - attachment.start_time;
if (duration_until_last / attachment.period) < (duration_until_now / attachment.period)
&& call(DeadlineQueueIndex(attachment.index)) == CallbackProgression::Stop
{
return;
match attachment.period {
0 => {
if matches!(
call(DeadlineQueueIndex(attachment.index)),
CallbackProgression::Stop
) {
return;
}
}
_ => {
let last_period = duration_until_last / attachment.period;
let current_period = duration_until_now / attachment.period;

if last_period < current_period
&& matches!(
call(DeadlineQueueIndex(attachment.index)),
CallbackProgression::Stop
)
{
return;
}
}
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions iceoryx2-bb/posix/tests/deadline_queue_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ mod deadline_queue {
assert_that!(sut.duration_until_next_deadline().unwrap(), eq Duration::MAX);
}

#[test]
fn next_iteration_works_zero_deadline() {
let sut = DeadlineQueueBuilder::new().create().unwrap();

let _guard = sut.add_deadline_interval(Duration::from_secs(0)).unwrap();

assert_that!(sut.duration_until_next_deadline().unwrap(), eq Duration::from_secs(0));
}

#[test]
fn next_iteration_works_smallest_deadline_added_first() {
let sut = DeadlineQueueBuilder::new().create().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2/src/port/waitset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ impl<Service: crate::service::Service> WaitSet<Service> {
mut fn_call: F,
timeout: Duration,
) -> Result<WaitSetRunResult, WaitSetRunError> {
let msg = "Unable to call WaitSet::try_wait_and_process()";
let msg = "Unable to call WaitSet::wait_and_process_once_with_timeout()";

if self.signal_handling_mode == SignalHandlingMode::HandleTerminationRequests
&& SignalHandler::termination_requested()
Expand Down

0 comments on commit d338238

Please sign in to comment.