Skip to main content

ax_task/
lib.rs

1//! [ArceOS](https://github.com/arceos-org/arceos) task management module.
2//!
3//! This module provides primitives for task management, including task
4//! creation, scheduling, sleeping, termination, etc. The scheduler algorithm
5//! is configurable by cargo features.
6//!
7//! # Cargo Features
8//!
9//! Multi-task scheduling and interrupt handling are mandatory runtime
10//! capabilities. Timer-based APIs such as [`sleep`], [`sleep_until`], and
11//! [`WaitQueue::wait_timeout`] are always available.
12//! - `preempt`: Enable preemptive scheduling.
13//! - FIFO cooperative scheduler is the default when no scheduler feature is
14//!   selected.
15//! - `sched-rr`: Use the [Round-robin preemptive scheduler][2]. It also enables
16//!   the `preempt` feature.
17//! - `sched-cfs`: Use the [Completely Fair Scheduler][3]. It also enables the
18//!   `preempt` feature.
19//! - `host-test`: Use host-safe fallbacks for unit tests.
20//!
21//! [1]: ax_sched::FifoScheduler
22//! [2]: ax_sched::RRScheduler
23//! [3]: ax_sched::CFScheduler
24
25#![cfg_attr(any(not(test), target_os = "none"), no_std)]
26#![cfg_attr(all(test, target_os = "none"), no_main)]
27#![cfg_attr(all(test, target_os = "none"), feature(custom_test_frameworks))]
28#![cfg_attr(doc, feature(doc_cfg))]
29#![cfg_attr(
30    all(test, target_os = "none"),
31    test_runner(crate::bare_metal_test_runner)
32)]
33
34#[cfg(all(feature = "host-test", not(target_os = "none")))]
35extern crate std;
36
37/// Native ArceOS synchronization primitives.
38pub mod sync;
39
40#[cfg(all(test, target_os = "none"))]
41fn bare_metal_test_runner(_tests: &[&dyn Fn()]) {}
42
43#[cfg(all(test, target_os = "none"))]
44#[unsafe(no_mangle)]
45extern "C" fn _start() -> ! {
46    loop {
47        core::hint::spin_loop();
48    }
49}
50
51#[cfg(all(test, target_os = "none"))]
52#[panic_handler]
53fn panic(_info: &core::panic::PanicInfo<'_>) -> ! {
54    loop {
55        core::hint::spin_loop();
56    }
57}
58
59mod build_info {
60    include!(concat!(env!("OUT_DIR"), "/build_info.rs"));
61}
62
63#[macro_use]
64extern crate log;
65extern crate alloc;
66
67#[macro_use]
68mod run_queue;
69mod api;
70mod interrupt;
71mod irq_notify;
72#[cfg(feature = "lockdep")]
73mod lockdep;
74#[doc(hidden)]
75pub mod runtime_preempt;
76#[cfg(feature = "tracepoint-hooks")]
77mod sched_tracepoint;
78mod task;
79mod timers;
80mod wait_queue;
81
82pub mod future;
83
84#[cfg(all(feature = "smp", feature = "ipi"))]
85pub use self::run_queue::handle_ipi_reschedule;
86#[cfg(feature = "tracepoint-hooks")]
87pub use self::sched_tracepoint::SchedTracepoint;
88pub use self::{
89    api::{sleep, sleep_until, yield_now, *},
90    irq_notify::IrqNotify,
91};