@@ -81,7 +81,7 @@ pub struct Once {
81
81
// `state_and_queue` is actually an a pointer to a `Waiter` with extra state
82
82
// bits, so we add the `PhantomData` appropriately.
83
83
state_and_queue : AtomicUsize ,
84
- _marker : marker:: PhantomData < * mut Waiter > ,
84
+ _marker : marker:: PhantomData < * const Waiter > ,
85
85
}
86
86
87
87
// The `PhantomData` of a raw pointer removes these two auto traits, but we
@@ -134,9 +134,9 @@ const STATE_MASK: usize = 0x3;
134
134
135
135
// Representation of a node in the linked list of waiters in the RUNNING state.
136
136
struct Waiter {
137
- thread : Option < Thread > ,
137
+ thread : Thread ,
138
138
signaled : AtomicBool ,
139
- next : * mut Waiter ,
139
+ next : * const Waiter ,
140
140
}
141
141
142
142
// Helper struct used to clean up after a closure call with a `Drop`
@@ -404,11 +404,11 @@ impl Once {
404
404
// Create the node for our current thread that we are going to try to slot
405
405
// in at the head of the linked list.
406
406
let mut node = Waiter {
407
- thread : Some ( thread:: current ( ) ) ,
407
+ thread : thread:: current ( ) ,
408
408
signaled : AtomicBool :: new ( false ) ,
409
- next : ptr:: null_mut ( ) ,
409
+ next : ptr:: null ( ) ,
410
410
} ;
411
- let me = & mut node as * mut Waiter as usize ;
411
+ let me = & node as * const Waiter as usize ;
412
412
assert ! ( me & STATE_MASK == 0 ) ; // We assume pointers have 2 free bits that
413
413
// we can use for state.
414
414
@@ -421,7 +421,7 @@ impl Once {
421
421
return ; // No need anymore to enqueue ourselves.
422
422
}
423
423
424
- node. next = ( old_head_and_status & !STATE_MASK ) as * mut Waiter ;
424
+ node. next = ( old_head_and_status & !STATE_MASK ) as * const Waiter ;
425
425
let old = self . state_and_queue . compare_and_swap ( old_head_and_status,
426
426
me | RUNNING ,
427
427
Ordering :: Release ) ;
@@ -469,10 +469,10 @@ impl Drop for Finish<'_> {
469
469
// in the node it can be free'd! As a result we load the `thread` to
470
470
// signal ahead of time and then unpark it after the store.
471
471
unsafe {
472
- let mut queue = ( state_and_queue & !STATE_MASK ) as * mut Waiter ;
472
+ let mut queue = ( state_and_queue & !STATE_MASK ) as * const Waiter ;
473
473
while !queue. is_null ( ) {
474
474
let next = ( * queue) . next ;
475
- let thread = ( * queue) . thread . take ( ) . unwrap ( ) ;
475
+ let thread = ( * queue) . thread . clone ( ) ;
476
476
( * queue) . signaled . store ( true , Ordering :: SeqCst ) ;
477
477
thread. unpark ( ) ;
478
478
queue = next;
0 commit comments