diff options
| author | Pietro Albini <pietro@pietroalbini.org> | 2018-11-15 11:04:41 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-11-15 11:04:41 +0100 |
| commit | fb4553299ca2717e6c106cd6db36b7dc6c959aac (patch) | |
| tree | e57d1b0bea121367e8ee7dbaca06fc56a7e653ea /src/libstd/sys | |
| parent | 3c7acc78783dfb2df5437d3a793fbd194f1ea785 (diff) | |
| parent | db133901042f7ccc8194b240c8381281bc4be575 (diff) | |
| download | rust-fb4553299ca2717e6c106cd6db36b7dc6c959aac.tar.gz rust-fb4553299ca2717e6c106cd6db36b7dc6c959aac.zip | |
Rollup merge of #55865 - RalfJung:unix-rwlock, r=alexcrichton
Unix RwLock: avoid racy access to write_locked We should only access `write_locked` if we really got the lock.
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/rwlock.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/libstd/sys/unix/rwlock.rs b/src/libstd/sys/unix/rwlock.rs index c754d5b8359..fcd6f7a27b6 100644 --- a/src/libstd/sys/unix/rwlock.rs +++ b/src/libstd/sys/unix/rwlock.rs @@ -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,13 +52,13 @@ 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(); } panic!("rwlock read lock would result in deadlock"); } else { - debug_assert_eq!(r, 0); + assert_eq!(r, 0); self.num_readers.fetch_add(1, Ordering::Relaxed); } } |
