#[allow(dead_code)] #[derive(Debug, PartialEq, Eq)]
pub(crate) enum LockHeldState {
HeldByThread,
NotHeldByThread,
#[cfg(any(ldk_bench, not(test)))]
Unsupported,
}
pub(crate) trait LockTestExt<'a> {
fn held_by_thread(&self) -> LockHeldState;
type ExclLock;
fn unsafe_well_ordered_double_lock_self(&'a self) -> Self::ExclLock;
}
#[cfg(all(not(ldk_bench), test))]
mod debug_sync;
#[cfg(all(not(ldk_bench), test))]
pub use debug_sync::*;
#[cfg(all(not(ldk_bench), test))]
mod test_lockorder_checks;
#[cfg(all(feature = "std", any(ldk_bench, not(test))))]
pub(crate) mod fairrwlock;
#[cfg(all(feature = "std", any(ldk_bench, not(test))))]
pub use {
fairrwlock::FairRwLock,
std::sync::{Arc, Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard},
};
#[cfg(all(feature = "std", any(ldk_bench, not(test))))]
mod ext_impl {
use super::*;
impl<'a, T: 'a> LockTestExt<'a> for Mutex<T> {
#[inline]
fn held_by_thread(&self) -> LockHeldState {
LockHeldState::Unsupported
}
type ExclLock = MutexGuard<'a, T>;
#[inline]
fn unsafe_well_ordered_double_lock_self(&'a self) -> MutexGuard<'a, T> {
self.lock().unwrap()
}
}
impl<'a, T: 'a> LockTestExt<'a> for RwLock<T> {
#[inline]
fn held_by_thread(&self) -> LockHeldState {
LockHeldState::Unsupported
}
type ExclLock = RwLockWriteGuard<'a, T>;
#[inline]
fn unsafe_well_ordered_double_lock_self(&'a self) -> RwLockWriteGuard<'a, T> {
self.write().unwrap()
}
}
}
#[cfg(all(not(feature = "std"), any(ldk_bench, not(test))))]
mod nostd_sync;
#[cfg(all(not(feature = "std"), any(ldk_bench, not(test))))]
pub use nostd_sync::*;