@@ -31,7 +31,7 @@ impl RWLock {
31
31
if * wguard. lock_var ( ) || !wguard. queue_empty ( ) {
32
32
// Another thread has or is waiting for the write lock, wait
33
33
drop ( wguard) ;
34
- WaitQueue :: wait ( rguard) ;
34
+ WaitQueue :: wait ( rguard, || { } ) ;
35
35
// Another thread has passed the lock to us
36
36
} else {
37
37
// No waiting writers, acquire the read lock
@@ -62,7 +62,7 @@ impl RWLock {
62
62
if * wguard. lock_var ( ) || rguard. lock_var ( ) . is_some ( ) {
63
63
// Another thread has the lock, wait
64
64
drop ( rguard) ;
65
- WaitQueue :: wait ( wguard) ;
65
+ WaitQueue :: wait ( wguard, || { } ) ;
66
66
// Another thread has passed the lock to us
67
67
} else {
68
68
// We are just now obtaining the lock
@@ -97,6 +97,7 @@ impl RWLock {
97
97
if let Ok ( mut wguard) = WaitQueue :: notify_one ( wguard) {
98
98
// A writer was waiting, pass the lock
99
99
* wguard. lock_var_mut ( ) = true ;
100
+ wguard. drop_after ( rguard) ;
100
101
} else {
101
102
// No writers were waiting, the lock is released
102
103
rtassert ! ( rguard. queue_empty( ) ) ;
@@ -117,21 +118,26 @@ impl RWLock {
117
118
rguard : SpinMutexGuard < ' _ , WaitVariable < Option < NonZeroUsize > > > ,
118
119
wguard : SpinMutexGuard < ' _ , WaitVariable < bool > > ,
119
120
) {
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) ;
127
133
} else {
128
- unreachable ! ( ) // called notify_all
134
+ // No readers waiting, the lock is released
129
135
}
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) ;
132
140
}
133
- } else {
134
- // There was a thread waiting for write, just pass the lock
135
141
}
136
142
}
137
143
0 commit comments