Skip to content

Commit 18b9020

Browse files
committed
---
yaml --- r: 207918 b: refs/heads/snap-stage3 c: 5c8ca26 h: refs/heads/master v: v3
1 parent 2409b33 commit 18b9020

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 38a97becdf3e6a6157f6f7ec2d98ade8d8edc193
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 4288a08e9a640e2b24d2f5974f6785f0ab82694b
4+
refs/heads/snap-stage3: 5c8ca26ad7fd6bbe0e7d4f5ddc10a891b2e74512
55
refs/heads/try: 7b4ef47b7805a402d756fb8157101f64880a522f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/libstd/sys/unix/rwlock.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use prelude::v1::*;
1212

13+
use libc;
1314
use cell::UnsafeCell;
1415
use sys::sync as ffi;
1516

@@ -26,7 +27,23 @@ impl RWLock {
2627
#[inline]
2728
pub unsafe fn read(&self) {
2829
let r = ffi::pthread_rwlock_rdlock(self.inner.get());
29-
debug_assert_eq!(r, 0);
30+
31+
// According to the pthread_rwlock_rdlock spec, this function **may**
32+
// fail with EDEADLK if a deadlock is detected. On the other hand
33+
// pthread mutexes will *never* return EDEADLK if they are initialized
34+
// as the "fast" kind (which ours always are). As a result, a deadlock
35+
// situation may actually return from the call to pthread_rwlock_rdlock
36+
// instead of blocking forever (as mutexes and Windows rwlocks do). Note
37+
// that not all unix implementations, however, will return EDEADLK for
38+
// their rwlocks.
39+
//
40+
// We roughly maintain the deadlocking behavior by panicking to ensure
41+
// that this lock acquisition does not succeed.
42+
if r == libc::EDEADLK {
43+
panic!("rwlock read lock would result in deadlock");
44+
} else {
45+
debug_assert_eq!(r, 0);
46+
}
3047
}
3148
#[inline]
3249
pub unsafe fn try_read(&self) -> bool {
@@ -35,7 +52,12 @@ impl RWLock {
3552
#[inline]
3653
pub unsafe fn write(&self) {
3754
let r = ffi::pthread_rwlock_wrlock(self.inner.get());
38-
debug_assert_eq!(r, 0);
55+
// see comments above for why we check for EDEADLK
56+
if r == libc::EDEADLK {
57+
panic!("rwlock write lock would result in deadlock");
58+
} else {
59+
debug_assert_eq!(r, 0);
60+
}
3961
}
4062
#[inline]
4163
pub unsafe fn try_write(&self) -> bool {

0 commit comments

Comments
 (0)