pub(crate) mod r#async;
use r#async::cfg_async_or_sync;
use core::ops::Deref;
use core::ops::DerefMut;
use crate::cfg::cfg_async;
use crate::cfg::cfg_not_async;
cfg_async_or_sync! {
pub trait SyncPointBeh {
#only_async {
fn new_lock(&self) -> impl core::future::Future<Output = Self::LockType<'_>> + Send;
}
#only_sync {
fn new_lock(&self) -> Self::LockType<'_>;
}
fn try_lock(&self) -> Option<Self::LockType<'_>>;
fn unlock(&self, lock_type: Self::LockType<'_>);
type LockType<'a>: Deref<Target = Self::DerefLockType> + DerefMut where Self: 'a;
type DerefLockType;
#[cfg_attr(docsrs, doc(cfg( feature = "pl" )))]
#[cfg( all(
feature = "pl",
not(feature = "std"),
not(feature = "async")
) )]
fn is_lock(&self) -> bool;
}
}
#[repr(transparent)]
pub struct SyncPoint<T> {
mutex_builder: T,
}
impl<T> SyncPoint<T>
where
T: SyncPointBeh,
{
#[inline]
pub const fn new(mutex_builder: T) -> Self {
Self { mutex_builder }
}
cfg_not_async! {
#[inline]
pub fn new_lock(&self) -> T::LockType<'_> {
T::new_lock(&self.mutex_builder)
}
}
cfg_async! {
#[inline]
pub async fn new_lock(&self) -> T::LockType<'_> {
T::new_lock(&self.mutex_builder).await
}
}
#[inline]
pub fn try_lock(&self) -> Option<T::LockType<'_>> {
T::try_lock(&self.mutex_builder)
}
#[inline]
pub fn unlock(&self, lock: T::LockType<'_>) {
T::unlock(&self.mutex_builder, lock)
}
#[inline]
#[cfg_attr(docsrs, doc(cfg(feature = "pl")))]
#[cfg(all(feature = "pl", not(feature = "std"), not(feature = "async")))]
pub fn is_lock(&self) -> bool {
T::is_lock(&self.mutex_builder)
}
}