From 730d60e5e4b9a0a8105f7b610cd462dc77c501d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Drwi=C4=99ga?= Date: Thu, 7 Apr 2016 00:20:03 +0200 Subject: [PATCH] Avoid signalling readiness when app is about to be closed --- ethcore/src/block_queue.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ethcore/src/block_queue.rs b/ethcore/src/block_queue.rs index 4a52d6a6b..d9f629f11 100644 --- a/ethcore/src/block_queue.rs +++ b/ethcore/src/block_queue.rs @@ -116,6 +116,7 @@ struct VerifyingBlock { } struct QueueSignal { + deleting: Arc, signalled: AtomicBool, message_channel: IoChannel, } @@ -123,10 +124,16 @@ struct QueueSignal { impl QueueSignal { #[cfg_attr(feature="dev", allow(bool_comparison))] fn set(&self) { + // Do not signal when we are about to close + if self.deleting.load(AtomicOrdering::Relaxed) { + return; + } + if self.signalled.compare_and_swap(false, true, AtomicOrdering::Relaxed) == false { self.message_channel.send(UserMessage(SyncMessage::BlockVerified)).expect("Error sending BlockVerified message"); } } + fn reset(&self) { self.signalled.store(false, AtomicOrdering::Relaxed); } @@ -150,8 +157,12 @@ impl BlockQueue { bad: Mutex::new(HashSet::new()), }); let more_to_verify = Arc::new(Condvar::new()); - let ready_signal = Arc::new(QueueSignal { signalled: AtomicBool::new(false), message_channel: message_channel }); let deleting = Arc::new(AtomicBool::new(false)); + let ready_signal = Arc::new(QueueSignal { + deleting: deleting.clone(), + signalled: AtomicBool::new(false), + message_channel: message_channel + }); let empty = Arc::new(Condvar::new()); let panic_handler = PanicHandler::new_in_arc();