kernel_api/sync/
mod.rs

1//! Provides kernel synchronisation primitives
2//!
3//! These are currently based on spinlocks but this may be changed in future
4
5#![stable(feature = "kernel_core_api", since = "1.0.0")]
6
7use core::ops::{Deref, DerefMut};
8#[cfg(not(feature = "use_std"))]
9#[stable(feature = "kernel_core_api", since = "1.0.0")]
10pub use mutex::{Spinlock, SpinlockGuard, SpinlockGuardExt};
11#[cfg(feature = "use_std")]
12#[stable(feature = "kernel_core_api", since = "1.0.0")]
13pub use parking_lot::{Mutex as Spinlock, MutexGuard as SpinlockGuard};
14
15#[cfg(not(feature = "use_std"))]
16#[unstable(feature = "kernel_sync_once", issue = "none")]
17pub use once::{LazyLock, Once, OnceLock, BootstrapOnceLock};
18#[cfg(feature = "use_std")]
19#[unstable(feature = "kernel_sync_once", issue = "none")]
20pub use std::sync::{LazyLock, Once, OnceLock};
21
22#[cfg(not(feature = "use_std"))]
23#[stable(feature = "kernel_core_api", since = "1.0.0")]
24pub use rwlock::{RwSpinlock, RwReadGuard, RwUpgradableReadGuard, RwWriteGuard};
25#[cfg(feature = "use_std")]
26#[stable(feature = "kernel_core_api", since = "1.0.0")]
27pub use parking_lot::{RwLock as RwSpinlock, RwLockReadGuard as RwReadGuard, RwLockUpgradableReadGuard as RwUpgradableReadGuard, RwLockWriteGuard as RwWriteGuard};
28
29#[cfg(not(feature = "use_std"))]
30#[unstable(feature = "kernel_irq_cell", issue = "none")]
31pub use irq_cell::{IrqCell, IrqGuard};
32
33#[cfg(not(feature = "use_std"))]
34mod mutex;
35
36#[cfg(not(feature = "use_std"))]
37pub(crate) mod rwlock;
38
39#[cfg(not(feature = "use_std"))]
40mod once;
41
42#[cfg(not(feature = "use_std"))]
43mod irq_cell;
44
45#[stable(feature = "kernel_core_api", since = "1.0.0")]
46pub struct Syncify<T>(T);
47
48impl<T> Syncify<T> {
49	#[stable(feature = "kernel_core_api", since = "1.0.0")]
50	pub unsafe fn new(t: T) -> Self { Self(t) }
51}
52
53#[stable(feature = "kernel_core_api", since = "1.0.0")]
54impl<T> Deref for Syncify<T> {
55	type Target = T;
56
57	fn deref(&self) -> &Self::Target {
58		&self.0
59	}
60}
61
62#[stable(feature = "kernel_core_api", since = "1.0.0")]
63impl<T> DerefMut for Syncify<T> {
64	fn deref_mut(&mut self) -> &mut Self::Target {
65		&mut self.0
66	}
67}
68
69#[stable(feature = "kernel_core_api", since = "1.0.0")]
70unsafe impl<T> Sync for Syncify<T> {}
71#[stable(feature = "kernel_core_api", since = "1.0.0")]
72unsafe impl<T> Send for Syncify<T> {}