summaryrefslogtreecommitdiff
path: root/src/buildtool/multithreading/task_system.cpp
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2021-10-22 15:50:47 +0200
committerOliver Reiche <oliver.reiche@huawei.com>2022-07-06 18:49:49 +0200
commit1af5a281460901281104532c9bb398adcf269eb9 (patch)
tree39aaeeb56a862b5de16776e39ff52e4d286e8c27 /src/buildtool/multithreading/task_system.cpp
parenta71a4b5015327b15fb0bb4fea16c43f21ef0616c (diff)
downloadjustbuild-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.cpp16
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);