From 3e93f9ad88ca810cb6aea7b6dd7c3fc43a641af8 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sat, 30 Sep 2023 17:35:21 +0000 Subject: [PATCH] Implement `Readable`/`Writeable` for `RwLock` wrappers We now support separate R/W locks in `LockableScore`, which allow us to do routefinding in parallel, however in order to support `WriteableScore` for such users we need to implement `Writeable` for `RwLock` wrappers around `Writeable` types, which we do here. --- lightning/src/util/ser.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index af4de88a1..7971f35fc 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -17,7 +17,7 @@ use crate::prelude::*; use crate::io::{self, Read, Seek, Write}; use crate::io_extras::{copy, sink}; use core::hash::Hash; -use crate::sync::Mutex; +use crate::sync::{Mutex, RwLock}; use core::cmp; use core::convert::TryFrom; use core::ops::Deref; @@ -1195,6 +1195,18 @@ impl Writeable for Mutex { } } +impl Readable for RwLock { + fn read(r: &mut R) -> Result { + let t: T = Readable::read(r)?; + Ok(RwLock::new(t)) + } +} +impl Writeable for RwLock { + fn write(&self, w: &mut W) -> Result<(), io::Error> { + self.read().unwrap().write(w) + } +} + impl Readable for (A, B) { fn read(r: &mut R) -> Result { let a: A = Readable::read(r)?; -- 2.39.5