local-waker: Add safety docs

This commit is contained in:
Nur 2026-02-01 19:31:57 +06:00
parent 8ea3b14779
commit 08c16c4597
1 changed files with 6 additions and 0 deletions

View File

@ -44,12 +44,18 @@ impl LocalWaker {
#[inline]
pub fn register(&self, waker: &Waker) -> bool {
let mut registered = false;
// SAFETY: `LocalWaker` is `!Send`, threfore this cannot be called from a separate thread.
// And this is an unique access before the assignment below.
if let Some(prev) = unsafe { &*self.waker.get() } {
if waker.will_wake(prev) {
return true;
}
registered = true;
}
// SAFETY: This can cause data races if called from a separate thread,
// but `LocalWaker` is `!Send` + `!Sync` so this won't happen.
unsafe { *self.waker.get() = Some(waker.clone()) }
registered
}