Migrate compare_and_swap to compare_exchange (#291)
This commit is contained in:
parent
0fcb102f03
commit
dbc5f94241
@ -450,7 +450,15 @@ pub fn execute(cmd: RunCmd, logger: Arc<RotatingLogger>) -> Result<RunningClient
|
||||
let is_ready = Arc::new(atomic::AtomicBool::new(true));
|
||||
miner.add_transactions_listener(Box::new(move |_hashes| {
|
||||
// we want to have only one PendingTransactions task in the queue.
|
||||
if is_ready.compare_and_swap(true, false, atomic::Ordering::SeqCst) {
|
||||
if is_ready
|
||||
.compare_exchange(
|
||||
true,
|
||||
false,
|
||||
atomic::Ordering::SeqCst,
|
||||
atomic::Ordering::SeqCst,
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
let task =
|
||||
::sync::PriorityTask::PropagateTransactions(Instant::now(), is_ready.clone());
|
||||
// we ignore error cause it means that we are closing
|
||||
|
@ -1187,7 +1187,7 @@ impl Engine<EthereumMachine> 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<EthereumMachine> 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<EthereumMachine> 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
|
||||
|
@ -81,12 +81,16 @@ impl<M: Machine> Engine<M> for InstantSeal<M> {
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
|
@ -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.",
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user