1 pub(crate) use loom::*; 2 3 pub(crate) mod sync { 4 5 pub(crate) use loom::sync::{MutexGuard, RwLockReadGuard, RwLockWriteGuard}; 6 7 #[derive(Debug)] 8 pub(crate) struct Mutex<T>(loom::sync::Mutex<T>); 9 10 #[allow(dead_code)] 11 impl<T> Mutex<T> { 12 #[inline] new(t: T) -> Mutex<T>13 pub(crate) fn new(t: T) -> Mutex<T> { 14 Mutex(loom::sync::Mutex::new(t)) 15 } 16 17 #[inline] 18 #[track_caller] lock(&self) -> MutexGuard<'_, T>19 pub(crate) fn lock(&self) -> MutexGuard<'_, T> { 20 self.0.lock().unwrap() 21 } 22 23 #[inline] try_lock(&self) -> Option<MutexGuard<'_, T>>24 pub(crate) fn try_lock(&self) -> Option<MutexGuard<'_, T>> { 25 self.0.try_lock().ok() 26 } 27 28 #[inline] get_mut(&mut self) -> &mut T29 pub(crate) fn get_mut(&mut self) -> &mut T { 30 self.0.get_mut().unwrap() 31 } 32 } 33 34 #[derive(Debug)] 35 pub(crate) struct RwLock<T>(loom::sync::RwLock<T>); 36 37 #[allow(dead_code)] 38 impl<T> RwLock<T> { 39 #[inline] new(t: T) -> Self40 pub(crate) fn new(t: T) -> Self { 41 Self(loom::sync::RwLock::new(t)) 42 } 43 44 #[inline] read(&self) -> RwLockReadGuard<'_, T>45 pub(crate) fn read(&self) -> RwLockReadGuard<'_, T> { 46 self.0.read().unwrap() 47 } 48 49 #[inline] try_read(&self) -> Option<RwLockReadGuard<'_, T>>50 pub(crate) fn try_read(&self) -> Option<RwLockReadGuard<'_, T>> { 51 self.0.try_read().ok() 52 } 53 54 #[inline] write(&self) -> RwLockWriteGuard<'_, T>55 pub(crate) fn write(&self) -> RwLockWriteGuard<'_, T> { 56 self.0.write().unwrap() 57 } 58 59 #[inline] try_write(&self) -> Option<RwLockWriteGuard<'_, T>>60 pub(crate) fn try_write(&self) -> Option<RwLockWriteGuard<'_, T>> { 61 self.0.try_write().ok() 62 } 63 } 64 65 pub(crate) use loom::sync::*; 66 67 pub(crate) mod atomic { 68 pub(crate) use loom::sync::atomic::*; 69 70 // TODO: implement a loom version 71 pub(crate) type StaticAtomicU64 = std::sync::atomic::AtomicU64; 72 } 73 } 74 75 pub(crate) mod rand { seed() -> u6476 pub(crate) fn seed() -> u64 { 77 1 78 } 79 } 80 81 pub(crate) mod sys { num_cpus() -> usize82 pub(crate) fn num_cpus() -> usize { 83 2 84 } 85 } 86 87 pub(crate) mod thread { 88 pub use loom::lazy_static::AccessError; 89 pub use loom::thread::*; 90 } 91