extern crate tokio;
use crate::core::SyncPointBeh;
use crate::core::r#async::cfg_async_or_sync;
pub use tokio::sync::Mutex;
pub use tokio::sync::MutexGuard;
cfg_async_or_sync! {
impl[T: Send] SyncPointBeh for Mutex<T> {
#only_async {
#[inline]
fn new_lock(&self) -> impl core::future::Future<Output = Self::LockType<'_>> + Send {
Mutex::lock(self)
}
}
#only_sync {
#[inline]
fn new_lock(&self) -> Self::LockType<'_> {
unimplemented!();
}
}
type LockType<'a> = MutexGuard<'a, T> where T: 'a;
type DerefLockType = T;
#[inline]
fn try_lock(&self) -> Option<Self::LockType<'_>> {
Mutex::try_lock(self).ok()
}
#[inline]
fn unlock(&self, lock_type: Self::LockType<'_>) {
drop(lock_type)
}
}
}
#[macro_export]
#[doc(hidden)]
#[cfg(not(any(feature = "pl", feature = "std")))]
macro_rules! __sync_beh {
{
#name
} => { "async(tokio+parking_lot)" };
{
#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::r#async::Mutex<$t>
> = $crate::core::SyncPoint::new($crate::beh::r#async::Mutex::const_new(
$t_make
));
};
{
#new_lock($lock:ident): $v_point_name:ident
} => {
#[allow(unused_mut)]
let mut $lock = $v_point_name.new_lock().await;
};
{
#drop_lock($lock: ident): $v_point_name:ident
} => {
$crate::core::SyncPoint::unlock(&$v_point_name, $lock);
};
}