From 0add22e4543c7c936b45dccc0cfe766b85df063d Mon Sep 17 00:00:00 2001 From: Dinko Korunic Date: Sun, 8 Sep 2024 18:23:15 +0200 Subject: [PATCH] Atomic loads should use Acquire ordering and atomic stores Release ordering. --- src/calibrate.rs | 4 ++-- src/interrupt.rs | 2 +- src/walk.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/calibrate.rs b/src/calibrate.rs index 39cc4be..7888092 100644 --- a/src/calibrate.rs +++ b/src/calibrate.rs @@ -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"); } }); @@ -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"); diff --git a/src/interrupt.rs b/src/interrupt.rs index 3fa4abc..e46e164 100644 --- a/src/interrupt.rs +++ b/src/interrupt.rs @@ -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) -> Result<(), Error> { ctrlc::set_handler(move || { - shutdown.store(true, Ordering::SeqCst); + shutdown.store(true, Ordering::Release); }) .context("Unable to set Ctrl-C handler")?; diff --git a/src/walk.rs b/src/walk.rs index 39ccb9c..b8f295e 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -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()), @@ -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); } @@ -163,7 +163,7 @@ fn process_dir_entry( 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()) {