1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
pub use core::sync::*;
pub use alloc::sync::*;

mod mutex_shim {
  #[cfg(feature = "std")]
  pub use std::sync::*;
  #[cfg(not(feature = "std"))]
  pub use spin::*;

  #[derive(Default, Debug)]
  pub struct ShimMutex<T>(Mutex<T>);
  impl<T> ShimMutex<T> {
    pub const fn new(value: T) -> Self {
      Self(Mutex::new(value))
    }

    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};

#[cfg(feature = "std")]
pub use std::sync::OnceLock;
#[cfg(not(feature = "std"))]
mod oncelock_shim {
  use spin::Once;

  pub struct OnceLock<T>(Once<T>);
  impl<T> OnceLock<T> {
    pub const fn new() -> OnceLock<T> {
      OnceLock(Once::new())
    }
    pub fn get(&self) -> Option<&T> {
      self.0.poll()
    }
    pub fn get_mut(&mut self) -> Option<&mut T> {
      self.0.get_mut()
    }

    pub fn get_or_init<F: FnOnce() -> T>(&self, f: F) -> &T {
      self.0.call_once(f)
    }
  }
}
#[cfg(not(feature = "std"))]
pub use oncelock_shim::*;