extern crate std;
use crate::core::SyncPointBeh;
pub use std::sync::Mutex;
pub use std::sync::MutexGuard;
impl<T> SyncPointBeh for Mutex<T> {
type LockType<'a>
= MutexGuard<'a, T>
where
T: 'a;
type DerefLockType = T;
#[inline]
fn new_lock(&self) -> Self::LockType<'_> {
match Mutex::lock(self) {
Ok(a) => a,
Err(e) => e.into_inner(),
}
}
#[inline]
fn try_lock(&self) -> Option<Self::LockType<'_>> {
Mutex::try_lock(self).ok()
}
#[inline]
fn unlock<'a>(&'a self, lock_type: Self::LockType<'a>) {
drop(lock_type)
}
}
#[macro_export]
#[doc(hidden)]
macro_rules! __sync_beh {
{
#name
} => { "std" };
{
#new_point<$t: ty : [$t_make:expr]>: $v_point_name:ident
} => {
#[allow(dead_code)]
#[allow(non_upper_case_globals)]
#[allow(non_camel_case_types)]
pub static $v_point_name: $crate::core::SyncPoint<
$crate::beh::std::Mutex<$t>
> = $crate::core::SyncPoint::new(
$crate::beh::std::Mutex::new(
$t_make
)
);
};
{
#new_lock($lock:ident): $v_point_name:ident
} => {
#[allow(unused_mut)]
let mut $lock = $v_point_name.new_lock();
};
{
#drop_lock($lock: ident): $v_point_name:ident
} => {
$crate::core::SyncPoint::unlock(&$v_point_name, $lock);
};
}