]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add `try_write` function to `FairRwLock`
authorViktor Tigerström <11711198+ViktorTigerstrom@users.noreply.github.com>
Thu, 8 Dec 2022 21:40:54 +0000 (22:40 +0100)
committerViktor Tigerström <11711198+ViktorTigerstrom@users.noreply.github.com>
Fri, 6 Jan 2023 23:52:30 +0000 (00:52 +0100)
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()
+       }
 }