Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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__"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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<T>).
template <class T>
class WorkerThread final
class ThreadPool final
{
using Queue = MPMCConcurrentQueue<std::optional<T>, static_cast<std::size_t>(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> queue, uint32_t num_threads, IComponentController& component_controller)
ThreadPool(std::shared_ptr<Queue> 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<void>(i);
worker_threads_.emplace_back(std::make_unique<std::thread>(&WorkerThread::run, this));
worker_threads_.emplace_back(std::make_unique<std::thread>(&ThreadPool::run, this));
}
}

/// @brief Destructor.
/// Requests stop and joins all worker threads.
~WorkerThread()
~ThreadPool()
{
stop();
for (auto& thread : worker_threads_)
Expand All @@ -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().
Expand Down Expand Up @@ -117,4 +117,4 @@ class WorkerThread final

} // namespace score::mw::lifecycle::internal

#endif // WORKER_THREAD_HPP_INCLUDED
#endif // THREAD_POOL_HPP_INCLUDED
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_(),
Expand Down Expand Up @@ -155,7 +155,7 @@ void ProcessGroupManager::deinitialize()
configuration_.deinitialize();
process_groups_.clear();

worker_threads_.reset();
thread_pool_.reset();
worker_jobs_.reset();
process_map_.reset();
}
Expand Down Expand Up @@ -289,7 +289,7 @@ void ProcessGroupManager::createProcessComponentsObjects(std::size_t total_proce
worker_jobs_ = std::make_shared<WorkerQueue>();

LM_LOG_DEBUG() << "Creating worker threads...";
worker_threads_ = std::make_unique<WorkerThread<ComponentTask>>(
thread_pool_ = std::make_unique<ThreadPool<ComponentTask>>(
worker_jobs_, static_cast<uint32_t>(ProcessLimits::kNumWorkerThreads), *process_monitor_);
}

Expand Down Expand Up @@ -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_)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <memory>

#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"
Expand Down Expand Up @@ -287,7 +287,7 @@ class ProcessGroupManager final : public ITransitionResultPublisher
std::shared_ptr<SafeProcessMap> process_map_;

/// @brief Unique pointer to the worker threads handling ProcessInfoNode jobs.
std::unique_ptr<WorkerThread<ComponentTask>> worker_threads_;
std::unique_ptr<ThreadPool<ComponentTask>> thread_pool_;

/// @brief Shared pointer to the job queue for ProcessInfoNode jobs.
std::shared_ptr<WorkerQueue> worker_jobs_;
Expand Down
Loading