From 6abf5699187329c1ab63a765e92e1c0e12a202d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Fu=C3=9Fberger?= Date: Mon, 17 Aug 2026 16:31:21 +0200 Subject: [PATCH] Rename WorkerThread to ThreadPool --- .../src/daemon/src/common/concurrency/BUILD | 4 ++-- .../{workerthread.hpp => thread_pool.hpp} | 24 +++++++++---------- .../daemon/src/process_group_manager/BUILD | 2 +- .../process_group_manager.cpp | 8 +++---- .../process_group_manager.hpp | 4 ++-- 5 files changed, 21 insertions(+), 21 deletions(-) rename score/launch_manager/src/daemon/src/common/concurrency/{workerthread.hpp => thread_pool.hpp} (86%) diff --git a/score/launch_manager/src/daemon/src/common/concurrency/BUILD b/score/launch_manager/src/daemon/src/common/concurrency/BUILD index 30735211c..4fcc2200a 100644 --- a/score/launch_manager/src/daemon/src/common/concurrency/BUILD +++ b/score/launch_manager/src/daemon/src/common/concurrency/BUILD @@ -14,8 +14,8 @@ load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") load("//tests/utils/bazel:unit_test.bzl", "lm_cc_test") cc_library( - name = "workerthread", - hdrs = ["workerthread.hpp"], + name = "thread_pool", + hdrs = ["thread_pool.hpp"], include_prefix = "score/mw/launch_manager/common/concurrency", strip_include_prefix = "/score/launch_manager/src/daemon/src/common/concurrency", visibility = ["//score:__subpackages__"], diff --git a/score/launch_manager/src/daemon/src/common/concurrency/workerthread.hpp b/score/launch_manager/src/daemon/src/common/concurrency/thread_pool.hpp similarity index 86% rename from score/launch_manager/src/daemon/src/common/concurrency/workerthread.hpp rename to score/launch_manager/src/daemon/src/common/concurrency/thread_pool.hpp index f95584120..1296799ed 100644 --- a/score/launch_manager/src/daemon/src/common/concurrency/workerthread.hpp +++ b/score/launch_manager/src/daemon/src/common/concurrency/thread_pool.hpp @@ -11,8 +11,8 @@ * SPDX-License-Identifier: Apache-2.0 ********************************************************************************/ -#ifndef WORKER_THREAD_HPP_INCLUDED -#define WORKER_THREAD_HPP_INCLUDED +#ifndef THREAD_POOL_HPP_INCLUDED +#define THREAD_POOL_HPP_INCLUDED #include "score/mw/launch_manager/common/concurrency/mpmc_concurrent_queue.hpp" #include "score/mw/launch_manager/common/constants.hpp" @@ -30,30 +30,30 @@ namespace score::mw::lifecycle::internal /// from an MPMCConcurrentQueue until the pool is stopped or destructed. /// @tparam T The type of items stored in the queue (as std::shared_ptr). template -class WorkerThread final +class ThreadPool final { using Queue = MPMCConcurrentQueue, static_cast(ProcessLimits::kMaxProcesses)>; public: - /// @brief Constructs a WorkerThread pool with the specified number of threads. + /// @brief Constructs a ThreadPool with the specified number of threads. /// /// @param queue The MpmcQueue from which threads will take work items. /// @param num_threads Number of threads in the pool. /// @param component_controller_ The controller to delegate work to. - WorkerThread(std::shared_ptr queue, uint32_t num_threads, IComponentController& component_controller) + ThreadPool(std::shared_ptr queue, uint32_t num_threads, IComponentController& component_controller) : the_job_queue_(queue), component_controller_(component_controller) { worker_threads_.reserve(num_threads); for (uint32_t i = 0U; i < num_threads; ++i) { static_cast(i); - worker_threads_.emplace_back(std::make_unique(&WorkerThread::run, this)); + worker_threads_.emplace_back(std::make_unique(&ThreadPool::run, this)); } } /// @brief Destructor. /// Requests stop and joins all worker threads. - ~WorkerThread() + ~ThreadPool() { stop(); for (auto& thread : worker_threads_) @@ -67,16 +67,16 @@ class WorkerThread final // Rule of five /// @brief Copy constructor is deleted to prevent copying. - WorkerThread(const WorkerThread&) = delete; + ThreadPool(const ThreadPool&) = delete; /// @brief Copy assignment operator is deleted to prevent copying. - WorkerThread& operator=(const WorkerThread&) = delete; + ThreadPool& operator=(const ThreadPool&) = delete; /// @brief Move constructor is deleted to prevent moving. - WorkerThread(WorkerThread&&) = delete; + ThreadPool(ThreadPool&&) = delete; /// @brief Move assignment operator is deleted to prevent moving. - WorkerThread& operator=(WorkerThread&&) = delete; + ThreadPool& operator=(ThreadPool&&) = delete; /// @brief Requests all worker threads to stop. /// Calls stop() on the queue, which unblocks all threads waiting in pop(). @@ -117,4 +117,4 @@ class WorkerThread final } // namespace score::mw::lifecycle::internal -#endif // WORKER_THREAD_HPP_INCLUDED +#endif // THREAD_POOL_HPP_INCLUDED diff --git a/score/launch_manager/src/daemon/src/process_group_manager/BUILD b/score/launch_manager/src/daemon/src/process_group_manager/BUILD index dc397f036..d657bf12c 100644 --- a/score/launch_manager/src/daemon/src/process_group_manager/BUILD +++ b/score/launch_manager/src/daemon/src/process_group_manager/BUILD @@ -83,7 +83,7 @@ cc_library( ":iprocess", "//score/launch_manager/src/daemon/src/common:identifier_hash", "//score/launch_manager/src/daemon/src/common/concurrency:mpmc_concurrent_queue", - "//score/launch_manager/src/daemon/src/common/concurrency:workerthread", + "//score/launch_manager/src/daemon/src/common/concurrency:thread_pool", "//score/launch_manager/src/daemon/src/configuration:config", "//score/launch_manager/src/daemon/src/configuration:configuration_adapter", "//score/launch_manager/src/daemon/src/control:control_client_channel", diff --git a/score/launch_manager/src/daemon/src/process_group_manager/process_group_manager.cpp b/score/launch_manager/src/daemon/src/process_group_manager/process_group_manager.cpp index 37fad6ea3..358fa9e11 100644 --- a/score/launch_manager/src/daemon/src/process_group_manager/process_group_manager.cpp +++ b/score/launch_manager/src/daemon/src/process_group_manager/process_group_manager.cpp @@ -44,7 +44,7 @@ ProcessGroupManager::ProcessGroupManager( : configuration_(), process_interface_(), process_map_(nullptr), - worker_threads_(nullptr), + thread_pool_(nullptr), worker_jobs_(nullptr), num_process_groups_(0U), process_groups_(), @@ -155,7 +155,7 @@ void ProcessGroupManager::deinitialize() configuration_.deinitialize(); process_groups_.clear(); - worker_threads_.reset(); + thread_pool_.reset(); worker_jobs_.reset(); process_map_.reset(); } @@ -289,7 +289,7 @@ void ProcessGroupManager::createProcessComponentsObjects(std::size_t total_proce worker_jobs_ = std::make_shared(); LM_LOG_DEBUG() << "Creating worker threads..."; - worker_threads_ = std::make_unique>( + thread_pool_ = std::make_unique>( worker_jobs_, static_cast(ProcessLimits::kNumWorkerThreads), *process_monitor_); } @@ -460,7 +460,7 @@ void ProcessGroupManager::allProcessGroupsOff() if (!waitForStateCompletion(GraphState::kInTransition, 1000)) { LM_LOG_ERROR() << "NOTE: Transition to Off state timed out"; - worker_threads_->stop(); + thread_pool_->stop(); for (auto& pg : process_groups_) { diff --git a/score/launch_manager/src/daemon/src/process_group_manager/process_group_manager.hpp b/score/launch_manager/src/daemon/src/process_group_manager/process_group_manager.hpp index fe077b5c2..fdb998869 100644 --- a/score/launch_manager/src/daemon/src/process_group_manager/process_group_manager.hpp +++ b/score/launch_manager/src/daemon/src/process_group_manager/process_group_manager.hpp @@ -19,7 +19,7 @@ #include #include "score/mw/launch_manager/common/concurrency/mpmc_concurrent_queue.hpp" -#include "score/mw/launch_manager/common/concurrency/workerthread.hpp" +#include "score/mw/launch_manager/common/concurrency/thread_pool.hpp" #include "score/mw/launch_manager/common/constants.hpp" #include "score/mw/launch_manager/common/identifier_hash.hpp" #include "score/mw/launch_manager/configuration/config.hpp" @@ -287,7 +287,7 @@ class ProcessGroupManager final : public ITransitionResultPublisher std::shared_ptr process_map_; /// @brief Unique pointer to the worker threads handling ProcessInfoNode jobs. - std::unique_ptr> worker_threads_; + std::unique_ptr> thread_pool_; /// @brief Shared pointer to the job queue for ProcessInfoNode jobs. std::shared_ptr worker_jobs_;