@@ -18,15 +18,11 @@ use core::time::Duration;
1818
1919use crossbeam_utils:: Backoff ;
2020use hermit_sync:: without_interrupts;
21- #[ cfg( feature = "net" ) ]
22- use smoltcp:: time:: Instant ;
2321
2422use crate :: arch:: core_local;
2523use crate :: errno:: Errno ;
2624use crate :: executor:: task:: AsyncTask ;
2725use crate :: io;
28- #[ cfg( feature = "net" ) ]
29- use crate :: scheduler:: PerCoreSchedulerExt ;
3026use crate :: synch:: futex:: * ;
3127
3228/// WakerRegistration is derived from smoltcp's
@@ -155,101 +151,27 @@ where
155151
156152 let now = crate :: arch:: kernel:: systemtime:: now_micros ( ) ;
157153 if let Poll :: Ready ( t) = result {
158- // allow network interrupts
159- #[ cfg( feature = "net" ) ]
160- {
161- if let Some ( mut guard) = crate :: executor:: network:: NIC . try_lock ( ) {
162- let delay = if let Ok ( nic) = guard. as_nic_mut ( ) {
163- nic. set_polling_mode ( false ) ;
164-
165- nic. poll_delay ( Instant :: from_micros_const ( now. try_into ( ) . unwrap ( ) ) )
166- . map ( |d| d. total_micros ( ) )
167- } else {
168- None
169- } ;
170- core_local:: core_scheduler ( ) . add_network_timer (
171- delay. map ( |d| crate :: arch:: processor:: get_timer_ticks ( ) + d) ,
172- ) ;
173- }
174- }
175-
176154 return t;
177155 }
178156
179157 if let Some ( duration) = timeout
180158 && Duration :: from_micros ( now - start) >= duration
181159 {
182- // allow network interrupts
183- #[ cfg( feature = "net" ) ]
184- {
185- if let Some ( mut guard) = crate :: executor:: network:: NIC . try_lock ( ) {
186- let delay = if let Ok ( nic) = guard. as_nic_mut ( ) {
187- nic. set_polling_mode ( false ) ;
188-
189- nic. poll_delay ( Instant :: from_micros_const ( now. try_into ( ) . unwrap ( ) ) )
190- . map ( |d| d. total_micros ( ) )
191- } else {
192- None
193- } ;
194- core_local:: core_scheduler ( ) . add_network_timer (
195- delay. map ( |d| crate :: arch:: processor:: get_timer_ticks ( ) + d) ,
196- ) ;
197- }
198- }
199-
200160 return Err ( Errno :: Time ) ;
201161 }
202162
203- # [ cfg ( feature = "net" ) ]
163+ // TODO: I have no idea whether this is correct
204164 if backoff. is_completed ( ) {
205- let delay = if let Some ( mut guard) = crate :: executor:: network:: NIC . try_lock ( ) {
206- if let Ok ( nic) = guard. as_nic_mut ( ) {
207- nic. set_polling_mode ( false ) ;
208-
209- nic. poll_delay ( Instant :: from_micros_const ( now. try_into ( ) . unwrap ( ) ) )
210- . map ( |d| d. total_micros ( ) )
211- } else {
212- None
213- }
214- } else {
215- None
216- } ;
217-
218- if delay. unwrap_or ( 10_000_000 ) > 10_000 {
219- core_local:: core_scheduler ( ) . add_network_timer (
220- delay. map ( |d| crate :: arch:: processor:: get_timer_ticks ( ) + d) ,
221- ) ;
222- let wakeup_time =
223- timeout. map ( |duration| start + u64:: try_from ( duration. as_micros ( ) ) . unwrap ( ) ) ;
224-
225- // switch to another task
226- task_notify. wait ( wakeup_time) ;
227-
228- // restore default values
229- if let Ok ( nic) = crate :: executor:: network:: NIC . lock ( ) . as_nic_mut ( ) {
230- nic. set_polling_mode ( true ) ;
231- }
232-
233- backoff. reset ( ) ;
234- }
235- } else {
236- backoff. snooze ( ) ;
237- }
238-
239- #[ cfg( not( feature = "net" ) ) ]
240- {
241- if backoff. is_completed ( ) {
242- let wakeup_time =
243- timeout. map ( |duration| start + u64:: try_from ( duration. as_micros ( ) ) . unwrap ( ) ) ;
165+ let wakeup_time =
166+ timeout. map ( |duration| start + u64:: try_from ( duration. as_micros ( ) ) . unwrap ( ) ) ;
244167
245- // switch to another task
246- task_notify. wait ( wakeup_time) ;
168+ // switch to another task
169+ task_notify. wait ( wakeup_time) ;
247170
248- // restore default values
249- backoff. reset ( ) ;
250- } else {
251- backoff. snooze ( ) ;
252- }
171+ // restore default values
172+ backoff. reset ( ) ;
173+ } else {
174+ backoff. snooze ( ) ;
253175 }
254176 }
255177}
0 commit comments