Skip to content

Commit 491cda2

Browse files
committed
bin: remove use of atomic counters
1 parent 4ec974b commit 491cda2

File tree

5 files changed

+21
-49
lines changed

5 files changed

+21
-49
lines changed

bin/src/modules/binarize/mod.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
use std::{
2-
ffi::OsStr,
3-
fs::create_dir_all,
4-
path::PathBuf,
5-
process::Command,
6-
sync::{
7-
RwLock,
8-
atomic::{AtomicU16, Ordering},
9-
},
10-
};
1+
use std::{ffi::OsStr, fs::create_dir_all, path::PathBuf, process::Command, sync::RwLock};
112

123
use hemtt_common::config::PDriveOption;
134
use hemtt_p3d::SearchCache;
@@ -289,7 +280,6 @@ impl Module for Binarize {
289280
return Ok(Report::new());
290281
}
291282
let mut report = Report::new();
292-
let counter = AtomicU16::new(0);
293283
self.prechecked
294284
.read()
295285
.expect("can read in pre_build")
@@ -359,7 +349,6 @@ impl Module for Binarize {
359349
output.status.code().unwrap_or(-1)
360350
);
361351
if PathBuf::from(&target.output).join(&target.entry).exists() {
362-
counter.fetch_add(1, Ordering::Relaxed);
363352
None
364353
} else {
365354
Some(BinarizeFailed::code(target.entry.clone()))
@@ -372,7 +361,13 @@ impl Module for Binarize {
372361
report.push(error);
373362
});
374363

375-
info!("Binarized {} files", counter.load(Ordering::Relaxed));
364+
info!(
365+
"Binarized {} files",
366+
self.prechecked
367+
.read()
368+
.expect("prechecked should not be poisoned")
369+
.len()
370+
);
376371
Ok(report)
377372
}
378373
}

bin/src/modules/pbo.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use std::{
2-
fs::{File, create_dir_all},
3-
sync::atomic::{AtomicU16, Ordering},
4-
};
1+
use std::fs::{File, create_dir_all};
52

63
use git2::Repository;
74
use hemtt_common::{
@@ -41,20 +38,18 @@ pub fn build(ctx: &Context, collapse: Collapse) -> Result<Report, Error> {
4138
})
4239
})
4340
};
44-
let counter = AtomicU16::new(0);
45-
let progress = progress_bar(ctx.addons().to_vec().len() as u64).with_message("Building PBOs");
46-
ctx.addons()
47-
.to_vec()
41+
let addons = ctx.addons().to_vec();
42+
let progress = progress_bar(addons.len() as u64).with_message("Building PBOs");
43+
addons
4844
.iter()
4945
.map(|addon| {
5046
internal_build(ctx, addon, collapse, &version, git_hash.as_deref())?;
5147
progress.inc(1);
52-
counter.fetch_add(1, Ordering::Relaxed);
5348
Ok(())
5449
})
5550
.collect::<Result<Vec<_>, Error>>()?;
5651
progress.finish_and_clear();
57-
info!("Built {} PBOs", counter.load(Ordering::Relaxed));
52+
info!("Built {} PBOs", addons.len());
5853
Ok(Report::new())
5954
}
6055

bin/src/modules/rapifier.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
use std::{
2-
collections::HashMap,
3-
path::PathBuf,
4-
sync::{
5-
RwLock,
6-
atomic::{AtomicU16, Ordering},
7-
},
8-
};
1+
use std::{collections::HashMap, path::PathBuf, sync::RwLock};
92

103
use hemtt_config::{
114
Config,
@@ -61,7 +54,6 @@ impl Module for Rapifier {
6154
fn pre_build(&self, ctx: &Context) -> Result<Report, Error> {
6255
ctx.state().set(AddonConfigs::default());
6356
let mut report = Report::new();
64-
let counter = AtomicU16::new(0);
6557
let glob_options = glob::MatchOptions {
6658
require_literal_separator: true,
6759
..Default::default()
@@ -101,7 +93,6 @@ impl Module for Rapifier {
10193
.par_iter()
10294
.map(|(addon, entry)| {
10395
let report = rapify(addon, entry, ctx)?;
104-
counter.fetch_add(1, Ordering::Relaxed);
10596
progress.inc(1);
10697
Ok(report)
10798
})
@@ -112,7 +103,7 @@ impl Module for Rapifier {
112103
}
113104

114105
progress.finish_and_clear();
115-
info!("Rapified {} addon configs", counter.load(Ordering::Relaxed));
106+
info!("Rapified {} addon configs", entries.len());
116107
report.extend(lint_all(Some(ctx.config()), &ctx.addons().to_vec()));
117108
Ok(report)
118109
}

bin/src/modules/sqf.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use std::sync::{
2-
Arc,
3-
atomic::{AtomicU16, Ordering},
4-
};
1+
use std::sync::Arc;
52

63
use hemtt_common::version::Version;
74
use hemtt_preprocessor::Processor;
@@ -57,7 +54,6 @@ impl Module for SQFCompiler {
5754
fn pre_build(&self, ctx: &Context) -> Result<Report, Error> {
5855
let mut report = Report::new();
5956
let sqf_ext = Some(String::from("sqf"));
60-
let counter = AtomicU16::new(0);
6157
let mut entries = Vec::new();
6258
for addon in ctx.addons() {
6359
let addon = Arc::new(addon.clone());
@@ -109,7 +105,6 @@ impl Module for SQFCompiler {
109105
if !codes.failed() {
110106
let mut out = entry.with_extension("sqfc")?.create_file()?;
111107
sqf.optimize().compile_to_writer(&processed, &mut out)?;
112-
counter.fetch_add(1, Ordering::Relaxed);
113108
progress.inc(1);
114109
}
115110
for code in codes {
@@ -142,7 +137,7 @@ impl Module for SQFCompiler {
142137
report.merge(new_report);
143138
}
144139
progress.finish_and_clear();
145-
info!("Compiled {} sqf files", counter.load(Ordering::Relaxed));
140+
info!("Compiled {} sqf files", entries.len());
146141

147142
report.extend(lint_all(
148143
Some(ctx.config()),

bin/src/modules/stringtables.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use std::sync::{
2-
Arc, Mutex,
3-
atomic::{AtomicU16, Ordering},
4-
};
1+
use std::sync::{Arc, Mutex};
52

63
use hemtt_stringtable::{
74
Project,
@@ -67,8 +64,8 @@ impl Module for Stringtables {
6764
}),
6865
);
6966
}
70-
let counter = AtomicU16::new(0);
71-
let progress = progress_bar(paths.len() as u64).with_message("Processing Stringtables");
67+
let length = paths.len();
68+
let progress = progress_bar(length as u64).with_message("Processing Stringtables");
7269
let results = paths
7370
.into_par_iter()
7471
.map(|path| match Project::read(path.clone()) {
@@ -77,7 +74,6 @@ impl Module for Stringtables {
7774
if !codes.iter().any(|c| c.severity() == Severity::Error) {
7875
convert_stringtable(&project);
7976
}
80-
counter.fetch_add(1, Ordering::Relaxed);
8177
progress.inc(1);
8278
Some((project, codes))
8379
}
@@ -109,7 +105,7 @@ impl Module for Stringtables {
109105
ctx.addons().to_vec(),
110106
));
111107
progress.finish_and_clear();
112-
info!("Checked {} stringtables", counter.load(Ordering::Relaxed));
108+
info!("Checked {} stringtables", length);
113109
Ok(report)
114110
}
115111
}

0 commit comments

Comments
 (0)