Skip to content

Commit 7d93279

Browse files
committed
---
yaml --- r: 210423 b: refs/heads/try c: 7529bd6 h: refs/heads/master i: 210421: f857d20 210419: c71bbec 210415: 6078015 v: v3
1 parent a9aa0df commit 7d93279

File tree

4 files changed

+26
-23
lines changed

4 files changed

+26
-23
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 3e561f05c00cd180ec02db4ccab2840a4aba93d2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
5-
refs/heads/try: a031325e83b8f050f840395239197ea87361ada5
5+
refs/heads/try: 7529bd60c3cbc4c7b635ee43a89d5b14f6fb8bf7
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/libstd/sys/common/remutex.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use sys::mutex as sys;
1919

2020
/// A re-entrant mutual exclusion
2121
///
22-
/// This mutex will block *other* threads waiting for the lock to become available. The thread
23-
/// which has already locked the mutex can lock it multiple times without blocking, preventing a
24-
/// common source of deadlocks.
22+
/// This mutex will block *other* threads waiting for the lock to become
23+
/// available. The thread which has already locked the mutex can lock it
24+
/// multiple times without blocking, preventing a common source of deadlocks.
2525
pub struct ReentrantMutex<T> {
2626
inner: Box<sys::ReentrantMutex>,
2727
poison: poison::Flag,
@@ -51,10 +51,14 @@ impl<'a, T> !marker::Send for ReentrantMutexGuard<'a, T> {}
5151
impl<T> ReentrantMutex<T> {
5252
/// Creates a new reentrant mutex in an unlocked state.
5353
pub fn new(t: T) -> ReentrantMutex<T> {
54-
ReentrantMutex {
55-
inner: box unsafe { sys::ReentrantMutex::new() },
56-
poison: poison::FLAG_INIT,
57-
data: t,
54+
unsafe {
55+
let mut mutex = ReentrantMutex {
56+
inner: box sys::ReentrantMutex::uninitialized(),
57+
poison: poison::FLAG_INIT,
58+
data: t,
59+
};
60+
mutex.inner.init();
61+
return mutex
5862
}
5963
}
6064

branches/try/src/libstd/sys/unix/mutex.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,27 @@ impl Mutex {
6969
}
7070
}
7171

72-
// FIXME: remove the box, because box happens twice now, once at the common layer and once here.
73-
// Box is necessary here, because mutex may not change address after it is intialised on some
74-
// platforms. Regular Mutex above handles this by offloading intialisation to the OS on first lock.
75-
// Sadly, as far as reentrant mutexes go, this scheme is not quite portable and we must initialise
76-
// when we create the mutex, in the `new`.
77-
pub struct ReentrantMutex { inner: Box<UnsafeCell<ffi::pthread_mutex_t>> }
72+
pub struct ReentrantMutex { inner: UnsafeCell<ffi::pthread_mutex_t> }
7873

7974
unsafe impl Send for ReentrantMutex {}
8075
unsafe impl Sync for ReentrantMutex {}
8176

8277
impl ReentrantMutex {
83-
pub unsafe fn new() -> ReentrantMutex {
84-
let mutex = ReentrantMutex { inner: box mem::uninitialized() };
78+
pub unsafe fn uninitialized() -> ReentrantMutex {
79+
ReentrantMutex { inner: mem::uninitialized() }
80+
}
81+
82+
pub unsafe fn init(&mut self) {
8583
let mut attr: ffi::pthread_mutexattr_t = mem::uninitialized();
8684
let result = ffi::pthread_mutexattr_init(&mut attr as *mut _);
8785
debug_assert_eq!(result, 0);
8886
let result = ffi::pthread_mutexattr_settype(&mut attr as *mut _,
8987
ffi::PTHREAD_MUTEX_RECURSIVE);
9088
debug_assert_eq!(result, 0);
91-
let result = ffi::pthread_mutex_init(mutex.inner.get(), &attr as *const _);
89+
let result = ffi::pthread_mutex_init(self.inner.get(), &attr as *const _);
9290
debug_assert_eq!(result, 0);
9391
let result = ffi::pthread_mutexattr_destroy(&mut attr as *mut _);
9492
debug_assert_eq!(result, 0);
95-
mutex
9693
}
9794

9895
pub unsafe fn lock(&self) {

branches/try/src/libstd/sys/windows/mutex.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,18 @@ impl Mutex {
5959
}
6060
}
6161

62-
pub struct ReentrantMutex { inner: Box<UnsafeCell<ffi::CRITICAL_SECTION>> }
62+
pub struct ReentrantMutex { inner: UnsafeCell<ffi::CRITICAL_SECTION> }
6363

6464
unsafe impl Send for ReentrantMutex {}
6565
unsafe impl Sync for ReentrantMutex {}
6666

6767
impl ReentrantMutex {
68-
pub unsafe fn new() -> ReentrantMutex {
69-
let mutex = ReentrantMutex { inner: box mem::uninitialized() };
70-
ffi::InitializeCriticalSection(mutex.inner.get());
71-
mutex
68+
pub unsafe fn uninitialized() -> ReentrantMutex {
69+
mem::uninitialized()
70+
}
71+
72+
pub unsafe fn init(&mut self) {
73+
ffi::InitializeCriticalSection(self.inner.get());
7274
}
7375

7476
pub unsafe fn lock(&self) {

0 commit comments

Comments
 (0)