Fixing wait loop in case of spurious wake-ups.

This commit is contained in:
Tomasz Drwięga 2016-06-02 13:19:44 +02:00
parent 77942c0b48
commit ee3f608204

View File

@ -125,9 +125,13 @@ impl ConfirmationPromise {
let deadline = Instant::now() + timeout; let deadline = Instant::now() + timeout;
info!(target: "own_tx", "Signer: Awaiting transaction confirmation... ({:?}).", self.id); info!(target: "own_tx", "Signer: Awaiting transaction confirmation... ({:?}).", self.id);
while Instant::now() < deadline { loop {
// Park thread let now = Instant::now();
thread::park_timeout(timeout); if now >= deadline {
break;
}
// Park thread (may wake up spuriously)
thread::park_timeout(deadline - now);
// Take confirmation result // Take confirmation result
let res = self.result.lock().unwrap(); let res = self.result.lock().unwrap();
// Check the result // Check the result
@ -137,7 +141,7 @@ impl ConfirmationPromise {
ConfirmationResult::Waiting => continue, ConfirmationResult::Waiting => continue,
} }
} }
// We reached the timeout. Just return `None` and make sure to remove waiting. // We reached the timeout. Just return `None`
trace!(target: "own_tx", "Signer: Confirmation timeout reached... ({:?}).", self.id); trace!(target: "own_tx", "Signer: Confirmation timeout reached... ({:?}).", self.id);
None None
} }