File tree 3 files changed +12
-6
lines changed
3 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ use alloc::sync::Arc;
25
25
use hashbrown:: HashMap ;
26
26
27
27
use crate :: userland:: scheduler;
28
+ use crate :: userland:: task:: TaskState ;
28
29
use crate :: utils:: sync:: Mutex ;
29
30
30
31
use super :: inode:: { INodeInterface , PollTable } ;
@@ -193,9 +194,10 @@ impl EPoll {
193
194
}
194
195
195
196
' search: loop {
196
- scheduler:: get_scheduler ( ) . inner . await_io ( ) ?;
197
-
198
- if current_task. load_sleep_duration ( ) == 0 && timeout > 0 {
197
+ if current_task. state ( ) == TaskState :: AwaitingIoDeadline
198
+ && current_task. load_sleep_duration ( ) == 0
199
+ && timeout > 0
200
+ {
199
201
// Timeout has expired.
200
202
return Ok ( 0 ) ;
201
203
}
@@ -224,6 +226,8 @@ impl EPoll {
224
226
n = 1 ;
225
227
break ' search;
226
228
}
229
+
230
+ scheduler:: get_scheduler ( ) . inner . await_io ( ) ?;
227
231
}
228
232
}
229
233
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ impl TaskQueue {
80
80
fn push_deadline_awaiting ( & mut self , task : Arc < Task > , duration : usize ) {
81
81
debug_assert ! ( !task. link. is_linked( ) ) ; // Make sure the task is not already linked
82
82
83
- task. update_state ( TaskState :: AwaitingIo ) ;
83
+ task. update_state ( TaskState :: AwaitingIoDeadline ) ;
84
84
task. set_sleep_duration ( crate :: arch:: time:: get_uptime_ticks ( ) + duration) ;
85
85
86
86
self . deadline_awaiting . push_back ( task) ;
@@ -214,8 +214,8 @@ impl SchedulerInterface for RoundRobin {
214
214
let _guard = IrqGuard :: new ( ) ;
215
215
let queue = self . queue . get_mut ( ) ;
216
216
217
- if task. state ( ) == TaskState :: AwaitingIo {
218
- let mut cursor = if task. load_sleep_duration ( ) > 0 {
217
+ if task. state ( ) == TaskState :: AwaitingIo || task . state ( ) == TaskState :: AwaitingIoDeadline {
218
+ let mut cursor = if task. state ( ) == TaskState :: AwaitingIoDeadline {
219
219
unsafe { queue. deadline_awaiting . cursor_mut_from_ptr ( task. as_ref ( ) ) }
220
220
} else {
221
221
unsafe { queue. awaiting . cursor_mut_from_ptr ( task. as_ref ( ) ) }
Original file line number Diff line number Diff line change @@ -73,6 +73,7 @@ pub enum TaskState {
73
73
Runnable ,
74
74
Zombie ,
75
75
AwaitingIo ,
76
+ AwaitingIoDeadline ,
76
77
}
77
78
78
79
impl From < u8 > for TaskState {
@@ -81,6 +82,7 @@ impl From<u8> for TaskState {
81
82
0 => TaskState :: Runnable ,
82
83
1 => TaskState :: Zombie ,
83
84
2 => TaskState :: AwaitingIo ,
85
+ 3 => TaskState :: AwaitingIoDeadline ,
84
86
_ => panic ! ( "invalid task state" ) ,
85
87
}
86
88
}
You can’t perform that action at this time.
0 commit comments