@@ -44,8 +44,8 @@ cfg_if! {
44
44
use std:: panic:: { resume_unwind, catch_unwind, AssertUnwindSafe } ;
45
45
46
46
/// This is a single threaded variant of `AtomicU64`, `AtomicUsize`, etc.
47
- /// It differs from `AtomicCell` in that it has explicit ordering arguments
48
- /// and is only intended for use with the native atomic types.
47
+ /// It has explicit ordering arguments and is only intended for use with
48
+ /// the native atomic types.
49
49
/// You should use this type through the `AtomicU64`, `AtomicUsize`, etc, type aliases
50
50
/// as it's not intended to be used separately.
51
51
#[ derive( Debug ) ]
@@ -59,6 +59,11 @@ cfg_if! {
59
59
}
60
60
61
61
impl <T : Copy > Atomic <T > {
62
+ #[ inline]
63
+ pub fn into_inner( self ) -> T {
64
+ self . 0 . into_inner( )
65
+ }
66
+
62
67
#[ inline]
63
68
pub fn load( & self , _: Ordering ) -> T {
64
69
self . 0 . get( )
@@ -68,6 +73,11 @@ cfg_if! {
68
73
pub fn store( & self , val: T , _: Ordering ) {
69
74
self . 0 . set( val)
70
75
}
76
+
77
+ #[ inline]
78
+ pub fn swap( & self , val: T , _: Ordering ) -> T {
79
+ self . 0 . replace( val)
80
+ }
71
81
}
72
82
73
83
impl <T : Copy + PartialEq > Atomic <T > {
@@ -180,6 +190,12 @@ cfg_if! {
180
190
pub fn new<F : FnMut ( usize ) -> T >( mut f: F ) -> WorkerLocal <T > {
181
191
WorkerLocal ( OneThread :: new( f( 0 ) ) )
182
192
}
193
+
194
+ /// Returns the worker-local value for each thread
195
+ #[ inline]
196
+ pub fn into_inner( self ) -> Vec <T > {
197
+ vec![ OneThread :: into_inner( self . 0 ) ]
198
+ }
183
199
}
184
200
185
201
impl <T > Deref for WorkerLocal <T > {
@@ -207,6 +223,16 @@ cfg_if! {
207
223
self . 0
208
224
}
209
225
226
+ #[ inline( always) ]
227
+ pub fn get_mut( & mut self ) -> & mut T {
228
+ & mut self . 0
229
+ }
230
+
231
+ #[ inline( always) ]
232
+ pub fn lock( & self ) -> & T {
233
+ & self . 0
234
+ }
235
+
210
236
#[ inline( always) ]
211
237
pub fn lock_mut( & mut self ) -> & mut T {
212
238
& mut self . 0
@@ -437,6 +463,16 @@ impl<T> RwLock<T> {
437
463
RwLock ( InnerRwLock :: new ( inner) )
438
464
}
439
465
466
+ #[ inline( always) ]
467
+ pub fn into_inner ( self ) -> T {
468
+ self . 0 . into_inner ( )
469
+ }
470
+
471
+ #[ inline( always) ]
472
+ pub fn get_mut ( & mut self ) -> & mut T {
473
+ self . 0 . get_mut ( )
474
+ }
475
+
440
476
#[ cfg( not( parallel_compiler) ) ]
441
477
#[ inline( always) ]
442
478
pub fn read ( & self ) -> ReadGuard < ' _ , T > {
@@ -453,6 +489,11 @@ impl<T> RwLock<T> {
453
489
}
454
490
}
455
491
492
+ #[ inline( always) ]
493
+ pub fn with_read_lock < F : FnOnce ( & T ) -> R , R > ( & self , f : F ) -> R {
494
+ f ( & * self . read ( ) )
495
+ }
496
+
456
497
#[ cfg( not( parallel_compiler) ) ]
457
498
#[ inline( always) ]
458
499
pub fn try_write ( & self ) -> Result < WriteGuard < ' _ , T > , ( ) > {
@@ -481,6 +522,11 @@ impl<T> RwLock<T> {
481
522
}
482
523
}
483
524
525
+ #[ inline( always) ]
526
+ pub fn with_write_lock < F : FnOnce ( & mut T ) -> R , R > ( & self , f : F ) -> R {
527
+ f ( & mut * self . write ( ) )
528
+ }
529
+
484
530
#[ inline( always) ]
485
531
pub fn borrow ( & self ) -> ReadGuard < ' _ , T > {
486
532
self . read ( )
@@ -529,6 +575,12 @@ impl<T> OneThread<T> {
529
575
inner,
530
576
}
531
577
}
578
+
579
+ #[ inline( always) ]
580
+ pub fn into_inner ( value : Self ) -> T {
581
+ value. check ( ) ;
582
+ value. inner
583
+ }
532
584
}
533
585
534
586
impl < T > Deref for OneThread < T > {
0 commit comments