about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2018-11-11 10:06:41 +0100
committerRalf Jung <post@ralfj.de>2018-11-11 10:06:41 +0100
commit0c6a093afa7cd6943551b4855b3cc2588befdf3f (patch)
tree6a7b88bf44711ff079be6a344bf7f9c7a1ddcf17
parent9b8f9029762da90a88c8ca6f8ff7690177ec696a (diff)
downloadrust-0c6a093afa7cd6943551b4855b3cc2588befdf3f.tar.gz
rust-0c6a093afa7cd6943551b4855b3cc2588befdf3f.zip
Unix RwLock: avoid racy access to write_locked
-rw-r--r--src/libstd/sys/unix/rwlock.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libstd/sys/unix/rwlock.rs b/src/libstd/sys/unix/rwlock.rs
index c754d5b8359..8c385ae7760 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,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();
             }