Skip to content

Commit

Permalink
Atomic loads should use Acquire ordering and atomic stores Release or…
Browse files Browse the repository at this point in the history
…dering.
  • Loading branch information
dkorunic committed Sep 8, 2024
1 parent 3b7b689 commit 0add22e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/calibrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn get_inode_ratio(
// Mass create files; filenames are short to get minimal size to inode ratio
pool.install(|| {
(0..args.calibration_count).into_par_iter().for_each(|i| {
if !shutdown.load(Ordering::SeqCst) {
if !shutdown.load(Ordering::Acquire) {
File::create(test_path.join(i.to_string())).expect("Unable to create files");
}
});
Expand All @@ -83,7 +83,7 @@ pub fn get_inode_ratio(
pb.finish_with_message("Done.");

// Terminate on received interrupt signal
if shutdown.load(Ordering::SeqCst) {
if shutdown.load(Ordering::Acquire) {
println!("Requested program exit, stopping and deleting temporary files...",);
ensure_removed(test_path)
.expect("Unable to completely delete calibration directory, exiting");
Expand Down
2 changes: 1 addition & 1 deletion src/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use anyhow::{Context, Error};
/// Returns an error if the Ctrl-C handler cannot be set, encapsulated in an `anyhow::Error`.
pub fn setup_interrupt_handler(shutdown: Arc<AtomicBool>) -> Result<(), Error> {
ctrlc::set_handler(move || {
shutdown.store(true, Ordering::SeqCst);
shutdown.store(true, Ordering::Release);
})
.context("Unable to set Ctrl-C handler")?;

Expand Down
6 changes: 3 additions & 3 deletions src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub fn parallel_search(
pool.spawn(move || loop {
sleep(Duration::from_secs(sleep_delay));

let count = dir_count_status.load(Ordering::SeqCst);
let count = dir_count_status.load(Ordering::Acquire);
println!(
"Processed {} directories so far, next update in {} seconds",
Green.paint(count.to_string()),
Expand All @@ -104,7 +104,7 @@ pub fn parallel_search(
})
.process_read_dir(move |_, _, (), children| {
// Terminate on received interrupt signal
if shutdown.load(Ordering::SeqCst) {
if shutdown.load(Ordering::Acquire) {
println!("Requested program exit, stopping scan...");
process::exit(ERROR_EXIT);
}
Expand Down Expand Up @@ -163,7 +163,7 @@ fn process_dir_entry<E>(
if dir_entry.file_type.is_dir() {
if let Some(full_path) = dir_entry.read_children_path.as_ref() {
// Visited directory count
dir_count_walk.fetch_add(1, Ordering::SeqCst);
dir_count_walk.fetch_add(1, Ordering::AcqRel);

// Ignore skip paths, typically being virtual filesystems (/proc, /dev, /sys, /run)
if !skip_path.is_empty() && skip_path.contains(&full_path.to_path_buf()) {
Expand Down

0 comments on commit 0add22e

Please sign in to comment.