Skip to content

Commit ad18d9c

Browse files
committed
SystemLayerImplSelect: CHIP_SYSTEM_CONFIG_USE_LIBEV:
This follows the rationale in project-chip#22375 about posting the same work (same callback and appstate) again should not cancel the previously scheduled instance.
1 parent 9d8d36f commit ad18d9c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/system/SystemLayerImplSelect.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,17 @@ CHIP_ERROR LayerImplSelect::ScheduleWork(TimerCompleteCallback onComplete, void
242242
return CHIP_NO_ERROR;
243243
}
244244
#elif CHIP_SYSTEM_CONFIG_USE_LIBEV
245-
// just a timer with no delay
246-
return StartTimer(Clock::Timeout(0), onComplete, appState);
245+
// schedule as timer with no delay, but do NOT cancel previous timers with same onComplete/appState!
246+
TimerList::Node * timer = mTimerPool.Create(*this, SystemClock().GetMonotonicTimestamp(), onComplete, appState);
247+
VerifyOrReturnError(timer != nullptr, CHIP_ERROR_NO_MEMORY);
248+
VerifyOrDie(mLibEvLoopP != nullptr);
249+
ev_timer_init(&timer->mLibEvTimer, &LayerImplSelect::HandleLibEvTimer, 1, 0);
250+
timer->mLibEvTimer.data = timer;
251+
auto t = Clock::Milliseconds64(0).count();
252+
ev_timer_set(&timer->mLibEvTimer, static_cast<double>(t) / 1E3, 0.);
253+
(void) mTimerList.Add(timer);
254+
ev_timer_start(mLibEvLoopP, &timer->mLibEvTimer);
255+
return CHIP_NO_ERROR;
247256
#endif // CHIP_SYSTEM_CONFIG_USE_DISPATCH/LIBEV
248257
#if !CHIP_SYSTEM_CONFIG_USE_LIBEV
249258
// Note: dispatch based implementation needs this as fallback, but not LIBEV (and dead code is not allowed with -Werror)

0 commit comments

Comments
 (0)