Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add check relax ordering on ci #4627

Merged
merged 3 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
chenyukang marked this conversation as resolved.
Show resolved Hide resolved

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
Loading