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

Fine-tune the Ordering for the atomic usages #2706

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/core/messages.rs
Expand Up @@ -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.
Expand All @@ -122,18 +122,18 @@ 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.
///
/// 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);
}
2 changes: 1 addition & 1 deletion crates/ignore/src/lib.rs
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions crates/ignore/src/walk.rs
Expand Up @@ -1712,12 +1712,12 @@ impl<'s> Worker<'s> {

/// Indicates that all workers should quit immediately.
fn quit_now(&self) {
self.quit_now.store(true, AtomicOrdering::SeqCst);
self.quit_now.store(true, AtomicOrdering::Release);
}

/// Returns true if this worker should quit immediately.
fn is_quit_now(&self) -> bool {
self.quit_now.load(AtomicOrdering::SeqCst)
self.quit_now.load(AtomicOrdering::Acquire)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this and the Release above need comments justifying why this is correct.

}

/// Send work.
Expand Down
2 changes: 1 addition & 1 deletion tests/util.rs
Expand Up @@ -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()
Expand Down