The deadline is one more stamped waker on the select's wait epoch: a unit TimerTarget whose on_timeout is a bare unpark_at. Nothing registers in any arm for it, so there is nothing to cancel or leak — an arm winning leaves the timer entry to die at its epoch CAS; the timer winning leaves the arms' registrations to self-clean like any select loser's. Classification is pure channel state (wakes are precise): some arm ready -> Some(first, priority order); none -> the timer was the only remaining stamped waker -> None. Message-first on a raced deadline, same as recv_timeout. Registration pass factored into register_arms, which owns the retire_wait obligation on the ready-now exit for both entry points.
74 lines
2.6 KiB
Rust
74 lines
2.6 KiB
Rust
//! # smarm — Silly Marks Abstract Rust Machine
|
|
//!
|
|
//! Erlang-style green-thread actor concurrency for Rust.
|
|
//!
|
|
//! Multi-threaded: N scheduler OS threads (default: one per CPU) share a
|
|
//! single global run queue behind a `Mutex`. Actors communicate by sending
|
|
//! `Send` messages over channels; every actor has a supervisor. Synchronisation
|
|
//! primitives — `Mutex<T>` with mandatory lock timeouts, channel `recv`,
|
|
//! `sleep`, and epoll-backed `wait_readable`/`wait_writable` — all park the
|
|
//! green thread, never the OS thread.
|
|
//!
|
|
//! See `LOOM.md` for the design intent and the deferred-for-later list.
|
|
|
|
pub mod stack;
|
|
pub mod context;
|
|
pub mod preempt;
|
|
pub mod pid;
|
|
pub mod actor;
|
|
pub mod channel;
|
|
pub mod scheduler;
|
|
pub mod supervisor;
|
|
pub mod timer;
|
|
pub mod io;
|
|
pub mod mutex;
|
|
pub mod monitor;
|
|
pub mod registry;
|
|
pub mod link;
|
|
pub mod gen_server;
|
|
pub mod runtime;
|
|
pub(crate) mod raw_mutex;
|
|
pub(crate) mod slot_state;
|
|
pub(crate) mod sync_shim;
|
|
#[doc(hidden)] // pub only so benches/rq_micro.rs can drive the raw structures
|
|
pub mod run_queue;
|
|
pub mod trace;
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Global allocator
|
|
// ---------------------------------------------------------------------------
|
|
|
|
#[global_allocator]
|
|
static ALLOCATOR: preempt::PreemptingAllocator = preempt::PreemptingAllocator;
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Public API re-exports
|
|
// ---------------------------------------------------------------------------
|
|
|
|
pub use channel::{channel, select, select_timeout, Receiver, RecvError, RecvTimeoutError, Selectable, Sender};
|
|
pub use gen_server::{CallError, CallTimeoutError, CastError, GenServer, ServerRef};
|
|
pub use link::{link, trap_exit, unlink, ExitSignal};
|
|
pub use monitor::{demonitor, monitor, Down, DownReason, Monitor, MonitorId};
|
|
pub use mutex::{LockTimeout, Mutex, MutexGuard};
|
|
pub use pid::Pid;
|
|
pub use registry::{name_of, register, unregister, whereis, RegisterError};
|
|
pub use runtime::{init, Config, Runtime};
|
|
pub use scheduler::{
|
|
block_on_io, request_stop, run, self_pid, sleep, spawn, spawn_under, wait_readable,
|
|
wait_writable, yield_now, JoinError, JoinHandle,
|
|
};
|
|
pub use supervisor::{ChildSpec, OneForOne, Restart, Signal, Strategy};
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// check!()
|
|
// ---------------------------------------------------------------------------
|
|
|
|
/// Voluntarily check whether this actor's timeslice has expired, yielding
|
|
/// if so.
|
|
#[macro_export]
|
|
macro_rules! check {
|
|
() => {
|
|
$crate::preempt::maybe_preempt()
|
|
};
|
|
}
|