Skip to content

Commit b527494

Browse files
committed
Fix destroy assertions in mutex/rwlock/condvar
On DragonFly pthread_{mutex,rwlock,condvar}_destroy() returns EINVAL when called on a pthread_{mutex,rwlock,condvar}_t that was just initialized via PTHREAD_{MUTEX,RWLOCK,CONDVAR}_INITIALIZER and not used in the meantime or initialized via pthread_{mutex,rwlock,condvar}_init(). Change the code to treat a return value of EINVAL on DragonFly as success.
1 parent 2f99a41 commit b527494

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/libstd/sys/unix/condvar.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,20 @@ impl Condvar {
7676
}
7777

7878
#[inline]
79+
#[cfg(not(target_os = "dragonfly"))]
7980
pub unsafe fn destroy(&self) {
8081
let r = ffi::pthread_cond_destroy(self.inner.get());
8182
debug_assert_eq!(r, 0);
8283
}
84+
85+
#[inline]
86+
#[cfg(target_os = "dragonfly")]
87+
pub unsafe fn destroy(&self) {
88+
let r = ffi::pthread_cond_destroy(self.inner.get());
89+
// On DragonFly pthread_cond_destroy() returns EINVAL if called on
90+
// a condvar that was just initialized with
91+
// ffi::PTHREAD_COND_INITIALIZER. Once it is used or
92+
// pthread_cond_init() is called, this behaviour no longer occurs.
93+
debug_assert!(r == 0 || r == libc::EINVAL);
94+
}
8395
}

src/libstd/sys/unix/mutex.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,20 @@ impl Mutex {
4848
ffi::pthread_mutex_trylock(self.inner.get()) == 0
4949
}
5050
#[inline]
51+
#[cfg(not(target_os = "dragonfly"))]
5152
pub unsafe fn destroy(&self) {
5253
let r = ffi::pthread_mutex_destroy(self.inner.get());
5354
debug_assert_eq!(r, 0);
5455
}
56+
#[inline]
57+
#[cfg(target_os = "dragonfly")]
58+
pub unsafe fn destroy(&self) {
59+
use libc;
60+
let r = ffi::pthread_mutex_destroy(self.inner.get());
61+
// On DragonFly pthread_mutex_destroy() returns EINVAL if called on a
62+
// mutex that was just initialized with ffi::PTHREAD_MUTEX_INITIALIZER.
63+
// Once it is used (locked/unlocked) or pthread_mutex_init() is called,
64+
// this behaviour no longer occurs.
65+
debug_assert!(r == 0 || r == libc::EINVAL);
66+
}
5567
}

src/libstd/sys/unix/rwlock.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,21 @@ impl RWLock {
5050
#[inline]
5151
pub unsafe fn write_unlock(&self) { self.read_unlock() }
5252
#[inline]
53+
#[cfg(not(target_os = "dragonfly"))]
5354
pub unsafe fn destroy(&self) {
5455
let r = ffi::pthread_rwlock_destroy(self.inner.get());
5556
debug_assert_eq!(r, 0);
5657
}
58+
59+
#[inline]
60+
#[cfg(target_os = "dragonfly")]
61+
pub unsafe fn destroy(&self) {
62+
use libc;
63+
let r = ffi::pthread_rwlock_destroy(self.inner.get());
64+
// On DragonFly pthread_rwlock_destroy() returns EINVAL if called on a
65+
// rwlock that was just initialized with
66+
// ffi::PTHREAD_RWLOCK_INITIALIZER. Once it is used (locked/unlocked)
67+
// or pthread_rwlock_init() is called, this behaviour no longer occurs.
68+
debug_assert!(r == 0 || r == libc::EINVAL);
69+
}
5770
}

0 commit comments

Comments
 (0)