Skip to content

Commit

Permalink
chore: remove all relax order
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Aug 30, 2024
1 parent b86e176 commit 3d78da8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
18 changes: 15 additions & 3 deletions devtools/ci/check-relaxed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,21 @@ case "$OSTYPE" in
;;
esac

find ./ -not -path '*/target/*' -type f -name "*.rs" | xargs grep -H "Relaxed"
function main() {
local res=$(find ./ -not -path '*/target/*' -type f -name "*.rs" | xargs grep -H "Relaxed")

if [ $? -eq 0 ]; then
if [ -z "${res}" ]; then
echo "ok"
exit 0
else
echo "find use Relaxed on code, please check"

for file in ${res}; do
printf ${file}
done

exit 1
fi
fi
}

main "$@"
4 changes: 2 additions & 2 deletions network/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ impl NetworkState {

/// Network message processing controller, default is true, if false, discard any received messages
pub fn is_active(&self) -> bool {
self.active.load(Ordering::Relaxed)
self.active.load(Ordering::Acquire)
}
}

Expand Down Expand Up @@ -1368,7 +1368,7 @@ impl NetworkController {

/// Change active status, if set false discard any received messages
pub fn set_active(&self, active: bool) {
self.network_state.active.store(active, Ordering::Relaxed);
self.network_state.active.store(active, Ordering::Release);
}

/// Return all connected peers' protocols info
Expand Down
9 changes: 6 additions & 3 deletions sync/src/tests/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use ckb_types::{
use rand::{thread_rng, Rng};
use std::{
collections::{BTreeMap, HashMap},
sync::atomic::{AtomicUsize, Ordering::Relaxed},
sync::atomic::{
AtomicUsize,
Ordering::{Acquire, SeqCst},
},
};

use crate::types::{TtlFilter, FILTER_TTL};
Expand Down Expand Up @@ -64,15 +67,15 @@ fn test_get_ancestor_use_skip_list() {
0,
b,
|hash, _| {
count.fetch_add(1, Relaxed);
count.fetch_add(1, SeqCst);
header_map.get(hash).cloned()
},
|_, _| None,
)
.unwrap();

// Search must finished in <limit> steps
assert!(count.load(Relaxed) <= limit);
assert!(count.load(Acquire) <= limit);

header
};
Expand Down
4 changes: 2 additions & 2 deletions tx-pool/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1117,10 +1117,10 @@ impl TxPoolService {
}

pub fn after_delay(&self) -> bool {
self.after_delay.load(Ordering::Relaxed)
self.after_delay.load(Ordering::Acquire)
}

pub fn set_after_delay_true(&self) {
self.after_delay.store(true, Ordering::Relaxed);
self.after_delay.store(true, Ordering::Release);
}
}
4 changes: 2 additions & 2 deletions util/systemtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ impl FaketimeGuard {
/// Set faketime
#[cfg(feature = "enable_faketime")]
pub fn set_faketime(&self, time: u64) {
FAKETIME.store(time, Ordering::Relaxed);
FAKETIME.store(time, Ordering::Release);
FAKETIME_ENABLED.store(true, Ordering::SeqCst);
}

/// Disable faketime
#[cfg(feature = "enable_faketime")]
pub fn disable_faketime(&self) {
FAKETIME_ENABLED.store(false, Ordering::Relaxed);
FAKETIME_ENABLED.store(false, Ordering::Release);
}
}

Expand Down

0 comments on commit 3d78da8

Please sign in to comment.