diff --git a/core/src/net/event_loop.rs b/core/src/net/event_loop.rs index acf1d374..14f82731 100644 --- a/core/src/net/event_loop.rs +++ b/core/src/net/event_loop.rs @@ -4,7 +4,6 @@ use crate::common::constants::{CoroutineState, PoolState, Syscall, SyscallState, use crate::net::selector::{Event, Events, Poller, Selector}; use crate::scheduler::SchedulableCoroutine; use crate::{error, impl_current_for, impl_display_by_debug, info}; -use crossbeam_utils::atomic::AtomicCell; use dashmap::DashSet; use once_cell::sync::Lazy; use rand::Rng; @@ -28,8 +27,6 @@ cfg_if::cfg_if! { #[repr(C)] #[derive(Debug)] pub(crate) struct EventLoop<'e> { - //状态 - state: AtomicCell, stop: Arc<(Mutex, Condvar)>, shared_stop: Arc<(Mutex, Condvar)>, cpu: usize, @@ -87,7 +84,6 @@ impl<'e> EventLoop<'e> { shared_stop: Arc<(Mutex, Condvar)>, ) -> std::io::Result { Ok(EventLoop { - state: AtomicCell::new(PoolState::Running), stop: Arc::new((Mutex::new(false), Condvar::new())), shared_stop, cpu, diff --git a/core/src/scheduler.rs b/core/src/scheduler.rs index dcd7cc24..49185ade 100644 --- a/core/src/scheduler.rs +++ b/core/src/scheduler.rs @@ -322,26 +322,28 @@ impl<'s> Scheduler<'s> { fn check_ready(&mut self) -> std::io::Result<()> { // Check if the elements in the suspend queue are ready - if let Some(item) = self.suspend.peek() { - if now() >= item.timestamp { - if let Some(item) = self.suspend.pop() { - item.coroutine.ready()?; - self.ready.push(item.coroutine); - } + while let Some(item) = self.suspend.peek() { + if now() < item.timestamp { + break; + } + if let Some(item) = self.suspend.pop() { + item.coroutine.ready()?; + self.ready.push(item.coroutine); } } // Check if the elements in the syscall suspend queue are ready - if let Some(item) = self.syscall_suspend.peek() { - if now() >= item.timestamp { - if let Some(item) = self.syscall_suspend.pop() { - if let Some((_, co)) = self.syscall.remove(item.co_name) { - match co.state() { - CoroutineState::SystemCall(val, syscall, SyscallState::Suspend(_)) => { - co.syscall(val, syscall, SyscallState::Timeout)?; - self.ready.push(co); - } - _ => unreachable!("check_ready should never execute to here"), + while let Some(item) = self.syscall_suspend.peek() { + if now() < item.timestamp { + break; + } + if let Some(item) = self.syscall_suspend.pop() { + if let Some((_, co)) = self.syscall.remove(item.co_name) { + match co.state() { + CoroutineState::SystemCall(val, syscall, SyscallState::Suspend(_)) => { + co.syscall(val, syscall, SyscallState::Timeout)?; + self.ready.push(co); } + _ => unreachable!("check_ready should never execute to here"), } } }