From 3b6ded0e6c6849621a82c151ccac0db9ab17f31f Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Tue, 13 Dec 2022 14:58:35 +0100 Subject: [PATCH] f Use return non-Arc'ed Event afterall --- src/event.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/event.rs b/src/event.rs index cdf0c846c..34493bf42 100644 --- a/src/event.rs +++ b/src/event.rs @@ -136,7 +136,7 @@ pub(crate) struct EventQueue where K::Target: KVStorePersister, { - queue: Mutex>>, + queue: Mutex>, notifier: Condvar, persister: K, } @@ -146,7 +146,7 @@ where K::Target: KVStorePersister, { pub(crate) fn new(persister: K) -> Self { - let queue: Mutex>> = Mutex::new(VecDeque::new()); + let queue: Mutex> = Mutex::new(VecDeque::new()); let notifier = Condvar::new(); Self { queue, notifier, persister } } @@ -154,7 +154,7 @@ where pub(crate) fn add_event(&self, event: Event) -> Result<(), Error> { { let mut locked_queue = self.queue.lock().unwrap(); - locked_queue.push_back(Arc::new(event)); + locked_queue.push_back(event); self.persist_queue(&*locked_queue)?; } @@ -162,10 +162,10 @@ where Ok(()) } - pub(crate) fn next_event(&self) -> Arc { + pub(crate) fn next_event(&self) -> Event { let locked_queue = self.notifier.wait_while(self.queue.lock().unwrap(), |queue| queue.is_empty()).unwrap(); - Arc::clone(&locked_queue.front().unwrap()) + locked_queue.front().unwrap().clone() } pub(crate) fn event_handled(&self) -> Result<(), Error> { @@ -178,7 +178,7 @@ where Ok(()) } - fn persist_queue(&self, locked_queue: &VecDeque>) -> Result<(), Error> { + fn persist_queue(&self, locked_queue: &VecDeque) -> Result<(), Error> { self.persister .persist(EVENTS_PERSISTENCE_KEY, &EventQueueSerWrapper(locked_queue)) .map_err(|_| Error::PersistenceFailed)?; @@ -195,13 +195,13 @@ where reader: &mut R, persister: K, ) -> Result { let read_queue: EventQueueDeserWrapper = Readable::read(reader)?; - let queue: Mutex>> = Mutex::new(read_queue.0); + let queue: Mutex> = Mutex::new(read_queue.0); let notifier = Condvar::new(); Ok(Self { queue, notifier, persister }) } } -struct EventQueueDeserWrapper(VecDeque>); +struct EventQueueDeserWrapper(VecDeque); impl Readable for EventQueueDeserWrapper { fn read( @@ -210,13 +210,13 @@ impl Readable for EventQueueDeserWrapper { let len: u16 = Readable::read(reader)?; let mut queue = VecDeque::with_capacity(len as usize); for _ in 0..len { - queue.push_back(Arc::new(Readable::read(reader)?)); + queue.push_back(Readable::read(reader)?); } Ok(Self(queue)) } } -struct EventQueueSerWrapper<'a>(&'a VecDeque>); +struct EventQueueSerWrapper<'a>(&'a VecDeque); impl Writeable for EventQueueSerWrapper<'_> { fn write(&self, writer: &mut W) -> Result<(), lightning::io::Error> { @@ -594,7 +594,7 @@ mod tests { // Check we get the expected event and that it is returned until we mark it handled. for _ in 0..5 { - assert_eq!(*event_queue.next_event(), expected_event); + assert_eq!(event_queue.next_event(), expected_event); assert_eq!(false, test_persister.get_and_clear_pending_persist()); }