Skip to content

Commit ad7c8a8

Browse files
committed
code polish
1 parent 0180099 commit ad7c8a8

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

core/src/net/event_loop.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::common::constants::{CoroutineState, PoolState, Syscall, SyscallState,
44
use crate::net::selector::{Event, Events, Poller, Selector};
55
use crate::scheduler::SchedulableCoroutine;
66
use crate::{error, impl_current_for, impl_display_by_debug, info};
7-
use crossbeam_utils::atomic::AtomicCell;
87
use dashmap::DashSet;
98
use once_cell::sync::Lazy;
109
use rand::Rng;
@@ -28,8 +27,6 @@ cfg_if::cfg_if! {
2827
#[repr(C)]
2928
#[derive(Debug)]
3029
pub(crate) struct EventLoop<'e> {
31-
//状态
32-
state: AtomicCell<PoolState>,
3330
stop: Arc<(Mutex<bool>, Condvar)>,
3431
shared_stop: Arc<(Mutex<AtomicUsize>, Condvar)>,
3532
cpu: usize,
@@ -87,7 +84,6 @@ impl<'e> EventLoop<'e> {
8784
shared_stop: Arc<(Mutex<AtomicUsize>, Condvar)>,
8885
) -> std::io::Result<Self> {
8986
Ok(EventLoop {
90-
state: AtomicCell::new(PoolState::Running),
9187
stop: Arc::new((Mutex::new(false), Condvar::new())),
9288
shared_stop,
9389
cpu,

core/src/scheduler.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -322,26 +322,28 @@ impl<'s> Scheduler<'s> {
322322

323323
fn check_ready(&mut self) -> std::io::Result<()> {
324324
// Check if the elements in the suspend queue are ready
325-
if let Some(item) = self.suspend.peek() {
326-
if now() >= item.timestamp {
327-
if let Some(item) = self.suspend.pop() {
328-
item.coroutine.ready()?;
329-
self.ready.push(item.coroutine);
330-
}
325+
while let Some(item) = self.suspend.peek() {
326+
if now() < item.timestamp {
327+
break;
328+
}
329+
if let Some(item) = self.suspend.pop() {
330+
item.coroutine.ready()?;
331+
self.ready.push(item.coroutine);
331332
}
332333
}
333334
// Check if the elements in the syscall suspend queue are ready
334-
if let Some(item) = self.syscall_suspend.peek() {
335-
if now() >= item.timestamp {
336-
if let Some(item) = self.syscall_suspend.pop() {
337-
if let Some((_, co)) = self.syscall.remove(item.co_name) {
338-
match co.state() {
339-
CoroutineState::SystemCall(val, syscall, SyscallState::Suspend(_)) => {
340-
co.syscall(val, syscall, SyscallState::Timeout)?;
341-
self.ready.push(co);
342-
}
343-
_ => unreachable!("check_ready should never execute to here"),
335+
while let Some(item) = self.syscall_suspend.peek() {
336+
if now() < item.timestamp {
337+
break;
338+
}
339+
if let Some(item) = self.syscall_suspend.pop() {
340+
if let Some((_, co)) = self.syscall.remove(item.co_name) {
341+
match co.state() {
342+
CoroutineState::SystemCall(val, syscall, SyscallState::Suspend(_)) => {
343+
co.syscall(val, syscall, SyscallState::Timeout)?;
344+
self.ready.push(co);
344345
}
346+
_ => unreachable!("check_ready should never execute to here"),
345347
}
346348
}
347349
}

0 commit comments

Comments
 (0)