-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit replaces the `threadpool` crate with a handcrafted solution based on scoped threads. This leaves `valgrind` much happier than before. We also lose some dependency baggage.
- Loading branch information
Showing
4 changed files
with
64 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name = "libtest-mimic" | |
version = "0.7.3" | ||
authors = ["Lukas Kalbertodt <[email protected]>"] | ||
edition = "2021" | ||
rust-version = "1.60" | ||
rust-version = "1.63" | ||
|
||
description = """ | ||
Write your own test harness that looks and behaves like the built-in test \ | ||
|
@@ -20,7 +20,6 @@ exclude = [".github"] | |
|
||
[dependencies] | ||
clap = { version = "4.0.8", features = ["derive"] } | ||
threadpool = "1.8.1" | ||
termcolor = "1.0.5" | ||
escape8259 = "0.5.2" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use std::{sync, thread}; | ||
|
||
pub(crate) type Task = dyn FnOnce() + Send; | ||
pub(crate) type BoxedTask = Box<Task>; | ||
|
||
pub(crate) fn scoped_run_tasks( | ||
tasks: Vec<BoxedTask>, | ||
num_threads: usize, | ||
) { | ||
if num_threads < 2 { | ||
// There is another code path for num_threads == 1 running entirely in the main thread. | ||
panic!("`run_on_scoped_pool` may not be called with `num_threads` less than 2"); | ||
} | ||
|
||
let sync_iter = sync::Mutex::new(tasks.into_iter()); | ||
let next_task = || sync_iter.lock().unwrap().next(); | ||
|
||
thread::scope(|scope| { | ||
for _ in 0..num_threads { | ||
scope.spawn(|| { | ||
while let Some(task) = next_task() { | ||
task(); | ||
} | ||
}); | ||
} | ||
}); | ||
} |