PACS System 0.1.0
PACS DICOM system library
Loading...
Searching...
No Matches
thread_pool_interface.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
21#include <chrono>
22#include <cstddef>
23#include <functional>
24#include <future>
25#include <string>
26#include <thread>
27#include <type_traits>
28
30
31// ─────────────────────────────────────────────────────
32// Shared Types
33// ─────────────────────────────────────────────────────
34
42enum class job_priority {
43 critical = 0,
44 high = 1,
45 normal = 2,
46 low = 3
47};
48
55 std::size_t min_threads = 2;
56
58 std::size_t max_threads = std::thread::hardware_concurrency();
59
61 std::chrono::milliseconds idle_timeout{30000};
62
65
67 std::string pool_name = "pacs_thread_pool";
68};
69
113public:
115 virtual ~thread_pool_interface() = default;
116
117 // =========================================================================
118 // Lifecycle Management
119 // =========================================================================
120
129 [[nodiscard]] virtual auto start() -> bool = 0;
130
136 [[nodiscard]] virtual auto is_running() const noexcept -> bool = 0;
137
145 virtual void shutdown(bool wait_for_completion = true) = 0;
146
147 // =========================================================================
148 // Task Submission
149 // =========================================================================
150
162 [[nodiscard]] virtual auto submit(std::function<void()> task)
163 -> std::future<void> = 0;
164
176 [[nodiscard]] virtual auto submit_with_priority(
177 job_priority priority,
178 std::function<void()> task) -> std::future<void> = 0;
179
188 virtual void submit_fire_and_forget(std::function<void()> task) = 0;
189
190 // =========================================================================
191 // Statistics
192 // =========================================================================
193
199 [[nodiscard]] virtual auto get_thread_count() const -> std::size_t = 0;
200
206 [[nodiscard]] virtual auto get_pending_task_count() const -> std::size_t = 0;
207
213 [[nodiscard]] virtual auto get_idle_worker_count() const -> std::size_t = 0;
214
215protected:
218
221 thread_pool_interface& operator=(const thread_pool_interface&) = delete;
222
226};
227
228} // namespace kcenon::pacs::integration
virtual auto get_idle_worker_count() const -> std::size_t=0
Get the number of idle workers.
virtual void shutdown(bool wait_for_completion=true)=0
Shutdown the thread pool.
virtual void submit_fire_and_forget(std::function< void()> task)=0
Submit a task without waiting for completion.
virtual auto start() -> bool=0
Start the thread pool.
virtual auto get_thread_count() const -> std::size_t=0
Get the current number of worker threads.
virtual auto get_pending_task_count() const -> std::size_t=0
Get the number of pending tasks in the queue.
virtual auto submit_with_priority(job_priority priority, std::function< void()> task) -> std::future< void >=0
Submit a task with a specific priority level.
virtual auto is_running() const noexcept -> bool=0
Check if the thread pool is running.
virtual auto submit(std::function< void()> task) -> std::future< void >=0
Submit a task for execution.
virtual ~thread_pool_interface()=default
Virtual destructor for proper polymorphic destruction.
job_priority
Priority levels for job scheduling.
@ low
Background tasks (cleanup, maintenance)
@ critical
C-ECHO, association handling - highest priority.
Configuration options for the thread pool.
std::string pool_name
Thread pool name for logging.
bool use_lock_free_queue
Enable lock-free queue for higher throughput.
std::chrono::milliseconds idle_timeout
Time before idle threads are terminated (for dynamic scaling)
std::size_t min_threads
Minimum number of worker threads.
std::size_t max_threads
Maximum number of worker threads.