1#[cfg(all(feature = "sync", not(feature = "async"), feature = "std"))]
2pub(crate) use std::sync::Mutex;
3
4#[cfg(all(feature = "sync", feature = "async", feature = "smol"))]
5pub(crate) use smol::sync::Mutex;
6#[cfg(all(feature = "sync", not(feature = "std")))]
7pub(crate) use spin::Mutex;
8#[cfg(all(feature = "sync", feature = "async", feature = "tokio"))]
9pub(crate) use tokio::sync::Mutex;
10
11#[cfg(feature = "sync")]
12pub(crate) type Shared<T> = alloc::sync::Arc<Mutex<T>>;
13#[cfg(not(feature = "sync"))]
14pub(crate) type Shared<T> = alloc::rc::Rc<core::cell::RefCell<T>>;
15
16pub(crate) fn shared<T>(t: T) -> Shared<T> {
17 match () {
18 #[cfg(feature = "sync")]
19 () => alloc::sync::Arc::new(Mutex::new(t)),
20 #[cfg(not(feature = "sync"))]
21 () => alloc::rc::Rc::new(core::cell::RefCell::new(t)),
22 }
23}
24
25#[macro_export]
26macro_rules! acquire {
27 ($shared: expr) => {
28 match () {
29 #[cfg(all(feature = "sync", feature = "std", feature = "async"))]
30 () => $shared.lock().await,
31 #[cfg(all(feature = "sync", feature = "std", not(feature = "async")))]
32 () => $shared.lock().unwrap(),
33 #[cfg(all(feature = "sync", not(feature = "std")))]
34 () => $shared.lock(),
35 #[cfg(not(feature = "sync"))]
36 () => $shared.borrow_mut(),
37 }
38 };
39}
40
41pub(crate) use acquire;