|
Lightweight 0.20260617.0
|
#include <ThreadPoolExecutor.hpp>
Public Member Functions | |
| ThreadPoolExecutor (std::size_t threadCount) | |
| ThreadPoolExecutor (ThreadPoolExecutor const &)=delete | |
| ThreadPoolExecutor & | operator= (ThreadPoolExecutor const &)=delete |
| ThreadPoolExecutor (ThreadPoolExecutor &&)=delete | |
| ThreadPoolExecutor & | operator= (ThreadPoolExecutor &&)=delete |
| ~ThreadPoolExecutor () override | |
| void | Post (Work work) override |
| void | Resume (std::coroutine_handle<> handle) override |
| std::size_t | ThreadCount () const noexcept |
Public Member Functions inherited from Lightweight::Async::IExecutor | |
| IExecutor (IExecutor const &)=delete | |
| IExecutor & | operator= (IExecutor const &)=delete |
| IExecutor (IExecutor &&)=delete | |
| IExecutor & | operator= (IExecutor &&)=delete |
Public Member Functions inherited from Lightweight::Async::IResumeScheduler | |
| IResumeScheduler (IResumeScheduler const &)=delete | |
| IResumeScheduler & | operator= (IResumeScheduler const &)=delete |
| IResumeScheduler (IResumeScheduler &&)=delete | |
| IResumeScheduler & | operator= (IResumeScheduler &&)=delete |
A fixed-size pool of worker threads that run posted work concurrently.
This is the default "DB worker" offload target: blocking ODBC calls are posted here and executed on a worker thread while the awaiting coroutine is suspended. The pool is built on stdexec's exec::static_thread_pool (the C++26 std::execution scheduler model); each posted Work item is spawned as a schedule|then sender into an exec::async_scope so the destructor can wait for every in-flight item to finish, draining and joining. The pool must therefore outlive every coroutine that can resume on it.
The stdexec machinery lives in a pimpl defined in the translation unit, so this public header pulls in no stdexec headers — keeping them out of the C++20 module's global module fragment and off every downstream consumer that does not opt in.
Definition at line 25 of file ThreadPoolExecutor.hpp.
|
explicit |
Constructs the pool and starts threadCount worker threads.
| threadCount | Number of worker threads to start (must be >= 1). |
| std::invalid_argument | if threadCount is 0 or exceeds the supported maximum (std::uint32_t, the width the underlying stdexec pool accepts). |
|
override |
Waits for all in-flight work to drain, then stops and joins the worker threads.
|
overridevirtual |
Schedules work to run on the executor. Thread-safe.
| work | The work item to enqueue (consumed). |
Implements Lightweight::Async::IExecutor.
|
overridevirtual |
Schedules handle to be resumed. Thread-safe.
| handle | The coroutine to resume. |
Implements Lightweight::Async::IResumeScheduler.
|
inlinenoexcept |
Definition at line 54 of file ThreadPoolExecutor.hpp.