Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: registry: Factor out "wait till out of work" part of the main loop. #1087

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 15 additions & 8 deletions rayon-core/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,20 @@ impl WorkerThread {
mem::forget(abort_guard); // successful execution, do not abort
}

unsafe fn wait_until_out_of_work(&self) {
debug_assert_eq!(self as *const _, WorkerThread::current());
let registry = &*self.registry;
let index = self.index;

self.wait_until(&registry.thread_infos[index].terminate);

// Should not be any work left in our queue.
debug_assert!(self.take_local_job().is_none());

// Let registry know we are done
Latch::set(&registry.thread_infos[index].stopped);
}

fn find_work(&self) -> Option<JobRef> {
// Try to find some work to do. We give preference first
// to things in our local deque, then in other workers
Expand Down Expand Up @@ -905,14 +919,7 @@ unsafe fn main_loop(thread: ThreadBuilder) {
registry.catch_unwind(|| handler(index));
}

let my_terminate_latch = &registry.thread_infos[index].terminate;
worker_thread.wait_until(my_terminate_latch);

// Should not be any work left in our queue.
debug_assert!(worker_thread.take_local_job().is_none());

// let registry know we are done
Latch::set(&registry.thread_infos[index].stopped);
worker_thread.wait_until_out_of_work();

// Normal termination, do not abort.
mem::forget(abort_guard);
Expand Down