@@ -1008,7 +1008,12 @@ impl RawRwLock {
10081008 state & READERS_MASK != 0 && state & WRITER_PARKED_BIT != 0
10091009 } ;
10101010 let before_sleep = || { } ;
1011- let timed_out = |_, _| { } ;
1011+ let timed_out = |_, was_last_thread : bool | {
1012+ // Clear the parked bit while holding the queue lock. There can
1013+ // only be one thread parked (this one).
1014+ debug_assert ! ( was_last_thread) ;
1015+ self . state . fetch_and ( !WRITER_PARKED_BIT , Ordering :: Relaxed ) ;
1016+ } ;
10121017 // SAFETY:
10131018 // * `addr` is an address we control.
10141019 // * `validate`/`timed_out` does not panic or call into any function of `parking_lot`.
@@ -1037,10 +1042,9 @@ impl RawRwLock {
10371042 // We need to release WRITER_BIT and revert back to
10381043 // our previous value. We also wake up any threads that
10391044 // might be waiting on WRITER_BIT.
1040- let state = self . state . fetch_add (
1041- prev_value. wrapping_sub ( WRITER_BIT | WRITER_PARKED_BIT ) ,
1042- Ordering :: Relaxed ,
1043- ) ;
1045+ let state = self
1046+ . state
1047+ . fetch_add ( prev_value. wrapping_sub ( WRITER_BIT ) , Ordering :: Relaxed ) ;
10441048 if state & PARKED_BIT != 0 {
10451049 let callback = |_, result : UnparkResult | {
10461050 // Clear the parked bit if there no more parked threads
@@ -1051,7 +1055,7 @@ impl RawRwLock {
10511055 } ;
10521056 // SAFETY: `callback` does not panic or call any function of `parking_lot`.
10531057 unsafe {
1054- self . wake_parked_threads ( ONE_READER | UPGRADABLE_BIT , callback) ;
1058+ self . wake_parked_threads ( prev_value , callback) ;
10551059 }
10561060 }
10571061 return false ;
0 commit comments