A fixed-size thread pool used for writing PNG snapshots asynchronously. More...
Public Member Functions | |
| template<class F> | |
| void | enqueue (F &&f) |
| Submit a callable for asynchronous execution. | |
| SnapshotThreadPool (size_t threads) | |
| Construct a pool with a fixed number of worker threads. | |
| ~SnapshotThreadPool () | |
| Drain remaining tasks and join all worker threads. | |
Private Attributes | |
| std::condition_variable | condition |
| Signalled when a task is enqueued or pool stops. | |
| std::mutex | queue_mutex |
Protects tasks and stop. | |
| bool | stop = false |
| When true, workers exit after draining the queue. | |
| std::queue< std::function< void()> > | tasks |
| FIFO of pending PNG-write tasks. | |
| std::vector< std::thread > | workers |
| Persistent worker threads. | |
A fixed-size thread pool used for writing PNG snapshots asynchronously.
Tasks (snapshot encode + write) are enqueued and executed by worker threads so the render loop is never blocked by disk I/O.
Definition at line 1958 of file ACMX2/acmx.cpp.
|
inline |
Construct a pool with a fixed number of worker threads.
Each worker runs a loop that waits on the shared condition variable. When a task is pushed into the queue the condition is signalled and exactly one sleeping worker wakes to execute it. Workers remain alive until the destructor sets the stop flag and joins them.
| threads | Number of OS threads to spawn (typically 2). |
Definition at line 1970 of file ACMX2/acmx.cpp.
References condition, queue_mutex, stop, tasks, void(), and workers.
|
inline |
Drain remaining tasks and join all worker threads.
Sets the stop flag under the lock, then broadcasts the condition variable so every sleeping worker wakes and exits. Each thread is joined before the destructor returns, guaranteeing that no background I/O is still in flight.
Definition at line 2021 of file ACMX2/acmx.cpp.
References condition, queue_mutex, stop, and workers.
|
inline |
Submit a callable for asynchronous execution.
The callable is wrapped in a std::function<void()> and pushed onto the shared task queue. One waiting worker is then notified. Throws std::runtime_error if the pool has already been stopped.
| F | Any callable matching void() (typically a lambda that captures a FrameData by value for PNG writing). |
| f | The task to execute on a worker thread. |
Definition at line 2003 of file ACMX2/acmx.cpp.
References condition, queue_mutex, stop, and tasks.
Referenced by ACView::startWriterThread().
|
private |
Signalled when a task is enqueued or pool stops.
Definition at line 2035 of file ACMX2/acmx.cpp.
Referenced by enqueue(), SnapshotThreadPool(), and ~SnapshotThreadPool().
|
private |
Protects tasks and stop.
Definition at line 2034 of file ACMX2/acmx.cpp.
Referenced by enqueue(), SnapshotThreadPool(), and ~SnapshotThreadPool().
|
private |
When true, workers exit after draining the queue.
Definition at line 2036 of file ACMX2/acmx.cpp.
Referenced by enqueue(), SnapshotThreadPool(), and ~SnapshotThreadPool().
|
private |
FIFO of pending PNG-write tasks.
Definition at line 2033 of file ACMX2/acmx.cpp.
Referenced by enqueue(), and SnapshotThreadPool().
|
private |
Persistent worker threads.
Definition at line 2032 of file ACMX2/acmx.cpp.
Referenced by SnapshotThreadPool(), and ~SnapshotThreadPool().