1use crate::{KMutex, RawMutex};
6
7pub type SingletonMutex<Class, M = RawMutex> = KMutex<Class, M>;
9
10#[macro_export]
27macro_rules! declare_singleton_mutex {
28 ($($args:tt)*) => {
29 $crate::declare_singleton_lock!($($args)*);
30 };
31}
32
33#[macro_export]
35#[cfg(feature = "kernel")]
36macro_rules! declare_singleton_critical_mutex {
37 ($(#[$meta:meta])* $vis:vis $name:ident) => {
38 $crate::declare_singleton_lock!($(#[$meta])* $vis $name, $crate::RawCriticalMutex);
39 };
40}
41
42#[macro_export]
44#[cfg(feature = "kernel")]
45macro_rules! declare_singleton_spinlock {
46 ($(#[$meta:meta])* $vis:vis $name:ident) => {
47 $crate::declare_singleton_lock!($(#[$meta])* $vis $name, $crate::RawSpinlock);
48 };
49}
50
51#[macro_export]
53#[cfg(feature = "kernel")]
54macro_rules! declare_singleton_monitored_spinlock {
55 ($(#[$meta:meta])* $vis:vis $name:ident) => {
56 $crate::declare_singleton_lock!($(#[$meta])* $vis $name, $crate::RawMonitoredSpinlock);
57 };
58}
59
60#[cfg(not(feature = "kernel"))]
61#[cfg(test)]
62mod tests {
63 declare_singleton_mutex!(TestSingleton);
64
65 #[test]
66 fn test_singleton_mutex() {
67 let lock1 = TestSingleton::Get();
68 let lock2 = TestSingleton::get();
69 assert!(core::ptr::eq(lock1, lock2));
70
71 {
72 lock!(let _guard = TestSingleton::Get().lock());
73 }
74
75 {
76 lock!(TestSingleton::lock());
77 }
78 }
79}