Skip to content

Commit ea0c06d

Browse files
committed
core: registry: Factor out "wait till out of work" part of the main loop.
This was originally done for rayon-rs#1063, in order to reuse this to allow cleaning up the TLS data allocated by use_current_thread. We ended up not using that, but this refactoring seems useful on its own.
1 parent 75524e2 commit ea0c06d

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

rayon-core/src/registry.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,20 @@ impl WorkerThread {
809809
mem::forget(abort_guard); // successful execution, do not abort
810810
}
811811

812+
unsafe fn wait_until_out_of_work(&self) {
813+
debug_assert_eq!(self as *const _, WorkerThread::current());
814+
let registry = &*self.registry;
815+
let index = self.index;
816+
817+
self.wait_until(&registry.thread_infos[index].terminate);
818+
819+
// Should not be any work left in our queue.
820+
debug_assert!(self.take_local_job().is_none());
821+
822+
// Let registry know we are done
823+
Latch::set(&registry.thread_infos[index].stopped);
824+
}
825+
812826
fn find_work(&self) -> Option<JobRef> {
813827
// Try to find some work to do. We give preference first
814828
// to things in our local deque, then in other workers
@@ -905,14 +919,7 @@ unsafe fn main_loop(thread: ThreadBuilder) {
905919
registry.catch_unwind(|| handler(index));
906920
}
907921

908-
let my_terminate_latch = &registry.thread_infos[index].terminate;
909-
worker_thread.wait_until(my_terminate_latch);
910-
911-
// Should not be any work left in our queue.
912-
debug_assert!(worker_thread.take_local_job().is_none());
913-
914-
// let registry know we are done
915-
Latch::set(&registry.thread_infos[index].stopped);
922+
worker_thread.wait_until_out_of_work();
916923

917924
// Normal termination, do not abort.
918925
mem::forget(abort_guard);

0 commit comments

Comments
 (0)