queue: park directly instead of through condvar
This commit is contained in:
parent
133796b7ff
commit
53afb8d22d
@ -66,20 +66,20 @@ impl Default for Config {
|
|||||||
|
|
||||||
struct VerifierHandle {
|
struct VerifierHandle {
|
||||||
deleting: Arc<AtomicBool>,
|
deleting: Arc<AtomicBool>,
|
||||||
sleep: Arc<(Mutex<bool>, Condvar)>,
|
sleep: Arc<AtomicBool>,
|
||||||
thread: JoinHandle<()>,
|
thread: JoinHandle<()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VerifierHandle {
|
impl VerifierHandle {
|
||||||
// signal to the verifier thread that it should sleep.
|
// signal to the verifier thread that it should sleep.
|
||||||
fn sleep(&self) {
|
fn sleep(&self) {
|
||||||
*self.sleep.0.lock() = true;
|
self.sleep.store(true, AtomicOrdering::SeqCst);
|
||||||
}
|
}
|
||||||
|
|
||||||
// signal to the verifier thread that it should wake up.
|
// signal to the verifier thread that it should wake up.
|
||||||
fn wake_up(&self) {
|
fn wake_up(&self) {
|
||||||
*self.sleep.0.lock() = false;
|
self.sleep.store(false, AtomicOrdering::SeqCst);
|
||||||
self.sleep.1.notify_all();
|
self.thread.thread().unpark();
|
||||||
}
|
}
|
||||||
|
|
||||||
// signal to the verifier thread that it should conclude its
|
// signal to the verifier thread that it should conclude its
|
||||||
@ -91,7 +91,7 @@ impl VerifierHandle {
|
|||||||
|
|
||||||
// join the verifier thread.
|
// join the verifier thread.
|
||||||
fn join(self) {
|
fn join(self) {
|
||||||
self.thread.join().unwrap();
|
self.thread.join().expect("Verifier thread panicked");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,9 +241,9 @@ impl<K: Kind> VerificationQueue<K> {
|
|||||||
|
|
||||||
// enable only the first few verifiers.
|
// enable only the first few verifiers.
|
||||||
let sleep = if i < default_amount {
|
let sleep = if i < default_amount {
|
||||||
Arc::new((Mutex::new(false), Condvar::new()))
|
Arc::new(AtomicBool::new(false))
|
||||||
} else {
|
} else {
|
||||||
Arc::new((Mutex::new(true), Condvar::new()))
|
Arc::new(AtomicBool::new(true))
|
||||||
};
|
};
|
||||||
|
|
||||||
verifiers.push(VerifierHandle {
|
verifiers.push(VerifierHandle {
|
||||||
@ -283,14 +283,13 @@ impl<K: Kind> VerificationQueue<K> {
|
|||||||
ready: Arc<QueueSignal>,
|
ready: Arc<QueueSignal>,
|
||||||
deleting: Arc<AtomicBool>,
|
deleting: Arc<AtomicBool>,
|
||||||
empty: Arc<SCondvar>,
|
empty: Arc<SCondvar>,
|
||||||
sleep: Arc<(Mutex<bool>, Condvar)>,
|
sleep: Arc<AtomicBool>,
|
||||||
) {
|
) {
|
||||||
while !deleting.load(AtomicOrdering::Acquire) {
|
while !deleting.load(AtomicOrdering::Acquire) {
|
||||||
{
|
{
|
||||||
let mut should_sleep = sleep.0.lock();
|
while sleep.load(AtomicOrdering::SeqCst) {
|
||||||
while *should_sleep {
|
|
||||||
trace!(target: "verification", "Verifier sleeping");
|
trace!(target: "verification", "Verifier sleeping");
|
||||||
sleep.1.wait(&mut should_sleep);
|
::std::thread::park();
|
||||||
trace!(target: "verification", "Verifier waking up");
|
trace!(target: "verification", "Verifier waking up");
|
||||||
|
|
||||||
if deleting.load(AtomicOrdering::Acquire) {
|
if deleting.load(AtomicOrdering::Acquire) {
|
||||||
|
Loading…
Reference in New Issue
Block a user