未验证 提交 fb455329 编写于 作者: P Pietro Albini 提交者: GitHub

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.
......@@ -14,7 +14,7 @@
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 @@ pub unsafe fn read(&self) {
// 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);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册