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//! - `multitask`: Enable multi-task support. If it's enabled, complex task
10//! management and scheduling is used, as well as more task-related APIs.
11//! Otherwise, only a few APIs with naive implementation is available.
12//! - `irq`: Interrupts are enabled. If this feature is enabled, timer-based
13//! APIs can be used, such as [`sleep`], [`sleep_until`], and
14//! [`WaitQueue::wait_timeout`].
15//! - `preempt`: Enable preemptive scheduling.
16//! - `sched-fifo`: Use the [FIFO cooperative scheduler][1]. It also enables the
17//! `multitask` feature if it is enabled. This feature is enabled by default,
18//! and it can be overriden by other scheduler features.
19//! - `sched-rr`: Use the [Round-robin preemptive scheduler][2]. It also enables
20//! the `multitask` and `preempt` features if it is enabled.
21//! - `sched-cfs`: Use the [Completely Fair Scheduler][3]. It also enables the
22//! the `multitask` and `preempt` features if it is enabled.
23//!
24//! [1]: ax_sched::FifoScheduler
25//! [2]: ax_sched::RRScheduler
26//! [3]: ax_sched::CFScheduler
27
28#![cfg_attr(any(not(test), target_os = "none"), no_std)]
29#![cfg_attr(all(test, target_os = "none"), no_main)]
30#![cfg_attr(all(test, target_os = "none"), feature(custom_test_frameworks))]
31#![cfg_attr(doc, feature(doc_cfg))]
32#![cfg_attr(
33 all(test, target_os = "none"),
34 test_runner(crate::bare_metal_test_runner)
35)]
36
37#[cfg(all(test, not(target_os = "none"), feature = "multitask"))]
38mod tests;
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
59cfg_if::cfg_if! {
60 if #[cfg(feature = "multitask")] {
61 #[macro_use]
62 extern crate log;
63 extern crate alloc;
64
65 #[macro_use]
66 mod run_queue;
67 mod task;
68 mod api;
69 #[cfg(feature = "lockdep")]
70 mod lockdep;
71 mod wait_queue;
72
73 #[cfg(feature = "irq")]
74 mod timers;
75
76 #[cfg(feature = "multitask")]
77 pub mod future;
78
79 #[cfg_attr(doc, doc(cfg(feature = "multitask")))]
80 pub use self::api::*;
81 pub use self::api::{sleep, sleep_until, yield_now};
82 } else {
83 mod api_s;
84 pub use self::api_s::{sleep, sleep_until, yield_now};
85 }
86}