1818//!
1919//! | Type | Serial version | Parallel version |
2020//! | ----------------------- | ------------------- | ------------------------------- |
21- //! | `LRef<'a, T>` [^2] | `&'a mut T` | `&'a T` |
22- //! | | | |
2321//! | `Lock<T>` | `RefCell<T>` | `RefCell<T>` or |
2422//! | | | `parking_lot::Mutex<T>` |
2523//! | `RwLock<T>` | `RefCell<T>` | `parking_lot::RwLock<T>` |
2624//! | `MTLock<T>` [^1] | `T` | `Lock<T>` |
27- //! | `MTLockRef<'a, T>` [^2] | `&'a mut MTLock<T>` | `&'a MTLock<T>` |
2825//! | | | |
2926//! | `ParallelIterator` | `Iterator` | `rayon::iter::ParallelIterator` |
3027//!
3128//! [^1]: `MTLock` is similar to `Lock`, but the serial version avoids the cost
3229//! of a `RefCell`. This is appropriate when interior mutability is not
3330//! required.
34- //!
35- //! [^2]: `MTRef`, `MTLockRef` are type aliases.
3631
3732use std:: collections:: HashMap ;
3833use std:: hash:: { BuildHasher , Hash } ;
3934
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+ } ;
4139
42- mod lock;
40+ pub use self :: atomic:: AtomicU64 ;
41+ pub use self :: freeze:: { FreezeLock , FreezeReadGuard , FreezeWriteGuard } ;
4342#[ 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:: * ;
4851
52+ mod freeze;
53+ mod lock;
4954mod 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-
5355mod vec;
56+ mod worker_local;
5457
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+ }
5769
5870mod mode {
5971 use std:: sync:: atomic:: { AtomicU8 , Ordering } ;
@@ -97,21 +109,6 @@ mod mode {
97109
98110// FIXME(parallel_compiler): Get rid of these aliases across the compiler.
99111
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-
115112#[ derive( Debug , Default ) ]
116113pub struct MTLock < T > ( Lock < T > ) ;
117114
@@ -142,14 +139,10 @@ impl<T> MTLock<T> {
142139 }
143140}
144141
145- use parking_lot:: RwLock as InnerRwLock ;
146-
147142/// This makes locks panic if they are already held.
148143/// It is only useful when you are running in a single thread
149144const ERROR_CHECKING : bool = false ;
150145
151- pub type MTLockRef < ' a , T > = LRef < ' a , MTLock < T > > ;
152-
153146#[ derive( Default ) ]
154147#[ repr( align( 64 ) ) ]
155148pub 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>
167160}
168161
169162#[ derive( Debug , Default ) ]
170- pub struct RwLock < T > ( InnerRwLock < T > ) ;
163+ pub struct RwLock < T > ( parking_lot :: RwLock < T > ) ;
171164
172165impl < T > RwLock < T > {
173166 #[ inline( always) ]
174167 pub fn new ( inner : T ) -> Self {
175- RwLock ( InnerRwLock :: new ( inner) )
168+ RwLock ( parking_lot :: RwLock :: new ( inner) )
176169 }
177170
178171 #[ inline( always) ]
0 commit comments