/// A re-entrant mutual exclusion
///
-/// This mutex will block *other* threads waiting for the lock to become available. The thread
-/// which has already locked the mutex can lock it multiple times without blocking, preventing a
-/// common source of deadlocks.
+/// This mutex will block *other* threads waiting for the lock to become
+/// available. The thread which has already locked the mutex can lock it
+/// multiple times without blocking, preventing a common source of deadlocks.
pub struct ReentrantMutex<T> {
inner: Box<sys::ReentrantMutex>,
poison: poison::Flag,
impl<T> ReentrantMutex<T> {
/// Creates a new reentrant mutex in an unlocked state.
pub fn new(t: T) -> ReentrantMutex<T> {
- ReentrantMutex {
- inner: box unsafe { sys::ReentrantMutex::new() },
- poison: poison::FLAG_INIT,
- data: t,
+ unsafe {
+ let mut mutex = ReentrantMutex {
+ inner: box sys::ReentrantMutex::uninitialized(),
+ poison: poison::FLAG_INIT,
+ data: t,
+ };
+ mutex.inner.init();
+ return mutex
}
}
}
}
-#[unsafe_destructor]
impl<T> Drop for ReentrantMutex<T> {
fn drop(&mut self) {
// This is actually safe b/c we know that there is no further usage of
}
}
-#[unsafe_destructor]
impl<'a, T> Drop for ReentrantMutexGuard<'a, T> {
#[inline]
fn drop(&mut self) {
#[cfg(test)]
-mod test {
+mod tests {
use prelude::v1::*;
use sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard};
use cell::RefCell;