Skip to content

Commit

Permalink
Address review comments.
Browse files Browse the repository at this point in the history
Co-authored-by: waffle <waffle.lapkin@gmail.com>
  • Loading branch information
m-ou-se and WaffleLapkin committed Nov 19, 2024
1 parent 79bffa9 commit c02090d
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions std/src/thread/spawnhook.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::cell::Cell;
use crate::iter;
use crate::sync::Arc;
use crate::thread::Thread;

Expand Down Expand Up @@ -91,9 +92,10 @@ where
{
SPAWN_HOOKS.with(|h| {
let mut hooks = h.take();
let next = hooks.first.take();
hooks.first = Some(Arc::new(SpawnHook {
hook: Box::new(move |thread| Box::new(hook(thread))),
next: hooks.first.take(),
next,
}));
h.set(hooks);
});
Expand All @@ -113,12 +115,9 @@ pub(super) fn run_spawn_hooks(thread: &Thread) -> ChildSpawnHooks {
snapshot
});
// Iterate over the hooks, run them, and collect the results in a vector.
let mut next: &Option<Arc<SpawnHook>> = &hooks.first;
let mut to_run = Vec::new();
while let Some(hook) = next {
to_run.push((hook.hook)(thread));
next = &hook.next;
}
let to_run: Vec<_> = iter::successors(hooks.first.as_deref(), |hook| hook.next.as_deref())
.map(|hook| (hook.hook)(thread))
.collect();
// Pass on the snapshot of the hooks and the results to the new thread,
// which will then run SpawnHookResults::run().
ChildSpawnHooks { hooks, to_run }
Expand Down

0 comments on commit c02090d

Please sign in to comment.