18
18
//!
19
19
//! | Type | Serial version | Parallel version |
20
20
//! | ----------------------- | ------------------- | ------------------------------- |
21
- //! | `LRef<'a, T>` [^2] | `&'a mut T` | `&'a T` |
22
- //! | | | |
23
21
//! | `Lock<T>` | `RefCell<T>` | `RefCell<T>` or |
24
22
//! | | | `parking_lot::Mutex<T>` |
25
23
//! | `RwLock<T>` | `RefCell<T>` | `parking_lot::RwLock<T>` |
26
24
//! | `MTLock<T>` [^1] | `T` | `Lock<T>` |
27
- //! | `MTLockRef<'a, T>` [^2] | `&'a mut MTLock<T>` | `&'a MTLock<T>` |
28
25
//! | | | |
29
26
//! | `ParallelIterator` | `Iterator` | `rayon::iter::ParallelIterator` |
30
27
//!
31
28
//! [^1]: `MTLock` is similar to `Lock`, but the serial version avoids the cost
32
29
//! of a `RefCell`. This is appropriate when interior mutability is not
33
30
//! required.
34
- //!
35
- //! [^2]: `MTRef`, `MTLockRef` are type aliases.
36
31
37
32
use std:: collections:: HashMap ;
38
33
use std:: hash:: { BuildHasher , Hash } ;
39
34
40
- pub use crate :: marker:: * ;
35
+ pub use parking_lot:: {
36
+ MappedRwLockReadGuard as MappedReadGuard , MappedRwLockWriteGuard as MappedWriteGuard ,
37
+ RwLockReadGuard as ReadGuard , RwLockWriteGuard as WriteGuard ,
38
+ } ;
41
39
42
- mod lock;
40
+ pub use self :: atomic:: AtomicU64 ;
41
+ pub use self :: freeze:: { FreezeLock , FreezeReadGuard , FreezeWriteGuard } ;
43
42
#[ doc( no_inline) ]
44
- pub use lock:: { Lock , LockGuard , Mode } ;
45
-
46
- mod worker_local;
47
- pub use worker_local:: { Registry , WorkerLocal } ;
43
+ pub use self :: lock:: { Lock , LockGuard , Mode } ;
44
+ pub use self :: mode:: { is_dyn_thread_safe, set_dyn_thread_safe_mode} ;
45
+ pub use self :: parallel:: {
46
+ join, par_for_each_in, par_map, parallel_guard, scope, try_par_for_each_in,
47
+ } ;
48
+ pub use self :: vec:: { AppendOnlyIndexVec , AppendOnlyVec } ;
49
+ pub use self :: worker_local:: { Registry , WorkerLocal } ;
50
+ pub use crate :: marker:: * ;
48
51
52
+ mod freeze;
53
+ mod lock;
49
54
mod parallel;
50
- pub use parallel:: { join, par_for_each_in, par_map, parallel_guard, scope, try_par_for_each_in} ;
51
- pub use vec:: { AppendOnlyIndexVec , AppendOnlyVec } ;
52
-
53
55
mod vec;
56
+ mod worker_local;
54
57
55
- mod freeze;
56
- pub use freeze:: { FreezeLock , FreezeReadGuard , FreezeWriteGuard } ;
58
+ /// Keep the conditional imports together in a submodule, so that import-sorting
59
+ /// doesn't split them up.
60
+ mod atomic {
61
+ // Most hosts can just use a regular AtomicU64.
62
+ #[ cfg( target_has_atomic = "64" ) ]
63
+ pub use std:: sync:: atomic:: AtomicU64 ;
64
+
65
+ // Some 32-bit hosts don't have AtomicU64, so use a fallback.
66
+ #[ cfg( not( target_has_atomic = "64" ) ) ]
67
+ pub use portable_atomic:: AtomicU64 ;
68
+ }
57
69
58
70
mod mode {
59
71
use std:: sync:: atomic:: { AtomicU8 , Ordering } ;
@@ -97,21 +109,6 @@ mod mode {
97
109
98
110
// FIXME(parallel_compiler): Get rid of these aliases across the compiler.
99
111
100
- pub use std:: sync:: OnceLock ;
101
- // Use portable AtomicU64 for targets without native 64-bit atomics
102
- #[ cfg( target_has_atomic = "64" ) ]
103
- pub use std:: sync:: atomic:: AtomicU64 ;
104
-
105
- pub use mode:: { is_dyn_thread_safe, set_dyn_thread_safe_mode} ;
106
- pub use parking_lot:: {
107
- MappedRwLockReadGuard as MappedReadGuard , MappedRwLockWriteGuard as MappedWriteGuard ,
108
- RwLockReadGuard as ReadGuard , RwLockWriteGuard as WriteGuard ,
109
- } ;
110
- #[ cfg( not( target_has_atomic = "64" ) ) ]
111
- pub use portable_atomic:: AtomicU64 ;
112
-
113
- pub type LRef < ' a , T > = & ' a T ;
114
-
115
112
#[ derive( Debug , Default ) ]
116
113
pub struct MTLock < T > ( Lock < T > ) ;
117
114
@@ -142,14 +139,10 @@ impl<T> MTLock<T> {
142
139
}
143
140
}
144
141
145
- use parking_lot:: RwLock as InnerRwLock ;
146
-
147
142
/// This makes locks panic if they are already held.
148
143
/// It is only useful when you are running in a single thread
149
144
const ERROR_CHECKING : bool = false ;
150
145
151
- pub type MTLockRef < ' a , T > = LRef < ' a , MTLock < T > > ;
152
-
153
146
#[ derive( Default ) ]
154
147
#[ repr( align( 64 ) ) ]
155
148
pub struct CacheAligned < T > ( pub T ) ;
@@ -167,12 +160,12 @@ impl<K: Eq + Hash, V: Eq, S: BuildHasher> HashMapExt<K, V> for HashMap<K, V, S>
167
160
}
168
161
169
162
#[ derive( Debug , Default ) ]
170
- pub struct RwLock < T > ( InnerRwLock < T > ) ;
163
+ pub struct RwLock < T > ( parking_lot :: RwLock < T > ) ;
171
164
172
165
impl < T > RwLock < T > {
173
166
#[ inline( always) ]
174
167
pub fn new ( inner : T ) -> Self {
175
- RwLock ( InnerRwLock :: new ( inner) )
168
+ RwLock ( parking_lot :: RwLock :: new ( inner) )
176
169
}
177
170
178
171
#[ inline( always) ]
0 commit comments