Skip to content

Commit c149e7c

Browse files
committed
modified atomic::ordering about all atomic types
1 parent 8cfa165 commit c149e7c

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

node/src/beacon/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<N: Network, C: ConsensusStorage<N>> NodeInterface<N> for Beacon<N, C> {
183183

184184
// Shut down block production.
185185
trace!("Shutting down block production...");
186-
self.shutdown.store(true, Ordering::SeqCst);
186+
self.shutdown.store(true, Ordering::Relaxed);
187187

188188
// Abort the tasks.
189189
trace!("Shutting down the beacon...");
@@ -231,7 +231,7 @@ impl<N: Network, C: ConsensusStorage<N>> Beacon<N, C> {
231231

232232
// Do not produce a block if the elapsed time has not exceeded `ROUND_TIME - block_generation_time`.
233233
// This will ensure a block is produced at intervals of approximately `ROUND_TIME`.
234-
let time_to_wait = ROUND_TIME.saturating_sub(beacon.block_generation_time.load(Ordering::SeqCst));
234+
let time_to_wait = ROUND_TIME.saturating_sub(beacon.block_generation_time.load(Ordering::Acquire));
235235
trace!("Waiting for {time_to_wait} seconds before producing a block...");
236236
if elapsed_time < time_to_wait {
237237
if let Err(error) = timeout(
@@ -249,7 +249,7 @@ impl<N: Network, C: ConsensusStorage<N>> Beacon<N, C> {
249249
// Produce the next block and propagate it to all peers.
250250
match beacon.produce_next_block().await {
251251
// Update the block generation time.
252-
Ok(()) => beacon.block_generation_time.store(timer.elapsed().as_secs(), Ordering::SeqCst),
252+
Ok(()) => beacon.block_generation_time.store(timer.elapsed().as_secs(), Ordering::Release),
253253
Err(error) => error!("{error}"),
254254
}
255255

node/src/prover/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl<N: Network, C: ConsensusStorage<N>> NodeInterface<N> for Prover<N, C> {
120120

121121
// Shut down the coinbase puzzle.
122122
trace!("Shutting down the coinbase puzzle...");
123-
self.shutdown.store(true, Ordering::SeqCst);
123+
self.shutdown.store(true, Ordering::Relaxed);
124124

125125
// Abort the tasks.
126126
trace!("Shutting down the prover...");
@@ -244,19 +244,19 @@ impl<N: Network, C: ConsensusStorage<N>> Prover<N, C> {
244244

245245
/// Returns the current number of puzzle instances.
246246
fn num_puzzle_instances(&self) -> u8 {
247-
self.puzzle_instances.load(Ordering::SeqCst)
247+
self.puzzle_instances.load(Ordering::Relaxed)
248248
}
249249

250250
/// Increments the number of puzzle instances.
251251
fn increment_puzzle_instances(&self) {
252-
self.puzzle_instances.fetch_add(1, Ordering::SeqCst);
252+
self.puzzle_instances.fetch_add(1, Ordering::Relaxed);
253253
#[cfg(debug_assertions)]
254254
trace!("Number of Instances - {}", self.num_puzzle_instances());
255255
}
256256

257257
/// Decrements the number of puzzle instances.
258258
fn decrement_puzzle_instances(&self) {
259-
self.puzzle_instances.fetch_sub(1, Ordering::SeqCst);
259+
self.puzzle_instances.fetch_sub(1, Ordering::Relaxed);
260260
#[cfg(debug_assertions)]
261261
trace!("Number of Instances - {}", self.num_puzzle_instances());
262262
}

node/src/validator/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl<N: Network, C: ConsensusStorage<N>> NodeInterface<N> for Validator<N, C> {
136136

137137
// Shut down the sync pool.
138138
trace!("Shutting down the sync pool...");
139-
self.shutdown.store(true, Ordering::SeqCst);
139+
self.shutdown.store(true, Ordering::Relaxed);
140140

141141
// Abort the tasks.
142142
trace!("Shutting down the validator...");

node/store/src/rocksdb/map.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<
4444
///
4545
fn insert(&self, key: K, value: V) -> Result<()> {
4646
// Determine if an atomic batch is in progress.
47-
let is_batch = self.batch_in_progress.load(Ordering::SeqCst);
47+
let is_batch = self.batch_in_progress.load(Ordering::Acquire);
4848

4949
match is_batch {
5050
// If a batch is in progress, add the key-value pair to the batch.
@@ -68,7 +68,7 @@ impl<
6868
///
6969
fn remove(&self, key: &K) -> Result<()> {
7070
// Determine if an atomic batch is in progress.
71-
let is_batch = self.batch_in_progress.load(Ordering::SeqCst);
71+
let is_batch = self.batch_in_progress.load(Ordering::Acquire);
7272

7373
match is_batch {
7474
// If a batch is in progress, add the key to the batch.
@@ -92,7 +92,7 @@ impl<
9292
///
9393
fn start_atomic(&self) {
9494
// Set the atomic batch flag to `true`.
95-
self.batch_in_progress.store(true, Ordering::SeqCst);
95+
self.batch_in_progress.store(true, Ordering::Relaxed);
9696
// Ensure that the atomic batch is empty.
9797
assert!(self.atomic_batch.lock().is_empty());
9898
}
@@ -103,7 +103,7 @@ impl<
103103
/// if they are already part of a larger one.
104104
///
105105
fn is_atomic_in_progress(&self) -> bool {
106-
self.batch_in_progress.load(Ordering::SeqCst)
106+
self.batch_in_progress.load(Ordering::Acquire)
107107
}
108108

109109
///
@@ -113,7 +113,7 @@ impl<
113113
// Clear the atomic batch.
114114
*self.atomic_batch.lock() = Default::default();
115115
// Set the atomic batch flag to `false`.
116-
self.batch_in_progress.store(false, Ordering::SeqCst);
116+
self.batch_in_progress.store(false, Ordering::Release);
117117
}
118118

119119
///
@@ -146,7 +146,7 @@ impl<
146146
}
147147

148148
// Set the atomic batch flag to `false`.
149-
self.batch_in_progress.store(false, Ordering::SeqCst);
149+
self.batch_in_progress.store(false, Ordering::Release);
150150

151151
Ok(())
152152
}
@@ -201,7 +201,7 @@ impl<
201201
K: Borrow<Q>,
202202
Q: PartialEq + Eq + Hash + Serialize + ?Sized,
203203
{
204-
if self.batch_in_progress.load(Ordering::SeqCst) { self.atomic_batch.lock().get(key).cloned() } else { None }
204+
if self.batch_in_progress.load(Ordering::Acquire) { self.atomic_batch.lock().get(key).cloned() } else { None }
205205
}
206206

207207
///

node/tcp/src/tcp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Tcp {
8686
pub fn new(mut config: Config) -> Self {
8787
// If there is no pre-configured name, assign a sequential numeric identifier.
8888
if config.name.is_none() {
89-
config.name = Some(SEQUENTIAL_NODE_ID.fetch_add(1, SeqCst).to_string());
89+
config.name = Some(SEQUENTIAL_NODE_ID.fetch_add(1, Relaxed).to_string());
9090
}
9191

9292
// Create a tracing span containing the node's name.

0 commit comments

Comments
 (0)