50ef40e295f50d0a0d9095a0f3dfe4c73916a340
[rust-lightning] / lightning / src / sync / mod.rs
1 #[allow(dead_code)] // Depending on the compilation flags some variants are never used
2 #[derive(Debug, PartialEq, Eq)]
3 pub(crate) enum LockHeldState {
4         HeldByThread,
5         NotHeldByThread,
6         #[cfg(any(feature = "_bench_unstable", not(test)))]
7         Unsupported,
8 }
9
10 pub(crate) trait LockTestExt {
11         fn held_by_thread(&self) -> LockHeldState;
12 }
13
14 #[cfg(all(feature = "std", not(feature = "_bench_unstable"), test))]
15 mod debug_sync;
16 #[cfg(all(feature = "std", not(feature = "_bench_unstable"), test))]
17 pub use debug_sync::*;
18 #[cfg(all(feature = "std", not(feature = "_bench_unstable"), test))]
19 // Note that to make debug_sync's regex work this must not contain `debug_string` in the module name
20 mod test_lockorder_checks;
21
22 #[cfg(all(feature = "std", any(feature = "_bench_unstable", not(test))))]
23 pub(crate) mod fairrwlock;
24 #[cfg(all(feature = "std", any(feature = "_bench_unstable", not(test))))]
25 pub use {std::sync::{Arc, Mutex, Condvar, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}, fairrwlock::FairRwLock};
26
27 #[cfg(all(feature = "std", any(feature = "_bench_unstable", not(test))))]
28 mod ext_impl {
29         use super::*;
30         impl<T> LockTestExt for Mutex<T> {
31                 #[inline]
32                 fn held_by_thread(&self) -> LockHeldState { LockHeldState::Unsupported }
33         }
34         impl<T> LockTestExt for RwLock<T> {
35                 #[inline]
36                 fn held_by_thread(&self) -> LockHeldState { LockHeldState::Unsupported }
37         }
38 }
39
40 #[cfg(not(feature = "std"))]
41 mod nostd_sync;
42 #[cfg(not(feature = "std"))]
43 pub use nostd_sync::*;