Skip to content

Commit

Permalink
Merge pull request #4623 from driftluo/fix-atomic-ordering
Browse files Browse the repository at this point in the history
fix: fix atomic ordering in multi-thread
  • Loading branch information
eval-exec authored Aug 30, 2024
2 parents 7749bcb + 258676a commit 2fb17ab
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions shared/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,14 @@ impl Shared {
/// Return whether chain is in initial block download
pub fn is_initial_block_download(&self) -> bool {
// Once this function has returned false, it must remain false.
if self.ibd_finished.load(Ordering::Relaxed) {
if self.ibd_finished.load(Ordering::Acquire) {
false
} else if unix_time_as_millis().saturating_sub(self.snapshot().tip_header().timestamp())
> MAX_TIP_AGE
{
true
} else {
self.ibd_finished.store(true, Ordering::Relaxed);
self.ibd_finished.store(true, Ordering::Release);
false
}
}
Expand Down
4 changes: 2 additions & 2 deletions shared/src/types/header_map/kernel_lru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ where
self.stats().tick_primary_delete();
}
// If IBD is not finished, don't shrink memory map
let allow_shrink_to_fit = self.ibd_finished.load(Ordering::Relaxed);
let allow_shrink_to_fit = self.ibd_finished.load(Ordering::Acquire);
self.memory.remove(hash, allow_shrink_to_fit);
if self.backend.is_empty() {
return;
Expand All @@ -175,7 +175,7 @@ where
});

// If IBD is not finished, don't shrink memory map
let allow_shrink_to_fit = self.ibd_finished.load(Ordering::Relaxed);
let allow_shrink_to_fit = self.ibd_finished.load(Ordering::Acquire);
self.memory
.remove_batch(values.iter().map(|value| value.hash()), allow_shrink_to_fit);
}
Expand Down
6 changes: 3 additions & 3 deletions tx-pool/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ macro_rules! send_notify {
impl TxPoolController {
/// Return whether tx-pool service is started
pub fn service_started(&self) -> bool {
self.started.load(Ordering::Relaxed)
self.started.load(Ordering::Acquire)
}

/// Set tx-pool service started, should only used for test
#[cfg(feature = "internal")]
pub fn set_service_started(&self, v: bool) {
self.started.store(v, Ordering::Relaxed);
self.started.store(v, Ordering::Release);
}

/// Return reference of tokio runtime handle
Expand Down Expand Up @@ -658,7 +658,7 @@ impl TxPoolServiceBuilder {
}
}
});
self.started.store(true, Ordering::Relaxed);
self.started.store(true, Ordering::Release);
if let Err(err) = self.tx_pool_controller.load_persisted_data(txs) {
error!("Failed to import persistent txs, cause: {}", err);
}
Expand Down

0 comments on commit 2fb17ab

Please sign in to comment.