Skip to main content

hiver_runtime/scheduler/
mod.rs

1//! Task scheduler module
2//! 任务调度器模块
3//!
4//! This module provides the thread-per-core task scheduler
5//! and work-stealing scheduler implementations.
6//! 本模块提供 thread-per-core 任务调度器和工作窃取调度器实现。
7
8pub mod handle;
9pub mod local;
10pub mod queue;
11pub mod work_stealing;
12
13pub use handle::SchedulerHandle;
14pub use local::{Scheduler, SchedulerConfig};
15pub use queue::LocalQueue;
16pub use work_stealing::{WorkStealingConfig, WorkStealingHandle, WorkStealingScheduler};
17
18use std::future::Future;
19use std::pin::Pin;
20
21/// A pinned, boxed future
22/// 固定位置的盒子未来
23pub type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
24
25/// Task ID type
26/// 任务ID类型
27pub type TaskId = u64;
28
29/// Generate a new unique task ID
30/// 生成新的唯一任务ID
31#[must_use]
32pub fn gen_task_id() -> TaskId {
33    use std::sync::atomic::{AtomicU64, Ordering};
34    static COUNTER: AtomicU64 = AtomicU64::new(1);
35    COUNTER.fetch_add(1, Ordering::Relaxed)
36}
37
38/// Raw task pointer for wake-up notifications
39/// 用于唤醒通知的原始任务指针
40pub type RawTask = *const ();