@@ -12,7 +12,7 @@ use fmt;
12
12
use marker;
13
13
use ops:: Deref ;
14
14
use sys_common:: poison:: { self , TryLockError , TryLockResult , LockResult } ;
15
- use sys :: mutex as sys ;
15
+ use sys_common :: parking_lot :: remutex :: RawReentrantMutex ;
16
16
use panic:: { UnwindSafe , RefUnwindSafe } ;
17
17
18
18
/// A re-entrant mutual exclusion
@@ -21,7 +21,7 @@ use panic::{UnwindSafe, RefUnwindSafe};
21
21
/// available. The thread which has already locked the mutex can lock it
22
22
/// multiple times without blocking, preventing a common source of deadlocks.
23
23
pub struct ReentrantMutex < T > {
24
- inner : Box < sys :: ReentrantMutex > ,
24
+ inner : Box < RawReentrantMutex > ,
25
25
poison : poison:: Flag ,
26
26
data : T ,
27
27
}
@@ -59,14 +59,10 @@ impl<'a, T> !marker::Send for ReentrantMutexGuard<'a, T> {}
59
59
impl < T > ReentrantMutex < T > {
60
60
/// Creates a new reentrant mutex in an unlocked state.
61
61
pub fn new ( t : T ) -> ReentrantMutex < T > {
62
- unsafe {
63
- let mut mutex = ReentrantMutex {
64
- inner : box sys:: ReentrantMutex :: uninitialized ( ) ,
65
- poison : poison:: Flag :: new ( ) ,
66
- data : t,
67
- } ;
68
- mutex. inner . init ( ) ;
69
- mutex
62
+ ReentrantMutex {
63
+ inner : box RawReentrantMutex :: INIT ,
64
+ poison : poison:: Flag :: new ( ) ,
65
+ data : t,
70
66
}
71
67
}
72
68
@@ -83,7 +79,7 @@ impl<T> ReentrantMutex<T> {
83
79
/// this call will return failure if the mutex would otherwise be
84
80
/// acquired.
85
81
pub fn lock ( & self ) -> LockResult < ReentrantMutexGuard < T > > {
86
- unsafe { self . inner . lock ( ) }
82
+ self . inner . lock ( ) ;
87
83
ReentrantMutexGuard :: new ( & self )
88
84
}
89
85
@@ -100,7 +96,7 @@ impl<T> ReentrantMutex<T> {
100
96
/// this call will return failure if the mutex would otherwise be
101
97
/// acquired.
102
98
pub fn try_lock ( & self ) -> TryLockResult < ReentrantMutexGuard < T > > {
103
- if unsafe { self . inner . try_lock ( ) } {
99
+ if self . inner . try_lock ( ) {
104
100
Ok ( ReentrantMutexGuard :: new ( & self ) ?)
105
101
} else {
106
102
Err ( TryLockError :: WouldBlock )
@@ -109,12 +105,7 @@ impl<T> ReentrantMutex<T> {
109
105
}
110
106
111
107
impl < T > Drop for ReentrantMutex < T > {
112
- fn drop ( & mut self ) {
113
- // This is actually safe b/c we know that there is no further usage of
114
- // this mutex (it's up to the user to arrange for a mutex to get
115
- // dropped, that's not our job)
116
- unsafe { self . inner . destroy ( ) }
117
- }
108
+ fn drop ( & mut self ) { }
118
109
}
119
110
120
111
impl < T : fmt:: Debug + ' static > fmt:: Debug for ReentrantMutex < T > {
@@ -159,10 +150,8 @@ impl<'mutex, T> Deref for ReentrantMutexGuard<'mutex, T> {
159
150
impl < ' a , T > Drop for ReentrantMutexGuard < ' a , T > {
160
151
#[ inline]
161
152
fn drop ( & mut self ) {
162
- unsafe {
163
- self . __lock . poison . done ( & self . __poison ) ;
164
- self . __lock . inner . unlock ( ) ;
165
- }
153
+ self . __lock . poison . done ( & self . __poison ) ;
154
+ self . __lock . inner . unlock ( ) ;
166
155
}
167
156
}
168
157
0 commit comments