1
+ #![ cfg_attr( not( feature = "parallel" ) , allow( unused_variables) ) ]
2
+
1
3
use std:: { cell:: RefCell , mem:: transmute} ;
2
4
3
5
#[ derive( Default ) ]
4
6
pub struct MaybeScope < ' a > ( ScopeLike < ' a > ) ;
5
7
6
8
enum ScopeLike < ' a > {
7
9
Scope ( Scope < ' a > ) ,
10
+ #[ cfg( feature = "parallel" ) ]
8
11
Global ( Option < chili:: Scope < ' a > > ) ,
9
12
}
10
13
11
14
impl Default for ScopeLike < ' _ > {
12
15
fn default ( ) -> Self {
13
- ScopeLike :: Global ( None )
16
+ #[ cfg( feature = "parallel" ) ]
17
+ {
18
+ ScopeLike :: Global ( None )
19
+ }
20
+
21
+ #[ cfg( not( feature = "parallel" ) ) ]
22
+ {
23
+ ScopeLike :: Scope ( Scope ( std:: marker:: PhantomData ) )
24
+ }
14
25
}
15
26
}
16
27
@@ -26,19 +37,25 @@ impl<'a> MaybeScope<'a> {
26
37
where
27
38
F : FnOnce ( Scope < ' a > ) -> R ,
28
39
{
40
+ #[ cfg( feature = "parallel" ) ]
29
41
let scope: & mut chili:: Scope = match & mut self . 0 {
30
42
ScopeLike :: Scope ( scope) => unsafe {
31
43
transmute :: < & mut chili:: Scope , & mut chili:: Scope > ( & mut scope. 0 )
32
44
} ,
45
+ #[ cfg( feature = "parallel" ) ]
33
46
ScopeLike :: Global ( global_scope) => {
34
47
let scope = global_scope. get_or_insert_with ( || chili:: Scope :: global ( ) ) ;
35
48
36
49
unsafe { transmute :: < & mut chili:: Scope , & mut chili:: Scope > ( scope) }
37
50
}
38
51
} ;
39
52
53
+ #[ cfg( feature = "parallel" ) ]
40
54
let scope = Scope ( scope) ;
41
55
56
+ #[ cfg( not( feature = "parallel" ) ) ]
57
+ let scope = Scope ( std:: marker:: PhantomData ) ;
58
+
42
59
f ( scope)
43
60
}
44
61
}
@@ -109,6 +126,7 @@ where
109
126
RA : Send ,
110
127
RB : Send ,
111
128
{
129
+ #[ cfg( feature = "parallel" ) ]
112
130
let ( ra, rb) = scope. 0 . join (
113
131
|scope| {
114
132
let scope = Scope ( unsafe { transmute :: < & mut chili:: Scope , & mut chili:: Scope > ( scope) } ) ;
@@ -122,5 +140,11 @@ where
122
140
} ,
123
141
) ;
124
142
143
+ #[ cfg( not( feature = "parallel" ) ) ]
144
+ let ( ra, rb) = (
145
+ oper_a ( Scope ( std:: marker:: PhantomData ) ) ,
146
+ oper_b ( Scope ( std:: marker:: PhantomData ) ) ,
147
+ ) ;
148
+
125
149
( ra, rb)
126
150
}
0 commit comments