axstd/thread/
mod.rs

1//! Native threads.
2
3#[cfg(feature = "multitask")]
4mod multi;
5#[cfg(feature = "multitask")]
6pub use multi::*;
7
8use arceos_api::task as api;
9
10/// Current thread gives up the CPU time voluntarily, and switches to another
11/// ready thread.
12///
13/// For single-threaded configuration (`multitask` feature is disabled), we just
14/// relax the CPU and wait for incoming interrupts.
15pub fn yield_now() {
16    api::ax_yield_now();
17}
18
19/// Exits the current thread.
20///
21/// For single-threaded configuration (`multitask` feature is disabled),
22/// it directly terminates the main thread and shutdown.
23pub fn exit(exit_code: i32) -> ! {
24    api::ax_exit(exit_code);
25}
26
27/// Current thread is going to sleep for the given duration.
28///
29/// If one of `multitask` or `irq` features is not enabled, it uses busy-wait
30/// instead.
31pub fn sleep(dur: core::time::Duration) {
32    sleep_until(arceos_api::time::ax_wall_time() + dur);
33}
34
35/// Current thread is going to sleep, it will be woken up at the given deadline.
36///
37/// If one of `multitask` or `irq` features is not enabled, it uses busy-wait
38/// instead.
39pub fn sleep_until(deadline: arceos_api::time::AxTimeValue) {
40    api::ax_sleep_until(deadline);
41}