@@ -69,30 +69,27 @@ impl Mutex {
69
69
}
70
70
}
71
71
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 > }
78
73
79
74
unsafe impl Send for ReentrantMutex { }
80
75
unsafe impl Sync for ReentrantMutex { }
81
76
82
77
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 ) {
85
83
let mut attr: ffi:: pthread_mutexattr_t = mem:: uninitialized ( ) ;
86
84
let result = ffi:: pthread_mutexattr_init ( & mut attr as * mut _ ) ;
87
85
debug_assert_eq ! ( result, 0 ) ;
88
86
let result = ffi:: pthread_mutexattr_settype ( & mut attr as * mut _ ,
89
87
ffi:: PTHREAD_MUTEX_RECURSIVE ) ;
90
88
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 _ ) ;
92
90
debug_assert_eq ! ( result, 0 ) ;
93
91
let result = ffi:: pthread_mutexattr_destroy ( & mut attr as * mut _ ) ;
94
92
debug_assert_eq ! ( result, 0 ) ;
95
- mutex
96
93
}
97
94
98
95
pub unsafe fn lock ( & self ) {
0 commit comments