Skip to content

Commit

Permalink
Tweak thread startup
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX committed Mar 23, 2023
1 parent 23033f7 commit d70539b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions fuc_engine/src/ops/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,16 @@ mod compat {
let mut buf = [MaybeUninit::<u8>::uninit(); 8192];
let symlink_buf_cache = Cell::new(Vec::new());
for node in &tasks {
let maybe_spawn = || {
if available_parallelism > 0 {
let mut maybe_spawn = || {
if available_parallelism > 0 && !tasks.is_empty() {
available_parallelism -= 1;
threads.push(scope.spawn({
let tasks = tasks.clone();
|| worker_thread(tasks)
}));
}
};
maybe_spawn();

copy_dir(&node, &mut buf, &symlink_buf_cache, maybe_spawn)?;
}
Expand Down Expand Up @@ -249,6 +250,7 @@ mod compat {
t => t,
};
if file_type == FileType::Directory {
maybe_spawn();
messages
.send(TreeNode {
from: concat_cstrs(from, file.file_name()),
Expand All @@ -257,7 +259,6 @@ mod compat {
root_to_inode: Some(root_to_inode),
})
.map_err(|_| Error::Internal)?;
maybe_spawn();
} else {
copy_one_file(
&from_dir,
Expand Down
7 changes: 4 additions & 3 deletions fuc_engine/src/ops/remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,16 @@ mod compat {
{
let mut buf = [MaybeUninit::<u8>::uninit(); 8192];
for message in &tasks {
let maybe_spawn = || {
if available_parallelism > 0 {
let mut maybe_spawn = || {
if available_parallelism > 0 && !tasks.is_empty() {
available_parallelism -= 1;
threads.push(scope.spawn({
let tasks = tasks.clone();
|| worker_thread(tasks)
}));
}
};
maybe_spawn();

match message {
Message::Node(node) => delete_dir(node, &mut buf, maybe_spawn)?,
Expand Down Expand Up @@ -228,14 +229,14 @@ mod compat {
t => t,
};
if file_type == FileType::Directory {
maybe_spawn();
node.messages
.send(Message::Node(TreeNode {
path: concat_cstrs(&node.path, file.file_name()),
_parent: Some(node.clone()),
messages: node.messages.clone(),
}))
.map_err(|_| Error::Internal)?;
maybe_spawn();
} else {
unlinkat(&dir, file.file_name(), AtFlags::empty()).map_io_err(|| {
format!(
Expand Down

0 comments on commit d70539b

Please sign in to comment.