Skip to content

Commit 1d35833

Browse files
committed
Switch from AtomicU64 to Mutex.
Not all platforms support AtomicU64, so this swaps the usage with Mutex. The difference in performance should be imperceptible.
1 parent 6658e1a commit 1d35833

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/cargo-util/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-util"
3-
version = "0.2.8"
3+
version = "0.2.9"
44
rust-version.workspace = true
55
edition.workspace = true
66
license.workspace = true

crates/cargo-util/src/du.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use anyhow::{Context, Result};
44
use ignore::overrides::OverrideBuilder;
55
use ignore::{WalkBuilder, WalkState};
66
use std::path::Path;
7-
use std::sync::atomic::{AtomicU64, Ordering};
87
use std::sync::{Arc, Mutex};
98

109
/// Determines the disk usage of all files in the given directory.
@@ -40,7 +39,7 @@ fn du_inner(path: &Path, patterns: &[&str]) -> Result<u64> {
4039
.git_ignore(false)
4140
.git_exclude(false);
4241
let walker = builder.build_parallel();
43-
let total = Arc::new(AtomicU64::new(0));
42+
let total = Arc::new(Mutex::new(0u64));
4443
// A slot used to indicate there was an error while walking.
4544
//
4645
// It is possible that more than one error happens (such as in different
@@ -52,7 +51,8 @@ fn du_inner(path: &Path, patterns: &[&str]) -> Result<u64> {
5251
Ok(entry) => match entry.metadata() {
5352
Ok(meta) => {
5453
if meta.is_file() {
55-
total.fetch_add(meta.len(), Ordering::SeqCst);
54+
let mut lock = total.lock().unwrap();
55+
*lock += meta.len();
5656
}
5757
}
5858
Err(e) => {
@@ -73,5 +73,6 @@ fn du_inner(path: &Path, patterns: &[&str]) -> Result<u64> {
7373
return Err(e);
7474
}
7575

76-
Ok(total.load(Ordering::SeqCst))
76+
let total = *total.lock().unwrap();
77+
Ok(total)
7778
}

0 commit comments

Comments
 (0)