Skip to main content

ax_sync/
lib.rs

1//! [ArceOS](https://github.com/arceos-org/arceos) synchronization primitives.
2//!
3//! Currently supported primitives:
4//!
5//! - [`Mutex`]: A mutual exclusion primitive.
6//! - mod [`spin`]: spinlocks imported from the [`ax-kspin`] crate.
7//!
8//! # Cargo Features
9//!
10//! - `multitask`: For use in the multi-threaded environments. If the feature is
11//!   not enabled, [`Mutex`] will be an alias of [`spin::SpinNoIrq`]. This
12//!   feature is enabled by default.
13
14#![cfg_attr(any(not(test), target_os = "none"), no_std)]
15#![cfg_attr(all(test, target_os = "none"), no_main)]
16#![cfg_attr(all(test, target_os = "none"), feature(custom_test_frameworks))]
17#![cfg_attr(doc, feature(doc_cfg))]
18#![cfg_attr(
19    all(test, target_os = "none"),
20    test_runner(crate::bare_metal_test_runner)
21)]
22
23pub use ax_kspin as spin;
24
25#[cfg(all(test, target_os = "none"))]
26fn bare_metal_test_runner(_tests: &[&dyn Fn()]) {}
27
28#[cfg(all(test, target_os = "none"))]
29#[unsafe(no_mangle)]
30extern "C" fn _start() -> ! {
31    loop {
32        core::hint::spin_loop();
33    }
34}
35
36#[cfg(all(test, target_os = "none"))]
37#[panic_handler]
38fn panic(_info: &core::panic::PanicInfo<'_>) -> ! {
39    loop {
40        core::hint::spin_loop();
41    }
42}
43
44#[cfg(feature = "multitask")]
45#[cfg(feature = "lockdep")]
46mod lockdep;
47
48#[cfg(feature = "multitask")]
49mod mutex;
50
51#[cfg(not(feature = "multitask"))]
52#[cfg_attr(doc, doc(cfg(not(feature = "multitask"))))]
53pub use ax_kspin::{SpinNoIrq as Mutex, SpinNoIrqGuard as MutexGuard};
54
55#[cfg(feature = "multitask")]
56#[cfg_attr(doc, doc(cfg(feature = "multitask")))]
57pub use self::mutex::{Mutex, MutexGuard, RawMutex};