File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -501,3 +501,11 @@ fn panic_while_mapping_write_unlocked_poison() {
501501
502502 drop ( lock) ;
503503}
504+
505+ #[ test]
506+ fn test_downgrade_basic ( ) {
507+ let r = RwLock :: new ( ( ) ) ;
508+
509+ let write_guard = r. write ( ) . unwrap ( ) ;
510+ let _read_guard = RwLockWriteGuard :: downgrade ( write_guard) ;
511+ }
Original file line number Diff line number Diff line change @@ -134,7 +134,8 @@ impl RwLock {
134134 // Wait for the state to change.
135135 futex_wait ( & self . state , state | READERS_WAITING , None ) ;
136136
137- // FIXME this protocol does not work
137+ // FIXME make sure this works
138+ // FIXME this can probably be more elegant
138139 state = self . state . load ( Relaxed ) ;
139140 if state & MASK < MAX_READERS && !has_readers_waiting ( state) {
140141 match self . state . compare_exchange_weak ( state, state + READ_LOCKED , Acquire , Relaxed )
@@ -145,10 +146,10 @@ impl RwLock {
145146 continue ;
146147 }
147148 }
148- } else {
149- // Otherwise, spin again after waking up.
150- state = self . spin_read ( ) ;
151149 }
150+
151+ // Otherwise, spin again after waking up.
152+ state = self . spin_read ( ) ;
152153 }
153154 }
154155
@@ -177,7 +178,7 @@ impl RwLock {
177178 }
178179 }
179180
180- // FIXME this does not work
181+ // FIXME make sure this works
181182 #[ inline]
182183 pub unsafe fn downgrade ( & self ) {
183184 // Removes all the write bits and adds a single read bit.
You can’t perform that action at this time.
0 commit comments