]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Implement `Readable`/`Writeable` for `RwLock` wrappers
authorMatt Corallo <git@bluematt.me>
Sat, 30 Sep 2023 17:35:21 +0000 (17:35 +0000)
committerMatt Corallo <git@bluematt.me>
Sat, 30 Sep 2023 17:41:43 +0000 (17:41 +0000)
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

index af4de88a1a7dda59145b1ea25fa7b7e434519f76..7971f35fc97ce6ef0c8ec9c5dba4348cfdce697b 100644 (file)
@@ -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<T: Writeable> Writeable for Mutex<T> {
        }
 }
 
+impl<T: Readable> Readable for RwLock<T> {
+       fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+               let t: T = Readable::read(r)?;
+               Ok(RwLock::new(t))
+       }
+}
+impl<T: Writeable> Writeable for RwLock<T> {
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+               self.read().unwrap().write(w)
+       }
+}
+
 impl<A: Readable, B: Readable> Readable for (A, B) {
        fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
                let a: A = Readable::read(r)?;