PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
thread_pool_adapter.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2021-2025, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
19#pragma once
20
22
23#include <cstddef>
24#include <memory>
25#include <mutex>
26
27namespace kcenon::thread {
28class thread_pool;
29} // namespace kcenon::thread
30
32
66public:
67 // =========================================================================
68 // Constructors
69 // =========================================================================
70
79 explicit thread_pool_adapter(const thread_pool_config& config);
80
89 explicit thread_pool_adapter(std::shared_ptr<kcenon::thread::thread_pool> pool);
90
96 ~thread_pool_adapter() override;
97
98 // =========================================================================
99 // Non-copyable, Non-movable
100 // =========================================================================
101
106
107 // =========================================================================
108 // Lifecycle Management (from thread_pool_interface)
109 // =========================================================================
110
111 [[nodiscard]] auto start() -> bool override;
112 [[nodiscard]] auto is_running() const noexcept -> bool override;
113 void shutdown(bool wait_for_completion = true) override;
114
115 // =========================================================================
116 // Task Submission (from thread_pool_interface)
117 // =========================================================================
118
119 [[nodiscard]] auto submit(std::function<void()> task)
120 -> std::future<void> override;
121
122 [[nodiscard]] auto submit_with_priority(
123 job_priority priority,
124 std::function<void()> task) -> std::future<void> override;
125
126 void submit_fire_and_forget(std::function<void()> task) override;
127
128 // =========================================================================
129 // Statistics (from thread_pool_interface)
130 // =========================================================================
131
132 [[nodiscard]] auto get_thread_count() const -> std::size_t override;
133 [[nodiscard]] auto get_pending_task_count() const -> std::size_t override;
134 [[nodiscard]] auto get_idle_worker_count() const -> std::size_t override;
135
136 // =========================================================================
137 // Adapter-specific Methods
138 // =========================================================================
139
148 [[nodiscard]] auto get_underlying_pool() const
149 -> std::shared_ptr<kcenon::thread::thread_pool>;
150
156 [[nodiscard]] auto get_config() const noexcept -> const thread_pool_config&;
157
158private:
159 std::shared_ptr<kcenon::thread::thread_pool> pool_;
161 mutable std::mutex mutex_;
162 bool initialized_{false};
163
165 void submit_internal(std::function<void()> task, job_priority priority);
166};
167
168} // namespace kcenon::pacs::integration
Concrete implementation of thread_pool_interface.
void submit_internal(std::function< void()> task, job_priority priority)
Internal task submission with priority.
thread_pool_adapter(const thread_pool_config &config)
Construct adapter with configuration.
auto submit(std::function< void()> task) -> std::future< void > override
Submit a task for execution.
auto get_idle_worker_count() const -> std::size_t override
Get the number of idle workers.
auto get_underlying_pool() const -> std::shared_ptr< kcenon::thread::thread_pool >
Get the underlying thread pool.
auto get_thread_count() const -> std::size_t override
Get the current number of worker threads.
auto get_config() const noexcept -> const thread_pool_config &
Get the current configuration.
auto get_pending_task_count() const -> std::size_t override
Get the number of pending tasks in the queue.
void submit_fire_and_forget(std::function< void()> task) override
Submit a task without waiting for completion.
thread_pool_adapter(const thread_pool_adapter &)=delete
thread_pool_adapter(thread_pool_adapter &&)=delete
thread_pool_adapter & operator=(thread_pool_adapter &&)=delete
auto submit_with_priority(job_priority priority, std::function< void()> task) -> std::future< void > override
Submit a task with a specific priority level.
void shutdown(bool wait_for_completion=true) override
Shutdown the thread pool.
auto start() -> bool override
Start the thread pool.
std::shared_ptr< kcenon::thread::thread_pool > pool_
auto is_running() const noexcept -> bool override
Check if the thread pool is running.
thread_pool_adapter & operator=(const thread_pool_adapter &)=delete
std::shared_mutex mutex
Mutex for thread-safe access.
job_priority
Priority levels for job scheduling.
Configuration options for the thread pool.
Abstract interface for thread pool operations.