diff options
| author | Paul Dicker <pitdicker@gmail.com> | 2019-10-23 09:56:41 +0200 |
|---|---|---|
| committer | Paul Dicker <pitdicker@gmail.com> | 2019-10-23 16:38:50 +0200 |
| commit | 1479c22a390a6b95706d4280cd7be24e4410dc77 (patch) | |
| tree | a080d9f6d67bdf0b9bf28e680dd97d1958bbee9e /src/libstd/sync | |
| parent | 7f1e166899a90226480d564549c36a395e2d8f47 (diff) | |
| download | rust-1479c22a390a6b95706d4280cd7be24e4410dc77.tar.gz rust-1479c22a390a6b95706d4280cd7be24e4410dc77.zip | |
Don't mutate waiter nodes
Diffstat (limited to 'src/libstd/sync')
| -rw-r--r-- | src/libstd/sync/once.rs | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs index 7a660daf2cb..d8565e55ab2 100644 --- a/src/libstd/sync/once.rs +++ b/src/libstd/sync/once.rs @@ -81,7 +81,7 @@ pub struct Once { // `state_and_queue` is actually an a pointer to a `Waiter` with extra state // bits, so we add the `PhantomData` appropriately. state_and_queue: AtomicUsize, - _marker: marker::PhantomData<*mut Waiter>, + _marker: marker::PhantomData<*const Waiter>, } // The `PhantomData` of a raw pointer removes these two auto traits, but we @@ -134,9 +134,9 @@ const STATE_MASK: usize = 0x3; // Representation of a node in the linked list of waiters in the RUNNING state. struct Waiter { - thread: Option<Thread>, + thread: Thread, signaled: AtomicBool, - next: *mut Waiter, + next: *const Waiter, } // Helper struct used to clean up after a closure call with a `Drop` @@ -404,11 +404,11 @@ impl Once { // Create the node for our current thread that we are going to try to slot // in at the head of the linked list. let mut node = Waiter { - thread: Some(thread::current()), + thread: thread::current(), signaled: AtomicBool::new(false), - next: ptr::null_mut(), + next: ptr::null(), }; - let me = &mut node as *mut Waiter as usize; + let me = &node as *const Waiter as usize; assert!(me & STATE_MASK == 0); // We assume pointers have 2 free bits that // we can use for state. @@ -421,7 +421,7 @@ impl Once { return; // No need anymore to enqueue ourselves. } - node.next = (old_head_and_status & !STATE_MASK) as *mut Waiter; + node.next = (old_head_and_status & !STATE_MASK) as *const Waiter; let old = self.state_and_queue.compare_and_swap(old_head_and_status, me | RUNNING, Ordering::Release); @@ -469,10 +469,10 @@ impl Drop for Finish<'_> { // in the node it can be free'd! As a result we load the `thread` to // signal ahead of time and then unpark it after the store. unsafe { - let mut queue = (state_and_queue & !STATE_MASK) as *mut Waiter; + let mut queue = (state_and_queue & !STATE_MASK) as *const Waiter; while !queue.is_null() { let next = (*queue).next; - let thread = (*queue).thread.take().unwrap(); + let thread = (*queue).thread.clone(); (*queue).signaled.store(true, Ordering::SeqCst); thread.unpark(); queue = next; |
