Skip to content

Commit f041962

Browse files
committed
Add comment why we use zero for COMPLETE
1 parent a2d4139 commit f041962

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

library/std/src/sys/sync/once/futex.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const POISONED: Primitive = 2;
1717
/// so all future threads need to wait for it to finish.
1818
const RUNNING: Primitive = 1;
1919
/// Initialization has completed and all future calls should finish immediately.
20+
/// By choosing this state as the all-zero state the `is_completed` check can be
21+
/// a bit faster on some platforms.
2022
const COMPLETE: Primitive = 0;
2123

2224
// An additional bit indicates whether there are waiting threads:

library/std/src/sys/sync/once/queue.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ pub struct OnceState {
7474
}
7575

7676
// Four states that a Once can be in, encoded into the lower bits of
77-
// `state_and_queue` in the Once structure.
77+
// `state_and_queue` in the Once structure. By choosing COMPLETE as the all-zero
78+
// state the `is_completed` check can be a bit faster on some platforms.
7879
const INCOMPLETE: usize = 0x3;
7980
const POISONED: usize = 0x2;
8081
const RUNNING: usize = 0x1;

0 commit comments

Comments
 (0)