15#include <shared_mutex>
21#include "ThreadData.hpp"
22#include <dfx-runtime-api/Task.hpp>
23#include <dfx-utilities/sync-queues/PriorityStableQueue.hpp>
92 std::size_t
threadCount() const noexcept { std::lock_guard lock(_mutexThreads);
return _threads.size(); }
109 requires std::is_constructible_v<T, Args...>
111 {
pushTask(std::make_unique<T>(std::forward<Args>(args)...)); }
132 void _work(std::stop_token stopToken);
140 std::list<ThreadData> _threadDatas;
141 mutable std::shared_mutex _mutexThreadData;
144 mutable std::mutex _mutexThreads;
146 std::vector<std::jthread> _threads;
void emplaceTask(Args &&... args)
Construct a task in-place and submit it.
Definition ThreadPool.hpp:110
std::size_t threadCount() const noexcept
Current number of worker threads.
Definition ThreadPool.hpp:92
MaybeThreadData threadData()
Retrieve the calling thread's ThreadData if it belongs to this pool.
std::optional< std::reference_wrapper< ThreadData > > MaybeThreadData
Optional reference to mutable thread data.
Definition ThreadPool.hpp:115
std::optional< std::reference_wrapper< ThreadData const > > MaybeCThreadData
Optional reference to immutable thread data.
Definition ThreadPool.hpp:117
MaybeCThreadData threadData() const
Retrieve the calling thread's ThreadData if it belongs to this pool.
void addThread(std::size_t count=1)
Add worker threads to the pool.
void pushTask(Api::TaskPtr task)
Submit a task for execution.
~ThreadPool()
Stop all worker threads and abandon remaining tasks.
ThreadPool(std::size_t threadCount=1)
Construct a thread pool with an initial number of worker threads.
void pushTasks(std::span< Api::TaskPtr > tasks)
Submit multiple tasks for execution.
void removeThread(std::size_t count=1)
Remove worker threads from the pool.
A thread-safe, priority-based queue that maintains insertion order for equal priorities.
Definition PriorityStableQueue.hpp:50
Convenience concept for constraining templates to Task-derived types.
Definition Task.hpp:24
std::unique_ptr< Task > TaskPtr
Unique ownership pointer for tasks.
Definition Task.hpp:102