@@ -31,7 +31,7 @@ impl RWLock {
3131 if * wguard. lock_var ( ) || !wguard. queue_empty ( ) {
3232 // Another thread has or is waiting for the write lock, wait
3333 drop ( wguard) ;
34- WaitQueue :: wait ( rguard) ;
34+ WaitQueue :: wait ( rguard, || { } ) ;
3535 // Another thread has passed the lock to us
3636 } else {
3737 // No waiting writers, acquire the read lock
@@ -62,7 +62,7 @@ impl RWLock {
6262 if * wguard. lock_var ( ) || rguard. lock_var ( ) . is_some ( ) {
6363 // Another thread has the lock, wait
6464 drop ( rguard) ;
65- WaitQueue :: wait ( wguard) ;
65+ WaitQueue :: wait ( wguard, || { } ) ;
6666 // Another thread has passed the lock to us
6767 } else {
6868 // We are just now obtaining the lock
@@ -97,6 +97,7 @@ impl RWLock {
9797 if let Ok ( mut wguard) = WaitQueue :: notify_one ( wguard) {
9898 // A writer was waiting, pass the lock
9999 * wguard. lock_var_mut ( ) = true ;
100+ wguard. drop_after ( rguard) ;
100101 } else {
101102 // No writers were waiting, the lock is released
102103 rtassert ! ( rguard. queue_empty( ) ) ;
@@ -117,21 +118,26 @@ impl RWLock {
117118 rguard : SpinMutexGuard < ' _ , WaitVariable < Option < NonZeroUsize > > > ,
118119 wguard : SpinMutexGuard < ' _ , WaitVariable < bool > > ,
119120 ) {
120- if let Err ( mut wguard) = WaitQueue :: notify_one ( wguard) {
121- // No writers waiting, release the write lock
122- * wguard. lock_var_mut ( ) = false ;
123- if let Ok ( mut rguard) = WaitQueue :: notify_all ( rguard) {
124- // One or more readers were waiting, pass the lock to them
125- if let NotifiedTcs :: All { count } = rguard. notified_tcs ( ) {
126- * rguard. lock_var_mut ( ) = Some ( count)
121+ match WaitQueue :: notify_one ( wguard) {
122+ Err ( mut wguard) => {
123+ // No writers waiting, release the write lock
124+ * wguard. lock_var_mut ( ) = false ;
125+ if let Ok ( mut rguard) = WaitQueue :: notify_all ( rguard) {
126+ // One or more readers were waiting, pass the lock to them
127+ if let NotifiedTcs :: All { count } = rguard. notified_tcs ( ) {
128+ * rguard. lock_var_mut ( ) = Some ( count)
129+ } else {
130+ unreachable ! ( ) // called notify_all
131+ }
132+ rguard. drop_after ( wguard) ;
127133 } else {
128- unreachable ! ( ) // called notify_all
134+ // No readers waiting, the lock is released
129135 }
130- } else {
131- // No readers waiting, the lock is released
136+ } ,
137+ Ok ( wguard) => {
138+ // There was a thread waiting for write, just pass the lock
139+ wguard. drop_after ( rguard) ;
132140 }
133- } else {
134- // There was a thread waiting for write, just pass the lock
135141 }
136142 }
137143
0 commit comments