diff options
| author | bors <bors@rust-lang.org> | 2024-11-24 23:17:56 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-11-24 23:17:56 +0000 |
| commit | 28fc2ba7142654fa6e654926f96ff913027b200e (patch) | |
| tree | 47ce907833aa4d4b770a5bb17ee0ebeac61b1c68 /library/std/src/sys/sync/once | |
| parent | 481b5fadd7994d0f04e9a6fe9ded3f22d6753825 (diff) | |
| parent | c50e19b69cf7f26fcd289c32a4f69adda5bc9470 (diff) | |
| download | rust-28fc2ba7142654fa6e654926f96ff913027b200e.tar.gz rust-28fc2ba7142654fa6e654926f96ff913027b200e.zip | |
Auto merge of #133423 - jieyouxu:rollup-m3gyoz6, r=jieyouxu
Rollup of 6 pull requests Successful merges: - #132730 (std: allow after-main use of synchronization primitives) - #133105 (only store valid proc macro item for doc link) - #133260 (Constify the `Deref`/`DerefMut` traits, too) - #133297 (Remove legacy bitcode for iOS) - #133298 (Mention that std::fs::remove_dir_all fails on files) - #133384 (add a test for target-feature-ABI warnings in closures and when calling extern fn) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/sys/sync/once')
| -rw-r--r-- | library/std/src/sys/sync/once/queue.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/library/std/src/sys/sync/once/queue.rs b/library/std/src/sys/sync/once/queue.rs index 177d0d7744a..87837915b39 100644 --- a/library/std/src/sys/sync/once/queue.rs +++ b/library/std/src/sys/sync/once/queue.rs @@ -93,7 +93,7 @@ const QUEUE_MASK: usize = !STATE_MASK; // use interior mutability. #[repr(align(4))] // Ensure the two lower bits are free to use as state bits. struct Waiter { - thread: Cell<Option<Thread>>, + thread: Thread, signaled: AtomicBool, next: Cell<*const Waiter>, } @@ -238,7 +238,7 @@ fn wait( return_on_poisoned: bool, ) -> StateAndQueue { let node = &Waiter { - thread: Cell::new(Some(thread::current())), + thread: thread::current_or_unnamed(), signaled: AtomicBool::new(false), next: Cell::new(ptr::null()), }; @@ -277,7 +277,8 @@ fn wait( // can park ourselves, the result could be this thread never gets // unparked. Luckily `park` comes with the guarantee that if it got // an `unpark` just before on an unparked thread it does not park. - thread::park(); + // SAFETY: we retrieved this handle on the current thread above. + unsafe { node.thread.park() } } return state_and_queue.load(Acquire); @@ -309,7 +310,7 @@ impl Drop for WaiterQueue<'_> { let mut queue = to_queue(current); while !queue.is_null() { let next = (*queue).next.get(); - let thread = (*queue).thread.take().unwrap(); + let thread = (*queue).thread.clone(); (*queue).signaled.store(true, Release); thread.unpark(); queue = next; |
