Merge pull request #20741 from mneumann/dragonfly-pthread-mutex

Fix assertion in Mutex::destroy() on DragonFly (#20698)

Reviewed-by: alexcrichton
This commit is contained in:
bors 2015-01-09 01:19:54 +00:00
commit 948d1d004d
3 changed files with 37 additions and 0 deletions

View File

@ -76,8 +76,20 @@ impl Condvar {
} }
#[inline] #[inline]
#[cfg(not(target_os = "dragonfly"))]
pub unsafe fn destroy(&self) { pub unsafe fn destroy(&self) {
let r = ffi::pthread_cond_destroy(self.inner.get()); let r = ffi::pthread_cond_destroy(self.inner.get());
debug_assert_eq!(r, 0); debug_assert_eq!(r, 0);
} }
#[inline]
#[cfg(target_os = "dragonfly")]
pub unsafe fn destroy(&self) {
let r = ffi::pthread_cond_destroy(self.inner.get());
// On DragonFly pthread_cond_destroy() returns EINVAL if called on
// a condvar that was just initialized with
// ffi::PTHREAD_COND_INITIALIZER. Once it is used or
// pthread_cond_init() is called, this behaviour no longer occurs.
debug_assert!(r == 0 || r == libc::EINVAL);
}
} }

View File

@ -48,8 +48,20 @@ impl Mutex {
ffi::pthread_mutex_trylock(self.inner.get()) == 0 ffi::pthread_mutex_trylock(self.inner.get()) == 0
} }
#[inline] #[inline]
#[cfg(not(target_os = "dragonfly"))]
pub unsafe fn destroy(&self) { pub unsafe fn destroy(&self) {
let r = ffi::pthread_mutex_destroy(self.inner.get()); let r = ffi::pthread_mutex_destroy(self.inner.get());
debug_assert_eq!(r, 0); debug_assert_eq!(r, 0);
} }
#[inline]
#[cfg(target_os = "dragonfly")]
pub unsafe fn destroy(&self) {
use libc;
let r = ffi::pthread_mutex_destroy(self.inner.get());
// On DragonFly pthread_mutex_destroy() returns EINVAL if called on a
// mutex that was just initialized with ffi::PTHREAD_MUTEX_INITIALIZER.
// Once it is used (locked/unlocked) or pthread_mutex_init() is called,
// this behaviour no longer occurs.
debug_assert!(r == 0 || r == libc::EINVAL);
}
} }

View File

@ -50,8 +50,21 @@ impl RWLock {
#[inline] #[inline]
pub unsafe fn write_unlock(&self) { self.read_unlock() } pub unsafe fn write_unlock(&self) { self.read_unlock() }
#[inline] #[inline]
#[cfg(not(target_os = "dragonfly"))]
pub unsafe fn destroy(&self) { pub unsafe fn destroy(&self) {
let r = ffi::pthread_rwlock_destroy(self.inner.get()); let r = ffi::pthread_rwlock_destroy(self.inner.get());
debug_assert_eq!(r, 0); debug_assert_eq!(r, 0);
} }
#[inline]
#[cfg(target_os = "dragonfly")]
pub unsafe fn destroy(&self) {
use libc;
let r = ffi::pthread_rwlock_destroy(self.inner.get());
// On DragonFly pthread_rwlock_destroy() returns EINVAL if called on a
// rwlock that was just initialized with
// ffi::PTHREAD_RWLOCK_INITIALIZER. Once it is used (locked/unlocked)
// or pthread_rwlock_init() is called, this behaviour no longer occurs.
debug_assert!(r == 0 || r == libc::EINVAL);
}
} }