aboutsummaryrefslogtreecommitdiff
path: root/embassy-time
diff options
context:
space:
mode:
authorRobertTDowling <[email protected]>2023-12-17 15:11:03 -0800
committerRobertTDowling <[email protected]>2023-12-17 15:35:35 -0800
commitb857334f92fc188004567edb93e0d1dfce4c259e (patch)
tree78f90e470c3d477dc97b78badf321e31dfe599ce /embassy-time
parenta2d4bab2f8a4a9b994bc0289938a9f725950715f (diff)
STM32: Fix race in alarm setting, which impacted scheduling.
Detect potential race condition (should be rare) and return false back to caller, allowing them to handle the possibility that either the alarm was never set because it was in the past (old meaning of false), or that in fact the alarm was set and may have fired within the race window (new meaning of false). In either case, the caller needs to make sure the callback got called.
Diffstat (limited to 'embassy-time')
-rw-r--r--embassy-time/src/driver.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/embassy-time/src/driver.rs b/embassy-time/src/driver.rs
index 5fe7becaf..81ee1b0f5 100644
--- a/embassy-time/src/driver.rs
+++ b/embassy-time/src/driver.rs
@@ -108,6 +108,10 @@ pub trait Driver: Send + Sync + 'static {
108 /// The `Driver` implementation should guarantee that the alarm callback is never called synchronously from `set_alarm`. 108 /// The `Driver` implementation should guarantee that the alarm callback is never called synchronously from `set_alarm`.
109 /// Rather - if `timestamp` is already in the past - `false` should be returned and alarm should not be set, 109 /// Rather - if `timestamp` is already in the past - `false` should be returned and alarm should not be set,
110 /// or alternatively, the driver should return `true` and arrange to call the alarm callback as soon as possible, but not synchronously. 110 /// or alternatively, the driver should return `true` and arrange to call the alarm callback as soon as possible, but not synchronously.
111 /// There is a rare third possibility that the alarm was barely in the future, and by the time it was enabled, it had slipped into the
112 /// past. This is can be detected by double-checking that the alarm is still in the future after enabling it; if it isn't, `false`
113 /// should also be returned to indicate that the callback may have been called already by the alarm, but it is not guaranteed, so the
114 /// caller should also call the callback, just like in the more common `false` case. (Note: This requires idempotency of the callback.)
111 /// 115 ///
112 /// When callback is called, it is guaranteed that now() will return a value greater or equal than timestamp. 116 /// When callback is called, it is guaranteed that now() will return a value greater or equal than timestamp.
113 /// 117 ///