Unix RwLock: avoid racy access to write_locked
This commit is contained in:
parent
9b8f902976
commit
0c6a093afa
1 changed files with 2 additions and 2 deletions
|
|
@ -14,7 +14,7 @@ use sync::atomic::{AtomicUsize, Ordering};
|
|||
|
||||
pub struct RWLock {
|
||||
inner: UnsafeCell<libc::pthread_rwlock_t>,
|
||||
write_locked: UnsafeCell<bool>,
|
||||
write_locked: UnsafeCell<bool>, // guarded by the `inner` RwLock
|
||||
num_readers: AtomicUsize,
|
||||
}
|
||||
|
||||
|
|
@ -52,7 +52,7 @@ impl RWLock {
|
|||
// allow that because it could lead to aliasing issues.
|
||||
if r == libc::EAGAIN {
|
||||
panic!("rwlock maximum reader count exceeded");
|
||||
} else if r == libc::EDEADLK || *self.write_locked.get() {
|
||||
} else if r == libc::EDEADLK || (r == 0 && *self.write_locked.get()) {
|
||||
if r == 0 {
|
||||
self.raw_unlock();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue