Merge pull request #1507 from ViktorTigerstrom/2022-05-store-channels-per-peer
[rust-lightning] / lightning / src / util / fairrwlock.rs
index c9b3866bec5c837e948b3a7f469515ed4b9b79f4..5715a8cf646cd67e29b7aa5c21c8722d89a45964 100644 (file)
@@ -1,4 +1,4 @@
-use std::sync::{LockResult, RwLock, RwLockReadGuard, RwLockWriteGuard};
+use std::sync::{LockResult, RwLock, RwLockReadGuard, RwLockWriteGuard, TryLockResult};
 use std::sync::atomic::{AtomicUsize, Ordering};
 
 /// Rust libstd's RwLock does not provide any fairness guarantees (and, in fact, when used on
@@ -43,4 +43,8 @@ impl<T> FairRwLock<T> {
                // codebase.
                self.lock.read()
        }
+
+       pub fn try_write(&self) -> TryLockResult<RwLockWriteGuard<'_, T>> {
+               self.lock.try_write()
+       }
 }