Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e0bbb74

Browse files
committedSep 6, 2022
SystemLayerImplSelect: adapt ScheduleWork impl for libev according to project-chip#22375
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. Implemented now for the CHIP_SYSTEM_CONFIG_USE_LIBEV=1 case as well.
1 parent 2f63f80 commit e0bbb74

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed
 

‎src/system/SystemLayerImplSelect.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,18 @@ 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;
256+
#endif // CHIP_SYSTEM_CONFIG_USE_DISPATCH/LIBEV
247257
#if !CHIP_SYSTEM_CONFIG_USE_LIBEV
248258
// Note: dispatch based implementation needs this as fallback, but not LIBEV (and dead code is not allowed with -Werror)
249259

0 commit comments

Comments
 (0)
Please sign in to comment.