diff options
| author | Orson Peters <orsonpeters@gmail.com> | 2025-07-13 12:37:34 +0200 |
|---|---|---|
| committer | Orson Peters <orsonpeters@gmail.com> | 2025-07-13 12:37:34 +0200 |
| commit | f041962694875c0f0a33f8a5e27fd00597042169 (patch) | |
| tree | 9b8939f436c39317287969647bd9724816169efa /library/std/src/sys/sync | |
| parent | a2d41393365df0c0c9f728de7f79b8f0d4e14ef2 (diff) | |
| download | rust-f041962694875c0f0a33f8a5e27fd00597042169.tar.gz rust-f041962694875c0f0a33f8a5e27fd00597042169.zip | |
Add comment why we use zero for COMPLETE
Diffstat (limited to 'library/std/src/sys/sync')
| -rw-r--r-- | library/std/src/sys/sync/once/futex.rs | 2 | ||||
| -rw-r--r-- | library/std/src/sys/sync/once/queue.rs | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/library/std/src/sys/sync/once/futex.rs b/library/std/src/sys/sync/once/futex.rs index 827bbf014cd..407fdcebcf5 100644 --- a/library/std/src/sys/sync/once/futex.rs +++ b/library/std/src/sys/sync/once/futex.rs @@ -17,6 +17,8 @@ const POISONED: Primitive = 2; /// so all future threads need to wait for it to finish. const RUNNING: Primitive = 1; /// Initialization has completed and all future calls should finish immediately. +/// By choosing this state as the all-zero state the `is_completed` check can be +/// a bit faster on some platforms. const COMPLETE: Primitive = 0; // An additional bit indicates whether there are waiting threads: diff --git a/library/std/src/sys/sync/once/queue.rs b/library/std/src/sys/sync/once/queue.rs index 7bebb6696a8..49e15d65f25 100644 --- a/library/std/src/sys/sync/once/queue.rs +++ b/library/std/src/sys/sync/once/queue.rs @@ -74,7 +74,8 @@ pub struct OnceState { } // Four states that a Once can be in, encoded into the lower bits of -// `state_and_queue` in the Once structure. +// `state_and_queue` in the Once structure. By choosing COMPLETE as the all-zero +// state the `is_completed` check can be a bit faster on some platforms. const INCOMPLETE: usize = 0x3; const POISONED: usize = 0x2; const RUNNING: usize = 0x1; |
