diff options
author | Oliver Reiche <oliver.reiche@huawei.com> | 2021-10-22 15:50:47 +0200 |
---|---|---|
committer | Oliver Reiche <oliver.reiche@huawei.com> | 2022-07-06 18:49:49 +0200 |
commit | 1af5a281460901281104532c9bb398adcf269eb9 (patch) | |
tree | 39aaeeb56a862b5de16776e39ff52e4d286e8c27 /src/buildtool/multithreading/task_system.cpp | |
parent | a71a4b5015327b15fb0bb4fea16c43f21ef0616c (diff) | |
download | justbuild-1af5a281460901281104532c9bb398adcf269eb9.tar.gz |
TaskSystem: Support wait for finish
Diffstat (limited to 'src/buildtool/multithreading/task_system.cpp')
-rw-r--r-- | src/buildtool/multithreading/task_system.cpp | 16 |
1 files changed, 10 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); |