Skip to content

Commit d1b96a7

Browse files
committed
futex not catastrophically failing yet
1 parent bc4b4ed commit d1b96a7

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

library/std/src/sync/rwlock/tests.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
}

library/std/src/sys/sync/rwlock/futex.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff 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.

0 commit comments

Comments
 (0)