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//! - `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//! - FIFO cooperative scheduler is the default when no scheduler feature is
17//!   selected.
18//! - `sched-rr`: Use the [Round-robin preemptive scheduler][2]. It also enables
19//!   the `multitask` and `preempt` features if it is enabled.
20//! - `sched-cfs`: Use the [Completely Fair Scheduler][3]. It also enables the
21//!   the `multitask` and `preempt` features if it is enabled.
22//! - `host-test`: Use host-safe fallbacks for unit tests.
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
59#[cfg(feature = "multitask")]
60mod build_info {
61    include!(concat!(env!("OUT_DIR"), "/build_info.rs"));
62}
63
64cfg_if::cfg_if! {
65    if #[cfg(feature = "multitask")] {
66        #[macro_use]
67        extern crate log;
68        extern crate alloc;
69
70        #[macro_use]
71        mod run_queue;
72        mod task;
73        mod api;
74        #[cfg(feature = "lockdep")]
75        mod lockdep;
76        #[cfg(feature = "tracepoint-hooks")]
77        mod sched_tracepoint;
78        #[cfg(feature = "irq")]
79        mod irq_notify;
80        mod wait_queue;
81
82        #[cfg(feature = "irq")]
83        mod timers;
84
85        #[cfg(feature = "multitask")]
86        pub mod future;
87
88        #[cfg_attr(doc, doc(cfg(feature = "multitask")))]
89        pub use self::api::*;
90        #[cfg(feature = "irq")]
91        pub use self::irq_notify::IrqNotify;
92        pub use self::api::{sleep, sleep_until, yield_now};
93        #[cfg(feature = "tracepoint-hooks")]
94        pub use self::sched_tracepoint::SchedTracepoint;
95    } else {
96        mod api_s;
97        pub use self::api_s::{sleep, sleep_until, yield_now};
98    }
99}