8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- //! This mdoule defines types which are thread safe if cfg!(parallel_queries) is true.
11
+ //! This module defines types which are thread safe if cfg!(parallel_queries) is true.
12
12
//!
13
13
//! `Lrc` is an alias of either Rc or Arc.
14
14
//!
@@ -40,6 +40,29 @@ use std;
40
40
use std:: ops:: { Deref , DerefMut } ;
41
41
use owning_ref:: { Erased , OwningRef } ;
42
42
43
+ pub fn serial_join < A , B , RA , RB > ( oper_a : A , oper_b : B ) -> ( RA , RB )
44
+ where A : FnOnce ( ) -> RA ,
45
+ B : FnOnce ( ) -> RB
46
+ {
47
+ ( oper_a ( ) , oper_b ( ) )
48
+ }
49
+
50
+ pub struct SerialScope ;
51
+
52
+ impl SerialScope {
53
+ pub fn spawn < F > ( & self , f : F )
54
+ where F : FnOnce ( & SerialScope )
55
+ {
56
+ f ( self )
57
+ }
58
+ }
59
+
60
+ pub fn serial_scope < F , R > ( f : F ) -> R
61
+ where F : FnOnce ( & SerialScope ) -> R
62
+ {
63
+ f ( & SerialScope )
64
+ }
65
+
43
66
cfg_if ! {
44
67
if #[ cfg( not( parallel_queries) ) ] {
45
68
pub auto trait Send { }
@@ -55,9 +78,19 @@ cfg_if! {
55
78
}
56
79
}
57
80
81
+ pub use self :: serial_join as join;
82
+ pub use self :: serial_scope as scope;
83
+
84
+ pub use std:: iter:: Iterator as ParallelIterator ;
85
+
86
+ pub fn par_iter<T : IntoIterator >( t: T ) -> T :: IntoIter {
87
+ t. into_iter( )
88
+ }
89
+
58
90
pub type MetadataRef = OwningRef <Box <Erased >, [ u8 ] >;
59
91
60
92
pub use std:: rc:: Rc as Lrc ;
93
+ pub use std:: rc:: Weak as Weak ;
61
94
pub use std:: cell:: Ref as ReadGuard ;
62
95
pub use std:: cell:: RefMut as WriteGuard ;
63
96
pub use std:: cell:: RefMut as LockGuard ;
@@ -160,13 +193,22 @@ cfg_if! {
160
193
pub use parking_lot:: MutexGuard as LockGuard ;
161
194
162
195
pub use std:: sync:: Arc as Lrc ;
196
+ pub use std:: sync:: Weak as Weak ;
163
197
164
198
pub use self :: Lock as MTLock ;
165
199
166
200
use parking_lot:: Mutex as InnerLock ;
167
201
use parking_lot:: RwLock as InnerRwLock ;
168
202
169
203
use std:: thread;
204
+ pub use rayon:: { join, scope} ;
205
+
206
+ pub use rayon:: iter:: ParallelIterator ;
207
+ use rayon:: iter:: IntoParallelIterator ;
208
+
209
+ pub fn par_iter<T : IntoParallelIterator >( t: T ) -> T :: Iter {
210
+ t. into_par_iter( )
211
+ }
170
212
171
213
pub type MetadataRef = OwningRef <Box <Erased + Send + Sync >, [ u8 ] >;
172
214
0 commit comments