diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/buildtool/multithreading/task_system.cpp | 16 | ||||
-rw-r--r-- | src/buildtool/multithreading/task_system.hpp | 3 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/buildtool/multithreading/task_system.cpp b/src/buildtool/multithreading/task_system.cpp index 4af57d0d..ee5be910 100644 --- a/src/buildtool/multithreading/task_system.cpp +++ b/src/buildtool/multithreading/task_system.cpp @@ -17,12 +17,7 @@ TaskSystem::TaskSystem(std::size_t number_of_threads) } TaskSystem::~TaskSystem() { - // When starting a new task system all spawned threads will immediately go - // to sleep and wait for tasks. Even after adding some tasks, it can take a - // while until the first thread wakes up. Therefore, we need to wait for the - // total workload (number of active threads _and_ total number of queued - // tasks) to become zero. - total_workload_.WaitForZero(); + Finish(); for (auto& q : queues_) { q.done(); } @@ -31,6 +26,15 @@ TaskSystem::~TaskSystem() { } } +void TaskSystem::Finish() noexcept { + // When starting a new task system all spawned threads will immediately go + // to sleep and wait for tasks. Even after adding some tasks, it can take a + // while until the first thread wakes up. Therefore, we need to wait for the + // total workload (number of active threads _and_ total number of queued + // tasks) to become zero. + total_workload_.WaitForZero(); +} + void TaskSystem::Run(std::size_t idx) { gsl_Expects(thread_count_ > 0); diff --git a/src/buildtool/multithreading/task_system.hpp b/src/buildtool/multithreading/task_system.hpp index 6387988a..888ba090 100644 --- a/src/buildtool/multithreading/task_system.hpp +++ b/src/buildtool/multithreading/task_system.hpp @@ -48,6 +48,9 @@ class TaskSystem { return thread_count_; } + // Wait for all queues to become empty _and_ all tasks to finish. + void Finish() noexcept; + private: std::size_t const thread_count_{ std::max(1U, std::thread::hardware_concurrency())}; |