@@ -2,7 +2,7 @@ use std::cell::Cell;
2
2
use std:: io;
3
3
use std:: iter;
4
4
use std:: sync:: atomic:: { self , Ordering } ;
5
- use std:: sync:: Arc ;
5
+ use std:: sync:: { Arc , Mutex } ;
6
6
use std:: thread;
7
7
use std:: time:: Duration ;
8
8
@@ -22,6 +22,11 @@ thread_local! {
22
22
static YIELD_NOW : Cell <bool > = Cell :: new( false ) ;
23
23
}
24
24
25
+ struct Scheduler {
26
+ /// Set to `true` while a machine is polling the reactor.
27
+ polling : bool ,
28
+ }
29
+
25
30
/// An async runtime.
26
31
pub struct Runtime {
27
32
/// The reactor.
@@ -33,7 +38,11 @@ pub struct Runtime {
33
38
/// Handles to local queues for stealing work.
34
39
stealers : Vec < Stealer < Runnable > > ,
35
40
41
+ /// Machines to start
36
42
machines : Vec < Arc < Machine > > ,
43
+
44
+ /// The scheduler state.
45
+ sched : Mutex < Scheduler > ,
37
46
}
38
47
39
48
impl Runtime {
@@ -57,6 +66,7 @@ impl Runtime {
57
66
injector : Injector :: new ( ) ,
58
67
stealers,
59
68
machines,
69
+ sched : Mutex :: new ( Scheduler { polling : false } ) ,
60
70
}
61
71
}
62
72
@@ -116,7 +126,29 @@ impl Runtime {
116
126
/// This function might not poll the reactor at all so do not rely on it doing anything. Only
117
127
/// use for optimization.
118
128
fn quick_poll ( & self ) -> io:: Result < bool > {
119
- return self . reactor . poll ( Some ( Duration :: from_secs ( 0 ) ) ) ;
129
+ let mut sched = self . sched . lock ( ) . unwrap ( ) ;
130
+ sched. polling = true ;
131
+ drop ( sched) ;
132
+
133
+ let result = self . reactor . poll ( Some ( Duration :: from_secs ( 0 ) ) ) ;
134
+
135
+ let mut sched = self . sched . lock ( ) . unwrap ( ) ;
136
+ sched. polling = false ;
137
+
138
+ result
139
+ }
140
+
141
+ fn poll ( & self ) -> io:: Result < bool > {
142
+ let mut sched = self . sched . lock ( ) . unwrap ( ) ;
143
+ sched. polling = true ;
144
+ drop ( sched) ;
145
+
146
+ let result = self . reactor . poll ( None ) ;
147
+
148
+ let mut sched = self . sched . lock ( ) . unwrap ( ) ;
149
+ sched. polling = false ;
150
+
151
+ result
120
152
}
121
153
}
122
154
@@ -242,7 +274,7 @@ impl Machine {
242
274
continue ;
243
275
}
244
276
245
- rt. reactor . poll ( None ) . unwrap ( ) ;
277
+ rt. poll ( ) . unwrap ( ) ;
246
278
247
279
runs = 0 ;
248
280
fails = 0 ;
0 commit comments