diff --git a/bin/oe/run.rs b/bin/oe/run.rs index e4eae651f..b1892aebb 100644 --- a/bin/oe/run.rs +++ b/bin/oe/run.rs @@ -450,7 +450,15 @@ pub fn execute(cmd: RunCmd, logger: Arc) -> Result for AuthorityRound { /// `Seal::None` will be returned. fn generate_seal(&self, block: &ExecutedBlock, parent: &Header) -> Seal { // first check to avoid generating signature most of the time - // (but there's still a race to the `compare_and_swap`) + // (but there's still a race to the `compare_exchange`) if !self.step.can_propose.load(AtomicOrdering::SeqCst) { trace!(target: "engine", "Aborting seal generation. Can't propose."); return Seal::None; @@ -1245,7 +1245,8 @@ impl Engine for AuthorityRound { if self .step .can_propose - .compare_and_swap(true, false, AtomicOrdering::SeqCst) + .compare_exchange(true, false, AtomicOrdering::SeqCst, AtomicOrdering::SeqCst) + .is_ok() { self.generate_empty_step(header.parent_hash()); } @@ -1266,11 +1267,12 @@ impl Engine for AuthorityRound { )) { trace!(target: "engine", "generate_seal: Issuing a block for step {}.", step); - // only issue the seal if we were the first to reach the compare_and_swap. + // only issue the seal if we were the first to reach the compare_exchange. if self .step .can_propose - .compare_and_swap(true, false, AtomicOrdering::SeqCst) + .compare_exchange(true, false, AtomicOrdering::SeqCst, AtomicOrdering::SeqCst) + .is_ok() { // we can drop all accumulated empty step messages that are // older than the parent step since we're including them in diff --git a/crates/ethcore/src/engines/instant_seal.rs b/crates/ethcore/src/engines/instant_seal.rs index 0c7749fa0..6d944a52f 100644 --- a/crates/ethcore/src/engines/instant_seal.rs +++ b/crates/ethcore/src/engines/instant_seal.rs @@ -81,12 +81,16 @@ impl Engine for InstantSeal { // Return a regular seal if the given block is _higher_ than // the last sealed one if block_number > last_sealed_block { - let prev_last_sealed_block = self.last_sealed_block.compare_and_swap( - last_sealed_block, - block_number, - Ordering::SeqCst, - ); - if prev_last_sealed_block == last_sealed_block { + if self + .last_sealed_block + .compare_exchange( + last_sealed_block, + block_number, + Ordering::SeqCst, + Ordering::SeqCst, + ) + .is_ok() + { return Seal::Regular(Vec::new()); } } diff --git a/crates/ethcore/src/snapshot/service.rs b/crates/ethcore/src/snapshot/service.rs index 556e0609e..17799b2b1 100644 --- a/crates/ethcore/src/snapshot/service.rs +++ b/crates/ethcore/src/snapshot/service.rs @@ -516,7 +516,8 @@ impl Service { pub fn take_snapshot(&self, client: &Client, num: u64) -> Result<(), Error> { if self .taking_snapshot - .compare_and_swap(false, true, Ordering::SeqCst) + .compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst) + .is_err() { info!( "Skipping snapshot at #{} as another one is currently in-progress.", diff --git a/crates/ethcore/src/verification/queue/mod.rs b/crates/ethcore/src/verification/queue/mod.rs index cb67d689c..b6f2b8bba 100644 --- a/crates/ethcore/src/verification/queue/mod.rs +++ b/crates/ethcore/src/verification/queue/mod.rs @@ -181,8 +181,13 @@ impl QueueSignal { if self .signalled - .compare_and_swap(false, true, AtomicOrdering::Relaxed) - == false + .compare_exchange( + false, + true, + AtomicOrdering::Relaxed, + AtomicOrdering::Relaxed, + ) + .is_ok() { let channel = self.message_channel.lock().clone(); if let Err(e) = channel.send_sync(ClientIoMessage::BlockVerified) { @@ -199,8 +204,13 @@ impl QueueSignal { if self .signalled - .compare_and_swap(false, true, AtomicOrdering::Relaxed) - == false + .compare_exchange( + false, + true, + AtomicOrdering::Relaxed, + AtomicOrdering::Relaxed, + ) + .is_ok() { let channel = self.message_channel.lock().clone(); if let Err(e) = channel.send(ClientIoMessage::BlockVerified) {