Skip to content

Commit

Permalink
Merge pull request #4587 from mitza-oci/master
Browse files Browse the repository at this point in the history
boottime timers: support one-shot timers with zero delay
  • Loading branch information
jrw972 committed Apr 16, 2024
2 parents 47133ba + 4545556 commit 284f738
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion dds/DCPS/Timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ TimerId schedule(ACE_Reactor* reactor,
}
itimerspec ts;
ts.it_interval = interval.value();
ts.it_value = (delay == TimeDuration()) ? interval.value() : delay.value();
if (delay == TimeDuration()) {
// avoid zeros since that would disarm the timer
// if the interval is positive, use that as the initial expiration
static const timespec one = {0, 1};
ts.it_value = (interval == TimeDuration()) ? one : interval.value();
} else {
ts.it_value = delay.value();
}
if (timerfd_settime(fd, 0, &ts, 0) == -1) {
if (log_level >= LogLevel::Notice) {
ACE_ERROR((LM_NOTICE, "(%P|%t) NOTICE: Timers::schedule: timerfd_settime %m\n"));
Expand Down
15 changes: 15 additions & 0 deletions tests/unit-tests/dds/DCPS/Timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,18 @@ TEST(dds_DCPS_Timers, test_repeat)
ASSERT_GT(handler->calls_, 10);
Timers::cancel(&reactor, id);
}

TEST(dds_DCPS_Timers, test_immediate)
{
RcHandle<TestEventHandler> handler = make_rch<TestEventHandler>();
ACE_Reactor reactor(new ACE_Select_Reactor, true);

const Timers::TimerId id = Timers::schedule(&reactor, *handler, 0, TimeDuration(), TimeDuration());
ASSERT_NE(id, Timers::InvalidTimerId);

ACE_Time_Value one_sec(1);
reactor.handle_events(one_sec);

ASSERT_EQ(handler->calls_, 1);
Timers::cancel(&reactor, id);
}

0 comments on commit 284f738

Please sign in to comment.