26
26
//!
27
27
//! `MTLock` is a mutex which disappears if cfg!(parallel_queries) is false.
28
28
//!
29
+ //! `MTRef` is a immutable refernce if cfg!(parallel_queries), and an mutable reference otherwise.
30
+ //!
29
31
//! `rustc_erase_owner!` erases a OwningRef owner into Erased or Erased + Send + Sync
30
32
//! depending on the value of cfg!(parallel_queries).
31
33
@@ -126,6 +128,8 @@ cfg_if! {
126
128
}
127
129
}
128
130
131
+ pub type MTRef <' a, T > = & ' a mut T ;
132
+
129
133
#[ derive( Debug ) ]
130
134
pub struct MTLock <T >( T ) ;
131
135
@@ -151,13 +155,8 @@ cfg_if! {
151
155
}
152
156
153
157
#[ inline( always) ]
154
- pub fn borrow( & self ) -> & T {
155
- & self . 0
156
- }
157
-
158
- #[ inline( always) ]
159
- pub fn borrow_mut( & self ) -> & T {
160
- & self . 0
158
+ pub fn lock_mut( & mut self ) -> & mut T {
159
+ & mut self . 0
161
160
}
162
161
}
163
162
@@ -221,7 +220,37 @@ cfg_if! {
221
220
pub use std:: sync:: Arc as Lrc ;
222
221
pub use std:: sync:: Weak as Weak ;
223
222
224
- pub use self :: Lock as MTLock ;
223
+ pub type MTRef <' a, T > = & ' a T ;
224
+
225
+ #[ derive( Debug ) ]
226
+ pub struct MTLock <T >( Lock <T >) ;
227
+
228
+ impl <T > MTLock <T > {
229
+ #[ inline( always) ]
230
+ pub fn new( inner: T ) -> Self {
231
+ MTLock ( Lock :: new( inner) )
232
+ }
233
+
234
+ #[ inline( always) ]
235
+ pub fn into_inner( self ) -> T {
236
+ self . 0 . into_inner( )
237
+ }
238
+
239
+ #[ inline( always) ]
240
+ pub fn get_mut( & mut self ) -> & mut T {
241
+ self . 0 . get_mut( )
242
+ }
243
+
244
+ #[ inline( always) ]
245
+ pub fn lock( & self ) -> LockGuard <T > {
246
+ self . 0 . lock( )
247
+ }
248
+
249
+ #[ inline( always) ]
250
+ pub fn lock_mut( & self ) -> LockGuard <T > {
251
+ self . lock( )
252
+ }
253
+ }
225
254
226
255
use parking_lot:: Mutex as InnerLock ;
227
256
use parking_lot:: RwLock as InnerRwLock ;
0 commit comments