@@ -179,15 +179,49 @@ cfg_if! {
179
179
180
180
pub use std:: rc:: Rc as Lrc ;
181
181
pub use std:: rc:: Weak as Weak ;
182
- pub use std:: cell:: Ref as ReadGuard ;
183
- pub use std:: cell:: Ref as MappedReadGuard ;
184
- pub use std:: cell:: RefMut as WriteGuard ;
185
- pub use std:: cell:: RefMut as MappedWriteGuard ;
186
- pub use std:: cell:: RefMut as LockGuard ;
187
- pub use std:: cell:: RefMut as MappedLockGuard ;
188
182
189
- use std:: cell:: RefCell as InnerRwLock ;
190
- use std:: cell:: RefCell as InnerLock ;
183
+ pub use parking_lot:: RwLockReadGuard as ReadGuard ;
184
+ pub use parking_lot:: MappedRwLockReadGuard as MappedReadGuard ;
185
+ pub use parking_lot:: RwLockWriteGuard as WriteGuard ;
186
+ pub use parking_lot:: MappedRwLockWriteGuard as MappedWriteGuard ;
187
+
188
+ pub use parking_lot:: MutexGuard as LockGuard ;
189
+ pub use parking_lot:: MappedMutexGuard as MappedLockGuard ;
190
+
191
+ pub type MTRef <' a, T > = & ' a T ;
192
+
193
+ #[ derive( Debug , Default ) ]
194
+ pub struct MTLock <T >( Lock <T >) ;
195
+
196
+ impl <T > MTLock <T > {
197
+ #[ inline( always) ]
198
+ pub fn new( inner: T ) -> Self {
199
+ MTLock ( Lock :: new( inner) )
200
+ }
201
+
202
+ #[ inline( always) ]
203
+ pub fn into_inner( self ) -> T {
204
+ self . 0 . into_inner( )
205
+ }
206
+
207
+ #[ inline( always) ]
208
+ pub fn get_mut( & mut self ) -> & mut T {
209
+ self . 0 . get_mut( )
210
+ }
211
+
212
+ #[ inline( always) ]
213
+ pub fn lock( & self ) -> LockGuard <' _, T > {
214
+ self . 0 . lock( )
215
+ }
216
+
217
+ #[ inline( always) ]
218
+ pub fn lock_mut( & self ) -> LockGuard <' _, T > {
219
+ self . lock( )
220
+ }
221
+ }
222
+
223
+ use parking_lot:: Mutex as InnerLock ;
224
+ use parking_lot:: RwLock as InnerRwLock ;
191
225
192
226
use std:: cell:: Cell ;
193
227
@@ -218,38 +252,6 @@ cfg_if! {
218
252
}
219
253
}
220
254
221
- pub type MTRef <' a, T > = & ' a mut T ;
222
-
223
- #[ derive( Debug , Default ) ]
224
- pub struct MTLock <T >( T ) ;
225
-
226
- impl <T > MTLock <T > {
227
- #[ inline( always) ]
228
- pub fn new( inner: T ) -> Self {
229
- MTLock ( inner)
230
- }
231
-
232
- #[ inline( always) ]
233
- pub fn into_inner( self ) -> T {
234
- self . 0
235
- }
236
-
237
- #[ inline( always) ]
238
- pub fn get_mut( & mut self ) -> & mut T {
239
- & mut self . 0
240
- }
241
-
242
- #[ inline( always) ]
243
- pub fn lock( & self ) -> & T {
244
- & self . 0
245
- }
246
-
247
- #[ inline( always) ]
248
- pub fn lock_mut( & mut self ) -> & mut T {
249
- & mut self . 0
250
- }
251
- }
252
-
253
255
// FIXME: Probably a bad idea (in the threaded case)
254
256
impl <T : Clone > Clone for MTLock <T > {
255
257
#[ inline]
@@ -535,32 +537,14 @@ impl<T> Lock<T> {
535
537
self . 0 . get_mut ( )
536
538
}
537
539
538
- #[ cfg( parallel_compiler) ]
539
540
#[ inline( always) ]
540
541
pub fn try_lock ( & self ) -> Option < LockGuard < ' _ , T > > {
541
542
self . 0 . try_lock ( )
542
543
}
543
544
544
- #[ cfg( not( parallel_compiler) ) ]
545
- #[ inline( always) ]
546
- pub fn try_lock ( & self ) -> Option < LockGuard < ' _ , T > > {
547
- self . 0 . try_borrow_mut ( ) . ok ( )
548
- }
549
-
550
- #[ cfg( parallel_compiler) ]
551
- #[ inline( always) ]
552
- pub fn lock ( & self ) -> LockGuard < ' _ , T > {
553
- if ERROR_CHECKING {
554
- self . 0 . try_lock ( ) . expect ( "lock was already held" )
555
- } else {
556
- self . 0 . lock ( )
557
- }
558
- }
559
-
560
- #[ cfg( not( parallel_compiler) ) ]
561
545
#[ inline( always) ]
562
546
pub fn lock ( & self ) -> LockGuard < ' _ , T > {
563
- self . 0 . borrow_mut ( )
547
+ self . 0 . lock ( )
564
548
}
565
549
566
550
#[ inline( always) ]
@@ -613,53 +597,24 @@ impl<T> RwLock<T> {
613
597
self . 0 . get_mut ( )
614
598
}
615
599
616
- #[ cfg( not( parallel_compiler) ) ]
617
- #[ inline( always) ]
618
- pub fn read ( & self ) -> ReadGuard < ' _ , T > {
619
- self . 0 . borrow ( )
620
- }
621
-
622
- #[ cfg( parallel_compiler) ]
623
600
#[ inline( always) ]
624
601
pub fn read ( & self ) -> ReadGuard < ' _ , T > {
625
- if ERROR_CHECKING {
626
- self . 0 . try_read ( ) . expect ( "lock was already held" )
627
- } else {
628
- self . 0 . read ( )
629
- }
602
+ self . 0 . read ( )
630
603
}
631
604
632
605
#[ inline( always) ]
633
606
pub fn with_read_lock < F : FnOnce ( & T ) -> R , R > ( & self , f : F ) -> R {
634
607
f ( & * self . read ( ) )
635
608
}
636
609
637
- #[ cfg( not( parallel_compiler) ) ]
638
- #[ inline( always) ]
639
- pub fn try_write ( & self ) -> Result < WriteGuard < ' _ , T > , ( ) > {
640
- self . 0 . try_borrow_mut ( ) . map_err ( |_| ( ) )
641
- }
642
-
643
- #[ cfg( parallel_compiler) ]
644
610
#[ inline( always) ]
645
611
pub fn try_write ( & self ) -> Result < WriteGuard < ' _ , T > , ( ) > {
646
612
self . 0 . try_write ( ) . ok_or ( ( ) )
647
613
}
648
614
649
- #[ cfg( not( parallel_compiler) ) ]
650
- #[ inline( always) ]
651
- pub fn write ( & self ) -> WriteGuard < ' _ , T > {
652
- self . 0 . borrow_mut ( )
653
- }
654
-
655
- #[ cfg( parallel_compiler) ]
656
615
#[ inline( always) ]
657
616
pub fn write ( & self ) -> WriteGuard < ' _ , T > {
658
- if ERROR_CHECKING {
659
- self . 0 . try_write ( ) . expect ( "lock was already held" )
660
- } else {
661
- self . 0 . write ( )
662
- }
617
+ self . 0 . write ( )
663
618
}
664
619
665
620
#[ inline( always) ]
0 commit comments