1
1
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
4
- use bach:: time:: scheduler;
4
+ use bach:: { environment :: Macrostep , time:: scheduler} ;
5
5
use core:: task:: Poll ;
6
6
use s2n_quic_core:: {
7
7
endpoint:: Endpoint , inet:: SocketAddress , io:: event_loop:: EventLoop , path:: mtu,
@@ -42,7 +42,7 @@ pub mod rand {
42
42
43
43
#[ inline]
44
44
fn gen_bool ( & mut self ) -> bool {
45
- gen ( )
45
+ produce :: < bool > ( ) . any ( )
46
46
}
47
47
48
48
#[ inline]
@@ -52,7 +52,7 @@ pub mod rand {
52
52
53
53
#[ inline]
54
54
fn gen_range ( & mut self , range : core:: ops:: Range < u64 > ) -> u64 {
55
- gen_range ( range)
55
+ range. any ( )
56
56
}
57
57
}
58
58
}
@@ -90,7 +90,7 @@ impl<N: Network> Executor<N> {
90
90
}
91
91
92
92
pub fn enter < F : FnOnce ( ) -> O , O > ( & mut self , f : F ) -> O {
93
- self . executor . environment ( ) . enter ( f)
93
+ bach :: environment :: Environment :: enter ( self . executor . environment ( ) , f)
94
94
}
95
95
96
96
pub fn run ( & mut self ) {
@@ -100,7 +100,7 @@ impl<N: Network> Executor<N> {
100
100
pub fn close ( & mut self ) {
101
101
// close the environment, which notifies all of the tasks that we're shutting down
102
102
self . executor . environment ( ) . close ( || { } ) ;
103
- while self . executor . macrostep ( ) > 0 { }
103
+ while self . executor . macrostep ( ) . tasks > 0 { }
104
104
105
105
// then close the actual executor
106
106
self . executor . close ( )
@@ -123,10 +123,6 @@ struct Env<N> {
123
123
}
124
124
125
125
impl < N > Env < N > {
126
- fn enter < F : FnOnce ( ) -> O , O > ( & self , f : F ) -> O {
127
- self . handle . enter ( || self . time . enter ( || self . rand . enter ( f) ) )
128
- }
129
-
130
126
fn close < F : FnOnce ( ) > ( & mut self , f : F ) {
131
127
let handle = & mut self . handle ;
132
128
let rand = & mut self . rand ;
@@ -144,11 +140,15 @@ impl<N> Env<N> {
144
140
}
145
141
}
146
142
147
- impl < N : Network > bach:: executor:: Environment for Env < N > {
148
- fn run < Tasks , F > ( & mut self , tasks : Tasks ) -> Poll < ( ) >
143
+ impl < N : Network > bach:: environment:: Environment for Env < N > {
144
+ fn enter < F : FnOnce ( ) -> O , O > ( & mut self , f : F ) -> O {
145
+ self . handle . enter ( || self . time . enter ( || self . rand . enter ( f) ) )
146
+ }
147
+
148
+ fn run < Tasks , R > ( & mut self , tasks : Tasks ) -> Poll < ( ) >
149
149
where
150
- Tasks : Iterator < Item = F > + Send ,
151
- F : ' static + FnOnce ( ) -> Poll < ( ) > + Send ,
150
+ Tasks : IntoIterator < Item = R > ,
151
+ R : bach :: environment :: Runnable ,
152
152
{
153
153
let mut is_ready = true ;
154
154
@@ -165,7 +165,7 @@ impl<N: Network> bach::executor::Environment for Env<N> {
165
165
time. enter ( || {
166
166
rand. enter ( || {
167
167
for task in tasks {
168
- is_ready &= task ( ) . is_ready ( ) ;
168
+ is_ready &= task. run ( ) . is_ready ( ) ;
169
169
}
170
170
network. execute ( buffers) ;
171
171
} )
@@ -179,11 +179,11 @@ impl<N: Network> bach::executor::Environment for Env<N> {
179
179
}
180
180
}
181
181
182
- fn on_macrostep ( & mut self , count : usize ) {
182
+ fn on_macrostep ( & mut self , macrostep : Macrostep ) -> Macrostep {
183
183
// only advance time after a stall
184
- if count > 0 {
184
+ if macrostep . tasks > 0 {
185
185
self . stalled_iterations = 0 ;
186
- return ;
186
+ return macrostep ;
187
187
}
188
188
189
189
self . stalled_iterations += 1 ;
@@ -206,6 +206,7 @@ impl<N: Network> bach::executor::Environment for Env<N> {
206
206
break ;
207
207
}
208
208
}
209
+ macrostep
209
210
}
210
211
211
212
fn close < F > ( & mut self , close : F )
0 commit comments