Skip to content

Commit 6b68608

Browse files
committed
---
yaml --- r: 206535 b: refs/heads/beta c: 7529bd6 h: refs/heads/master i: 206533: 18017d4 206531: 99b13b5 206527: beef084 v: v3
1 parent f2c7d1c commit 6b68608

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
@@ -29,7 +29,7 @@ refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2929
refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3030
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3131
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
32-
refs/heads/beta: a031325e83b8f050f840395239197ea87361ada5
32+
refs/heads/beta: 7529bd60c3cbc4c7b635ee43a89d5b14f6fb8bf7
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3535
refs/heads/tmp: 579e31929feff51dcaf8d444648eff8de735f91a

branches/beta/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/beta/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/beta/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)