diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-02-06 18:05:22 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-02-06 18:05:22 +0000 |
| commit | ba18656e94ceffc3fe10a7c47c9b93a1d9d4b2d6 (patch) | |
| tree | ba8725a94883b6e1f7a540d11010f75a0f0ed666 /examples/boot/bootloader | |
| parent | c8a7b74bc2c10d7c4da18b4cfdb08f5e28abf71e (diff) | |
| parent | 34b67fe1372c535a659590744242cd4ffd52dfb6 (diff) | |
Merge #1177
1177: STD driver needs a reentrant mutex; logic fixed to be reentrancy-safe r=Dirbaio a=ivmarkov
...or to summarize it in another way, the code in the alarm thread loop is written as if - when calling the user-supplied callback - the callback will *never, ever* call `alarm.set_alarm()`.
But this happens of course - at least with the generic timer queue implementation. Not sure if that would happen with `embassy-executor`'s own queue, but probably yes?
The end result on Linux is that the code deadlocks because when calling the user-supplied callback, the mutex of the alarms is locked, yet - the code in `set_alarm` tries to take the lock again leading to UB. (I suspect on Windows this will crash rather than deadlock but that's a bit irrelevant.)
(Note also that calling the user-supplied callback *outside* of the alarms' lock is also NOK, because at that time, the callback and/or context itself might be invalid as well, as the user might had changed it with a new one by calling `set_callback`. Right?)
I also had to fix the logic that computed the next timestamp when the alarm should fire; it was running a simple `for {}` loop, not anticipating that the just-traversed alarm might get a new timestamp.
The new code is slightly less efficient, in that on each `loop {}` iteration it always starts traversing the alarms from the beginning, whereas in reality only the timestamp of the alarm that just-fired could've changed, but given the complexities introduced by `RefCell`, I don't think we should bother with these micro-optimizations, for just 4 alarms in total.
Co-authored-by: ivmarkov <[email protected]>
Diffstat (limited to 'examples/boot/bootloader')
0 files changed, 0 insertions, 0 deletions
