Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-preemptive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ "${CROSS}" = "1" ]; then
export CARGO_NET_RETRY=5
export CARGO_NET_TIMEOUT=10

cargo install cross --git https://github.com/cross-rs/cross --rev 4090beca3cfffa44371a5bba524de3a578aa46c3
cargo install cross --git https://github.com/cross-rs/cross --rev c7dee4d008475ce1c140773cbcd6078f4b86c2aa
CARGO=cross
fi

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ if [ "${CROSS}" = "1" ]; then
export CARGO_NET_RETRY=5
export CARGO_NET_TIMEOUT=10

cargo install cross --git https://github.com/cross-rs/cross --rev 4090beca3cfffa44371a5bba524de3a578aa46c3
cargo install cross --git https://github.com/cross-rs/cross --rev c7dee4d008475ce1c140773cbcd6078f4b86c2aa
CARGO=cross
fi

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ windows-sys = "0.59"
anyhow = "1.0"
slab = "0.4"
backtrace = "0.3"
minhook = "0.6"
minhook = "0.7"
psm = "0.1"

once_cell = "1"
Expand Down
2 changes: 1 addition & 1 deletion core/docs/en/coroutine.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The above is excerpted from [corosensei](https://github.com/Amanieu/corosensei).
| switch efficiency | ✅ Higher | ❌ High |
| memory usage | ✅ Bytes/KB/MB | ❌ KB/MB |
| scheduled by OS | ❌ | ✅ |
| stack grow | ✅ | ❌ |
| grow stack | ✅ | ❌ |

## Stackfull VS Stackless

Expand Down
20 changes: 5 additions & 15 deletions core/src/co_pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,7 @@ impl<'p> CoroutinePool<'p> {
match self.state() {
PoolState::Running => {}
PoolState::Stopping | PoolState::Stopped => {
return Err(Error::new(
ErrorKind::Other,
"The coroutine pool is stopping or stopped !",
))
return Err(Error::other("The coroutine pool is stopping or stopped !"))
}
}
let name = name.unwrap_or(format!("{}@{}", self.name(), uuid::Uuid::new_v4()));
Expand Down Expand Up @@ -292,12 +289,11 @@ impl<'p> CoroutinePool<'p> {
let (lock, cvar) = &*arc;
drop(
cvar.wait_timeout_while(
lock.lock()
.map_err(|e| Error::new(ErrorKind::Other, format!("{e}")))?,
lock.lock().map_err(|e| Error::other(format!("{e}")))?,
wait_time,
|&mut pending| pending,
)
.map_err(|e| Error::new(ErrorKind::Other, format!("{e}")))?,
.map_err(|e| Error::other(format!("{e}")))?,
);
if let Some(r) = self.try_take_task_result(key) {
self.notify(key);
Expand Down Expand Up @@ -372,8 +368,7 @@ impl<'p> CoroutinePool<'p> {
"The coroutine pool:{} has reached its maximum size !",
self.name()
);
return Err(Error::new(
ErrorKind::Other,
return Err(Error::other(
"The coroutine pool has reached its maximum size !",
));
}
Expand Down Expand Up @@ -447,12 +442,7 @@ impl<'p> CoroutinePool<'p> {
PoolState::Running | PoolState::Stopping => {
drop(self.try_grow());
}
PoolState::Stopped => {
return Err(Error::new(
ErrorKind::Other,
"The coroutine pool is stopped !",
))
}
PoolState::Stopped => return Err(Error::other("The coroutine pool is stopped !")),
}
Self::init_current(self);
let r = self.try_timeout_schedule(timeout_time);
Expand Down
11 changes: 6 additions & 5 deletions core/src/co_pool/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::co_pool::CoroutinePool;
use crate::common::constants::PoolState;
use std::io::{Error, ErrorKind};
use std::io::Error;

impl CoroutinePool<'_> {
/// running -> stopping
Expand Down Expand Up @@ -37,10 +37,11 @@ impl CoroutinePool<'_> {
assert_eq!(old_state, self.state.replace(new_state));
return Ok(old_state);
}
Err(Error::new(
ErrorKind::Other,
format!("{} unexpected {current}->{:?}", self.name(), new_state),
))
Err(Error::other(format!(
"{} unexpected {current}->{:?}",
self.name(),
new_state
)))
}
}

Expand Down
10 changes: 5 additions & 5 deletions core/src/coroutine/korosensei.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::cell::{Cell, RefCell, UnsafeCell};
use std::collections::VecDeque;
use std::ffi::c_longlong;
use std::fmt::Debug;
use std::io::{Error, ErrorKind};
use std::io::Error;

cfg_if::cfg_if! {
if #[cfg(unix)] {
Expand Down Expand Up @@ -452,10 +452,10 @@ where
CoroutineState::Syscall(y, syscall, state) => {
Ok(CoroutineState::Syscall(y, syscall, state))
}
_ => Err(Error::new(
ErrorKind::Other,
format!("{} unexpected state {current}", self.name()),
)),
_ => Err(Error::other(format!(
"{} unexpected state {current}",
self.name()
))),
}
}
CoroutineResult::Return(result) => {
Expand Down
80 changes: 31 additions & 49 deletions core/src/coroutine/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::coroutine::listener::Listener;
use crate::coroutine::Coroutine;
use crate::{error, info};
use std::fmt::Debug;
use std::io::{Error, ErrorKind};
use std::io::Error;

impl<Param, Yield, Return> Coroutine<'_, Param, Yield, Return>
where
Expand Down Expand Up @@ -45,14 +45,11 @@ where
}
_ => {}
}
Err(Error::new(
ErrorKind::Other,
format!(
"{} unexpected {current}->{:?}",
self.name(),
CoroutineState::<Yield, Return>::Ready
),
))
Err(Error::other(format!(
"{} unexpected {current}->{:?}",
self.name(),
CoroutineState::<Yield, Return>::Ready
)))
}

/// ready -> running
Expand Down Expand Up @@ -87,14 +84,11 @@ where
}
_ => {}
}
Err(Error::new(
ErrorKind::Other,
format!(
"{} unexpected {current}->{:?}",
self.name(),
CoroutineState::<Yield, Return>::Running
),
))
Err(Error::other(format!(
"{} unexpected {current}->{:?}",
self.name(),
CoroutineState::<Yield, Return>::Running
)))
}

/// running -> suspend
Expand All @@ -109,14 +103,11 @@ where
self.on_suspend(self, old_state);
return Ok(());
}
Err(Error::new(
ErrorKind::Other,
format!(
"{} unexpected {current}->{:?}",
self.name(),
CoroutineState::<Yield, Return>::Suspend(val, timestamp)
),
))
Err(Error::other(format!(
"{} unexpected {current}->{:?}",
self.name(),
CoroutineState::<Yield, Return>::Suspend(val, timestamp)
)))
}

/// running -> syscall
Expand Down Expand Up @@ -148,14 +139,11 @@ where
}
_ => {}
}
Err(Error::new(
ErrorKind::Other,
format!(
"{} unexpected {current}->{:?}",
self.name(),
CoroutineState::<Yield, Return>::Syscall(val, syscall, syscall_state)
),
))
Err(Error::other(format!(
"{} unexpected {current}->{:?}",
self.name(),
CoroutineState::<Yield, Return>::Syscall(val, syscall, syscall_state)
)))
}

/// running -> complete
Expand All @@ -170,14 +158,11 @@ where
self.on_complete(self, old_state, val);
return Ok(());
}
Err(Error::new(
ErrorKind::Other,
format!(
"{} unexpected {current}->{:?}",
self.name(),
CoroutineState::<Yield, Return>::Complete(val)
),
))
Err(Error::other(format!(
"{} unexpected {current}->{:?}",
self.name(),
CoroutineState::<Yield, Return>::Complete(val)
)))
}

/// running -> error
Expand All @@ -192,14 +177,11 @@ where
self.on_error(self, old_state, msg);
return Ok(());
}
Err(Error::new(
ErrorKind::Other,
format!(
"{} unexpected {current}->{:?}",
self.name(),
CoroutineState::<Yield, Return>::Error(msg)
),
))
Err(Error::other(format!(
"{} unexpected {current}->{:?}",
self.name(),
CoroutineState::<Yield, Return>::Error(msg)
)))
}
}

Expand Down
21 changes: 8 additions & 13 deletions core/src/net/operator/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl<'o> Operator<'o> {
&mut sock_info_len,
) != 0
{
return Err(Error::new(ErrorKind::Other, "get socket info failed"));
return Err(Error::other("get socket info failed"));
}
self.add_handle(fd as HANDLE)?;
let socket = WSASocketW(
Expand All @@ -251,10 +251,7 @@ impl<'o> Operator<'o> {
WSA_FLAG_OVERLAPPED,
);
if INVALID_SOCKET == socket {
return Err(Error::new(
ErrorKind::Other,
format!("add {syscall_name} operation failed"),
));
return Err(Error::other(format!("add {syscall_name} operation failed")));
}
let size = size_of::<SOCKADDR_IN>()
.saturating_add(16)
Expand Down Expand Up @@ -370,10 +367,9 @@ impl<'o> Operator<'o> {
{
let errno = WSAGetLastError();
if WSA_IO_PENDING != errno {
return Err(Error::new(
ErrorKind::Other,
format!("add {syscall_name} operation failed with {errno}"),
));
return Err(Error::other(format!(
"add {syscall_name} operation failed with {errno}"
)));
}
}
eprintln!("add {syscall_name} operation:{overlapped}");
Expand Down Expand Up @@ -464,10 +460,9 @@ impl<'o> Operator<'o> {
{
let errno = WSAGetLastError();
if WSA_IO_PENDING != errno {
return Err(Error::new(
ErrorKind::Other,
format!("add {syscall_name} operation failed with {errno}"),
));
return Err(Error::other(format!(
"add {syscall_name} operation failed with {errno}"
)));
}
}
eprintln!("add {syscall_name} operation:{overlapped}");
Expand Down
5 changes: 2 additions & 3 deletions core/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{co, impl_current_for, impl_display_by_debug, impl_for_named};
use dashmap::DashMap;
use std::collections::{BinaryHeap, HashMap, VecDeque};
use std::ffi::c_longlong;
use std::io::{Error, ErrorKind};
use std::io::Error;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::time::Duration;

Expand Down Expand Up @@ -318,8 +318,7 @@ impl<'s> Scheduler<'s> {
);
}
_ => {
return Err(Error::new(
ErrorKind::Other,
return Err(Error::other(
"try_timeout_schedule should never execute to here",
));
}
Expand Down
11 changes: 3 additions & 8 deletions core/tests/coroutine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ fn coroutine_panic() -> std::io::Result<()> {
})?;
match coroutine.resume()? {
CoroutineState::Error(_) => Ok(()),
_ => Err(std::io::Error::new(
std::io::ErrorKind::Other,
"The coroutine should panic",
)),
_ => Err(std::io::Error::other("The coroutine should panic")),
}
}

Expand Down Expand Up @@ -233,8 +230,7 @@ fn coroutine_preemptive() -> std::io::Result<()> {
)
.unwrap();
if result.1.timed_out() {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
Err(std::io::Error::other(
"The monitor should send signals to coroutines in running state",
))
} else {
Expand Down Expand Up @@ -279,8 +275,7 @@ fn coroutine_syscall_not_preemptive() -> std::io::Result<()> {
if result.1.timed_out() {
Ok(())
} else {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
Err(std::io::Error::other(
"The monitor should not send signals to coroutines in syscall state",
))
}
Expand Down
Loading
Loading