diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-05-05 16:44:28 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-05-07 09:30:00 -0700 |
| commit | 7529bd60c3cbc4c7b635ee43a89d5b14f6fb8bf7 (patch) | |
| tree | 3497eae8c3d88f0f1b5c1e9fb3cf289b751c414e /src/libstd/sys/common/remutex.rs | |
| parent | a031325e83b8f050f840395239197ea87361ada5 (diff) | |
| download | rust-7529bd60c3cbc4c7b635ee43a89d5b14f6fb8bf7.tar.gz rust-7529bd60c3cbc4c7b635ee43a89d5b14f6fb8bf7.zip | |
std: Remove a double-box in ReentrantMutex
Perform unsafe initialization up front and then only afterward the mutex is in place do we initialize it.
Diffstat (limited to 'src/libstd/sys/common/remutex.rs')
| -rw-r--r-- | src/libstd/sys/common/remutex.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/libstd/sys/common/remutex.rs b/src/libstd/sys/common/remutex.rs index 48c74b8d89e..1a467580672 100644 --- a/src/libstd/sys/common/remutex.rs +++ b/src/libstd/sys/common/remutex.rs @@ -19,9 +19,9 @@ use sys::mutex as sys; /// 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, @@ -51,10 +51,14 @@ impl<'a, T> !marker::Send for ReentrantMutexGuard<'a, T> {} 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 } } |
