From 85a86eba2b1b55f2839b92610b27be15a5448c34 Mon Sep 17 00:00:00 2001 From: wang384670111 <384670111@qq.com> Date: Mon, 8 Jan 2024 16:10:57 +0800 Subject: [PATCH] impl: switch most atomic ops to `Relaxed` ordering These all seem pretty straight-forward. Compared with #2706, I dropped the changes to the atomic orderings used in `ignore` because I haven't had time to think through that carefully. But the ops in this PR seem fine. Closes #2706 --- crates/core/messages.rs | 12 ++++++------ crates/ignore/src/lib.rs | 2 +- tests/util.rs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/core/messages.rs b/crates/core/messages.rs index ba8b9adc..333e7076 100644 --- a/crates/core/messages.rs +++ b/crates/core/messages.rs @@ -99,19 +99,19 @@ macro_rules! ignore_message { /// Returns true if and only if messages should be shown. pub(crate) fn messages() -> bool { - MESSAGES.load(Ordering::SeqCst) + MESSAGES.load(Ordering::Relaxed) } /// Set whether messages should be shown or not. /// /// By default, they are not shown. pub(crate) fn set_messages(yes: bool) { - MESSAGES.store(yes, Ordering::SeqCst) + MESSAGES.store(yes, Ordering::Relaxed) } /// Returns true if and only if "ignore" related messages should be shown. pub(crate) fn ignore_messages() -> bool { - IGNORE_MESSAGES.load(Ordering::SeqCst) + IGNORE_MESSAGES.load(Ordering::Relaxed) } /// Set whether "ignore" related messages should be shown or not. @@ -122,12 +122,12 @@ pub(crate) fn ignore_messages() -> bool { /// `messages` is disabled, then "ignore" messages are never shown, regardless /// of this setting. pub(crate) fn set_ignore_messages(yes: bool) { - IGNORE_MESSAGES.store(yes, Ordering::SeqCst) + IGNORE_MESSAGES.store(yes, Ordering::Relaxed) } /// Returns true if and only if ripgrep came across a non-fatal error. pub(crate) fn errored() -> bool { - ERRORED.load(Ordering::SeqCst) + ERRORED.load(Ordering::Relaxed) } /// Indicate that ripgrep has come across a non-fatal error. @@ -135,5 +135,5 @@ pub(crate) fn errored() -> bool { /// Callers should not use this directly. Instead, it is called automatically /// via the `err_message` macro. pub(crate) fn set_errored() { - ERRORED.store(true, Ordering::SeqCst); + ERRORED.store(true, Ordering::Relaxed); } diff --git a/crates/ignore/src/lib.rs b/crates/ignore/src/lib.rs index a5d5ca30..74c96edd 100644 --- a/crates/ignore/src/lib.rs +++ b/crates/ignore/src/lib.rs @@ -527,7 +527,7 @@ mod tests { let tmpdir = env::temp_dir(); for _ in 0..TRIES { - let count = COUNTER.fetch_add(1, Ordering::SeqCst); + let count = COUNTER.fetch_add(1, Ordering::Relaxed); let path = tmpdir.join("rust-ignore").join(count.to_string()); if path.is_dir() { continue; diff --git a/tests/util.rs b/tests/util.rs index 07a1a783..41017660 100644 --- a/tests/util.rs +++ b/tests/util.rs @@ -68,7 +68,7 @@ impl Dir { /// does not need to be distinct for each invocation, but should correspond /// to a logical grouping of tests. pub fn new(name: &str) -> Dir { - let id = NEXT_ID.fetch_add(1, Ordering::SeqCst); + let id = NEXT_ID.fetch_add(1, Ordering::Relaxed); let root = env::current_exe() .unwrap() .parent()