Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
verification_queue: remove redundant mutexes
Browse files Browse the repository at this point in the history
  • Loading branch information
ordian committed Aug 21, 2018
1 parent 9b6642f commit 3c3c6f4
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions ethcore/src/verification/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ struct Verification<K: Kind> {
verifying: Mutex<VecDeque<Verifying<K>>>,
verified: Mutex<VecDeque<K::Verified>>,
bad: Mutex<HashSet<H256>>,
more_to_verify: Mutex<()>,
empty: Mutex<()>,
sizes: Sizes,
check_seal: bool,
}
Expand All @@ -216,8 +214,6 @@ impl<K: Kind> VerificationQueue<K> {
verifying: Mutex::new(VecDeque::new()),
verified: Mutex::new(VecDeque::new()),
bad: Mutex::new(HashSet::new()),
more_to_verify: Mutex::new(()),
empty: Mutex::new(()),
sizes: Sizes {
unverified: AtomicUsize::new(0),
verifying: AtomicUsize::new(0),
Expand Down Expand Up @@ -319,19 +315,19 @@ impl<K: Kind> VerificationQueue<K> {

// wait for work if empty.
{
let mut more_to_verify = verification.more_to_verify.lock();
let mut unverified = verification.unverified.lock();

if verification.unverified.lock().is_empty() && verification.verifying.lock().is_empty() {
if unverified.is_empty() && verification.verifying.lock().is_empty() {
empty.notify_all();
}

while verification.unverified.lock().is_empty() {
while unverified.is_empty() {
if let State::Exit = *state.0.lock() {
debug!(target: "verification", "verifier {} exiting", id);
return;
}

wait.wait(&mut more_to_verify);
wait.wait(&mut unverified);
}

if let State::Exit = *state.0.lock() {
Expand Down Expand Up @@ -450,9 +446,9 @@ impl<K: Kind> VerificationQueue<K> {

/// Wait for unverified queue to be empty
pub fn flush(&self) {
let mut lock = self.verification.empty.lock();
while !self.verification.unverified.lock().is_empty() || !self.verification.verifying.lock().is_empty() {
self.empty.wait(&mut lock);
let mut unverified = self.verification.unverified.lock();
while !unverified.is_empty() || !self.verification.verifying.lock().is_empty() {
self.empty.wait(&mut unverified);
}
}

Expand Down Expand Up @@ -712,7 +708,7 @@ impl<K: Kind> Drop for VerificationQueue<K> {
// acquire this lock to force threads to reach the waiting point
// if they're in-between the exit check and the more_to_verify wait.
{
let _more = self.verification.more_to_verify.lock();
let _unverified = self.verification.unverified.lock();
self.more_to_verify.notify_all();
}

Expand Down

0 comments on commit 3c3c6f4

Please sign in to comment.