From 53afb8d22d5e2b799114891cf4888cae7a47081c Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Mon, 21 Nov 2016 14:48:25 +0100 Subject: [PATCH] queue: park directly instead of through condvar --- ethcore/src/verification/queue/mod.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/ethcore/src/verification/queue/mod.rs b/ethcore/src/verification/queue/mod.rs index 0b39dd769..686a1d093 100644 --- a/ethcore/src/verification/queue/mod.rs +++ b/ethcore/src/verification/queue/mod.rs @@ -66,20 +66,20 @@ impl Default for Config { struct VerifierHandle { deleting: Arc, - sleep: Arc<(Mutex, Condvar)>, + sleep: Arc, thread: JoinHandle<()>, } impl VerifierHandle { // signal to the verifier thread that it should sleep. fn sleep(&self) { - *self.sleep.0.lock() = true; + self.sleep.store(true, AtomicOrdering::SeqCst); } // signal to the verifier thread that it should wake up. fn wake_up(&self) { - *self.sleep.0.lock() = false; - self.sleep.1.notify_all(); + self.sleep.store(false, AtomicOrdering::SeqCst); + self.thread.thread().unpark(); } // signal to the verifier thread that it should conclude its @@ -91,7 +91,7 @@ impl VerifierHandle { // join the verifier thread. fn join(self) { - self.thread.join().unwrap(); + self.thread.join().expect("Verifier thread panicked"); } } @@ -241,9 +241,9 @@ impl VerificationQueue { // enable only the first few verifiers. let sleep = if i < default_amount { - Arc::new((Mutex::new(false), Condvar::new())) + Arc::new(AtomicBool::new(false)) } else { - Arc::new((Mutex::new(true), Condvar::new())) + Arc::new(AtomicBool::new(true)) }; verifiers.push(VerifierHandle { @@ -283,14 +283,13 @@ impl VerificationQueue { ready: Arc, deleting: Arc, empty: Arc, - sleep: Arc<(Mutex, Condvar)>, + sleep: Arc, ) { while !deleting.load(AtomicOrdering::Acquire) { { - let mut should_sleep = sleep.0.lock(); - while *should_sleep { + while sleep.load(AtomicOrdering::SeqCst) { trace!(target: "verification", "Verifier sleeping"); - sleep.1.wait(&mut should_sleep); + ::std::thread::park(); trace!(target: "verification", "Verifier waking up"); if deleting.load(AtomicOrdering::Acquire) {