@@ -81,7 +81,7 @@ pub struct Once {
8181 // `state_and_queue` is actually an a pointer to a `Waiter` with extra state
8282 // bits, so we add the `PhantomData` appropriately.
8383 state_and_queue : AtomicUsize ,
84- _marker : marker:: PhantomData < * mut Waiter > ,
84+ _marker : marker:: PhantomData < * const Waiter > ,
8585}
8686
8787// The `PhantomData` of a raw pointer removes these two auto traits, but we
@@ -134,9 +134,9 @@ const STATE_MASK: usize = 0x3;
134134
135135// Representation of a node in the linked list of waiters in the RUNNING state.
136136struct Waiter {
137- thread : Option < Thread > ,
137+ thread : Thread ,
138138 signaled : AtomicBool ,
139- next : * mut Waiter ,
139+ next : * const Waiter ,
140140}
141141
142142// Helper struct used to clean up after a closure call with a `Drop`
@@ -404,11 +404,11 @@ impl Once {
404404 // Create the node for our current thread that we are going to try to slot
405405 // in at the head of the linked list.
406406 let mut node = Waiter {
407- thread : Some ( thread:: current ( ) ) ,
407+ thread : thread:: current ( ) ,
408408 signaled : AtomicBool :: new ( false ) ,
409- next : ptr:: null_mut ( ) ,
409+ next : ptr:: null ( ) ,
410410 } ;
411- let me = & mut node as * mut Waiter as usize ;
411+ let me = & node as * const Waiter as usize ;
412412 assert ! ( me & STATE_MASK == 0 ) ; // We assume pointers have 2 free bits that
413413 // we can use for state.
414414
@@ -421,7 +421,7 @@ impl Once {
421421 return ; // No need anymore to enqueue ourselves.
422422 }
423423
424- node. next = ( old_head_and_status & !STATE_MASK ) as * mut Waiter ;
424+ node. next = ( old_head_and_status & !STATE_MASK ) as * const Waiter ;
425425 let old = self . state_and_queue . compare_and_swap ( old_head_and_status,
426426 me | RUNNING ,
427427 Ordering :: Release ) ;
@@ -469,10 +469,10 @@ impl Drop for Finish<'_> {
469469 // in the node it can be free'd! As a result we load the `thread` to
470470 // signal ahead of time and then unpark it after the store.
471471 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 ;
473473 while !queue. is_null ( ) {
474474 let next = ( * queue) . next ;
475- let thread = ( * queue) . thread . take ( ) . unwrap ( ) ;
475+ let thread = ( * queue) . thread . clone ( ) ;
476476 ( * queue) . signaled . store ( true , Ordering :: SeqCst ) ;
477477 thread. unpark ( ) ;
478478 queue = next;
0 commit comments