Skip to content

Commit

Permalink
Merge pull request #4627 from driftluo/ci-check-relaxed
Browse files Browse the repository at this point in the history
test: add check relax ordering on ci
  • Loading branch information
eval-exec committed Sep 2, 2024
2 parents 6fa274e + ea3651f commit 0e99a2a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 9 deletions.
40 changes: 40 additions & 0 deletions devtools/ci/check-relaxed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

set -euo pipefail

case "$OSTYPE" in
darwin*)
if ! type gsed &>/dev/null || ! type ggrep &>/dev/null; then
echo "GNU sed and grep not found! You can install via Homebrew" >&2
echo >&2
echo " brew install grep gnu-sed" >&2
exit 1
fi

SED=gsed
GREP=ggrep
;;
*)
SED=sed
GREP=grep
;;
esac

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

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
}

main "$@"
1 change: 1 addition & 0 deletions devtools/ci/ci_main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ case $GITHUB_WORKFLOW in
make check-dirty-rpc-doc
make check-dirty-hashes-toml
devtools/ci/check-cyclic-dependencies.py
devtools/ci/check-relaxed.sh
;;
ci_aarch64_build*)
echo "ci_aarch64_build"
Expand Down
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 0e99a2a

Please sign in to comment.