Skip to content

Commit 3e93f9a

Browse files
committed
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.
1 parent 20f287f commit 3e93f9a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lightning/src/util/ser.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::prelude::*;
1717
use crate::io::{self, Read, Seek, Write};
1818
use crate::io_extras::{copy, sink};
1919
use core::hash::Hash;
20-
use crate::sync::Mutex;
20+
use crate::sync::{Mutex, RwLock};
2121
use core::cmp;
2222
use core::convert::TryFrom;
2323
use core::ops::Deref;
@@ -1195,6 +1195,18 @@ impl<T: Writeable> Writeable for Mutex<T> {
11951195
}
11961196
}
11971197

1198+
impl<T: Readable> Readable for RwLock<T> {
1199+
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
1200+
let t: T = Readable::read(r)?;
1201+
Ok(RwLock::new(t))
1202+
}
1203+
}
1204+
impl<T: Writeable> Writeable for RwLock<T> {
1205+
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
1206+
self.read().unwrap().write(w)
1207+
}
1208+
}
1209+
11981210
impl<A: Readable, B: Readable> Readable for (A, B) {
11991211
fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
12001212
let a: A = Readable::read(r)?;

0 commit comments

Comments
 (0)