use std::fmt::{Debug, Display, Formatter};
pub const DEFAULT_STACK_SIZE: usize = 64 * 1024;
pub const MONITOR_CPU: usize = 0;
#[allow(non_camel_case_types, missing_docs)]
#[repr(C)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Syscall {
sleep,
usleep,
nanosleep,
poll,
select,
#[cfg(target_os = "linux")]
accept4,
#[cfg(target_os = "linux")]
epoll_ctl,
#[cfg(target_os = "linux")]
epoll_wait,
#[cfg(target_os = "linux")]
io_uring_enter,
#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "freebsd",
target_os = "dragonfly",
target_os = "openbsd",
target_os = "netbsd"
))]
kevent,
#[cfg(windows)]
iocp,
recv,
recvfrom,
read,
pread,
readv,
preadv,
recvmsg,
connect,
listen,
accept,
shutdown,
close,
socket,
send,
sendto,
write,
pwrite,
writev,
pwritev,
sendmsg,
fsync,
renameat,
#[cfg(target_os = "linux")]
renameat2,
mkdirat,
openat,
}
impl Display for Syscall {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Debug::fmt(self, f)
}
}
thread_local! {
static SYSCALL: std::cell::RefCell<std::collections::VecDeque<Syscall>> = std::cell::RefCell::new(std::collections::VecDeque::new());
}
#[allow(missing_docs)]
impl Syscall {
pub fn init_current(current: Self) {
SYSCALL.with(|s| {
s.borrow_mut().push_front(current);
});
}
#[must_use]
pub fn current() -> Option<Self> {
SYSCALL.with(|s| s.borrow().front().copied())
}
pub fn clean_current() {
SYSCALL.with(|s| _ = s.borrow_mut().pop_front());
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum SyscallState {
Executing,
Suspend(u64),
Timeout,
Finished,
}
impl Display for SyscallState {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Debug::fmt(self, f)
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum CoroutineState<Y, R>
where
Y: Copy + Eq + PartialEq,
R: Copy + Eq + PartialEq,
{
Created,
Ready,
Running,
Suspend(Y, u64),
SystemCall(Y, Syscall, SyscallState),
Complete(R),
Error(&'static str),
}
impl<Y, R> Display for CoroutineState<Y, R>
where
Y: Copy + Eq + PartialEq + Debug,
R: Copy + Eq + PartialEq + Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Debug::fmt(self, f)
}
}
#[repr(C)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum PoolState {
Created,
Running(bool),
Stopping(bool),
Stopped,
}
impl Display for PoolState {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Debug::fmt(self, f)
}
}