ETLCPP / etl

Embedded Template Library
https://www.etlcpp.com
MIT License
2.25k stars 393 forks source link

Feature request: deferred timers #952

Open KammutierSpule opened 2 months ago

KammutierSpule commented 2 months ago

Current situation: The existent timers do not allow changes on timer (i.e: call timer functions, due design and mutex protection) while handling the expired callbacks, on tick(). Also it is expected to be real-time (callbacks handlers should run as fast as possible) as the timeout callback will be called inside the tick update, so other timers will not suffer from delays.

Feature request: to implement a timer that create a queue of delegates on the tick update and a method to allow later pop from that queue. Bonus: Implement another version with priority_queue

Pseudo code:

On_Tick() {
bool anyTimeExpired = timer.tick( elapsed_time_ms );
  if (anyTimeExpired) {
    OS_Notify_DeferedWorker_Task();
  }
}

DeferedWorker_Task() {
  while(1) {
    OS_Wait_Notification();
    timer.HandleDeferred();
  }
}

Do you see any disadvantage (other of no-realtime deferred issue) of this solution? Would it work?