2025-09-15 21:21:30 -04:00
|
|
|
pub use core::sync::atomic;
|
|
|
|
|
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
|
|
|
|
pub use extern_alloc::sync::{Arc, Weak};
|
2025-09-15 21:59:58 -04:00
|
|
|
#[cfg(feature = "std")]
|
|
|
|
|
pub use std::sync::{Arc, Weak};
|
2023-06-28 21:16:33 -04:00
|
|
|
|
|
|
|
|
mod mutex_shim {
|
|
|
|
|
#[cfg(not(feature = "std"))]
|
2025-09-15 21:21:30 -04:00
|
|
|
pub use spin::{Mutex, MutexGuard};
|
|
|
|
|
#[cfg(feature = "std")]
|
|
|
|
|
pub use std::sync::{Mutex, MutexGuard};
|
2023-06-28 21:16:33 -04:00
|
|
|
|
2025-09-15 21:21:30 -04:00
|
|
|
/// A shimmed `Mutex` with an API mutual to `spin` and `std`.
|
2023-06-28 21:16:33 -04:00
|
|
|
#[derive(Default, Debug)]
|
|
|
|
|
pub struct ShimMutex<T>(Mutex<T>);
|
|
|
|
|
impl<T> ShimMutex<T> {
|
2025-09-15 21:21:30 -04:00
|
|
|
/// Construct a new `Mutex`.
|
2023-06-28 21:16:33 -04:00
|
|
|
pub const fn new(value: T) -> Self {
|
|
|
|
|
Self(Mutex::new(value))
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-15 21:21:30 -04:00
|
|
|
/// Acquire a lock on the contents of the `Mutex`.
|
|
|
|
|
///
|
|
|
|
|
/// On no-`std` environments, this may spin until the lock is acquired. On `std` environments,
|
|
|
|
|
/// this may panic if the `Mutex` was poisoned.
|
2023-06-28 21:16:33 -04:00
|
|
|
pub fn lock(&self) -> MutexGuard<'_, T> {
|
|
|
|
|
#[cfg(feature = "std")]
|
|
|
|
|
let res = self.0.lock().unwrap();
|
|
|
|
|
#[cfg(not(feature = "std"))]
|
|
|
|
|
let res = self.0.lock();
|
|
|
|
|
res
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pub use mutex_shim::{ShimMutex as Mutex, MutexGuard};
|
|
|
|
|
|
2025-08-19 18:10:33 -04:00
|
|
|
#[rustversion::before(1.80)]
|
2025-11-04 19:28:26 -05:00
|
|
|
pub use spin::Lazy as LazyLock;
|
|
|
|
|
|
|
|
|
|
#[rustversion::since(1.80)]
|
2025-09-15 21:21:30 -04:00
|
|
|
#[cfg(not(feature = "std"))]
|
2025-08-19 18:10:33 -04:00
|
|
|
pub use spin::Lazy as LazyLock;
|
|
|
|
|
#[rustversion::since(1.80)]
|
2025-08-19 17:40:19 -04:00
|
|
|
#[cfg(feature = "std")]
|
2025-08-19 18:10:33 -04:00
|
|
|
pub use std::sync::LazyLock;
|