@@ -12,7 +12,7 @@ use fmt;
1212use marker;
1313use ops:: Deref ;
1414use sys_common:: poison:: { self , TryLockError , TryLockResult , LockResult } ;
15- use sys :: mutex as sys ;
15+ use sys_common :: parking_lot :: remutex :: RawReentrantMutex ;
1616use panic:: { UnwindSafe , RefUnwindSafe } ;
1717
1818/// A re-entrant mutual exclusion
@@ -21,7 +21,7 @@ use panic::{UnwindSafe, RefUnwindSafe};
2121/// available. The thread which has already locked the mutex can lock it
2222/// multiple times without blocking, preventing a common source of deadlocks.
2323pub struct ReentrantMutex < T > {
24- inner : Box < sys :: ReentrantMutex > ,
24+ inner : Box < RawReentrantMutex > ,
2525 poison : poison:: Flag ,
2626 data : T ,
2727}
@@ -59,14 +59,10 @@ impl<'a, T> !marker::Send for ReentrantMutexGuard<'a, T> {}
5959impl < T > ReentrantMutex < T > {
6060 /// Creates a new reentrant mutex in an unlocked state.
6161 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,
7066 }
7167 }
7268
@@ -83,7 +79,7 @@ impl<T> ReentrantMutex<T> {
8379 /// this call will return failure if the mutex would otherwise be
8480 /// acquired.
8581 pub fn lock ( & self ) -> LockResult < ReentrantMutexGuard < T > > {
86- unsafe { self . inner . lock ( ) }
82+ self . inner . lock ( ) ;
8783 ReentrantMutexGuard :: new ( & self )
8884 }
8985
@@ -100,7 +96,7 @@ impl<T> ReentrantMutex<T> {
10096 /// this call will return failure if the mutex would otherwise be
10197 /// acquired.
10298 pub fn try_lock ( & self ) -> TryLockResult < ReentrantMutexGuard < T > > {
103- if unsafe { self . inner . try_lock ( ) } {
99+ if self . inner . try_lock ( ) {
104100 Ok ( ReentrantMutexGuard :: new ( & self ) ?)
105101 } else {
106102 Err ( TryLockError :: WouldBlock )
@@ -109,12 +105,7 @@ impl<T> ReentrantMutex<T> {
109105}
110106
111107impl < 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 ) { }
118109}
119110
120111impl < T : fmt:: Debug + ' static > fmt:: Debug for ReentrantMutex < T > {
@@ -159,10 +150,8 @@ impl<'mutex, T> Deref for ReentrantMutexGuard<'mutex, T> {
159150impl < ' a , T > Drop for ReentrantMutexGuard < ' a , T > {
160151 #[ inline]
161152 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 ( ) ;
166155 }
167156}
168157
0 commit comments