From: Viktor Tigerström <11711198+ViktorTigerstrom@users.noreply.github.com> Date: Thu, 8 Dec 2022 21:40:54 +0000 (+0100) Subject: Add `try_write` function to `FairRwLock` X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=6c96edee4cebbcfc18149240d5d9a77156ffd677;p=rust-lightning Add `try_write` function to `FairRwLock` --- diff --git a/lightning/src/util/fairrwlock.rs b/lightning/src/util/fairrwlock.rs index c9b3866be..5715a8cf6 100644 --- a/lightning/src/util/fairrwlock.rs +++ b/lightning/src/util/fairrwlock.rs @@ -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 FairRwLock { // codebase. self.lock.read() } + + pub fn try_write(&self) -> TryLockResult> { + self.lock.try_write() + } }