modm-io / modm

modm: a C++23 library generator for AVR and ARM Cortex-M devices
https://modm.io
Mozilla Public License 2.0
748 stars 132 forks source link

[fiber] Improve timing of poll functions #1196

Closed salkinium closed 2 months ago

salkinium commented 2 months ago

There are two problems with the poll functions:

  1. Calling sleep_for with nanoseconds (or less) durations would be cast to 0us or 0ms. This is now fixed by making the duration at least 1us or 1ms. (cc @TomSaw)
  2. The condition was not checked again after a yield, thus can time out if the yield takes longer. The correct behavior should check the function upon entry of the poll for a fast exit and then again after each yield before checking the timeout.
  3. Fix infinite loop when passing 0s as sleep time, whoops. Now it only yields once.