Skip to content
Snippets Groups Projects
Commit 986246a1 authored by Nikolay Volf's avatar Nikolay Volf Committed by GitHub
Browse files

Replace Condvars with blocking channel (#5815)


* remove condvars

* return false on lost sender

* fix

* Update primitives/io/src/batch_verifier.rs

Co-authored-by: default avatarBastian Köcher <bkchr@users.noreply.github.com>
parent 1be634da
Branches
No related merge requests found
......@@ -114,8 +114,6 @@ impl BatchVerifier {
/// aggregated result.
#[must_use]
pub fn verify_and_clear(&mut self) -> bool {
use std::sync::{Mutex, Condvar};
let pending = std::mem::replace(&mut self.pending_tasks, vec![]);
let started = std::time::Instant::now();
......@@ -139,14 +137,12 @@ impl BatchVerifier {
self.sr25519_items.clear();
if pending.len() > 0 {
let pair = Arc::new((Mutex::new(false), Condvar::new()));
let pair_clone = pair.clone();
let (sender, receiver) = std::sync::mpsc::channel();
if self.scheduler.spawn_obj(FutureObj::new(async move {
futures::future::join_all(pending).await;
let mut finished = pair_clone.0.lock().expect("Locking can only fail when the mutex is poisoned; qed");
*finished = true;
pair_clone.1.notify_all();
sender.send(())
.expect("Channel never panics if receiver is live. \
Receiver is always live until received this data; qed. ");
}.boxed())).is_err() {
log::debug!(
target: "runtime",
......@@ -155,11 +151,9 @@ impl BatchVerifier {
return false;
}
let (finished, cond_var) = &*pair;
let mut finished = finished.lock().expect("Locking can only fail when the mutex is poisoned; qed");
while !*finished {
finished = cond_var.wait(finished).expect("Waiting can only fail when the mutex waited on is poisoned; qed");
if receiver.recv().is_err() {
log::warn!(target: "runtime", "Haven't received async result from verification task. Returning false.");
return false;
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment