ACMX 2.139.0
Dual-Backend Real-Time GPU Video Synthesis
Loading...
Searching...
No Matches
SnapshotThreadPool Class Reference

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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ SnapshotThreadPool()

SnapshotThreadPool::SnapshotThreadPool ( size_t threads)
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.

Parameters
threadsNumber 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.

◆ ~SnapshotThreadPool()

SnapshotThreadPool::~SnapshotThreadPool ( )
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.

Member Function Documentation

◆ enqueue()

template<class F>
void SnapshotThreadPool::enqueue ( F && f)
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.

Template Parameters
FAny callable matching void() (typically a lambda that captures a FrameData by value for PNG writing).
Parameters
fThe 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().

Member Data Documentation

◆ condition

std::condition_variable SnapshotThreadPool::condition
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().

◆ queue_mutex

std::mutex SnapshotThreadPool::queue_mutex
private

Protects tasks and stop.

Definition at line 2034 of file ACMX2/acmx.cpp.

Referenced by enqueue(), SnapshotThreadPool(), and ~SnapshotThreadPool().

◆ stop

bool SnapshotThreadPool::stop = false
private

When true, workers exit after draining the queue.

Definition at line 2036 of file ACMX2/acmx.cpp.

Referenced by enqueue(), SnapshotThreadPool(), and ~SnapshotThreadPool().

◆ tasks

std::queue<std::function<void()> > SnapshotThreadPool::tasks
private

FIFO of pending PNG-write tasks.

Definition at line 2033 of file ACMX2/acmx.cpp.

Referenced by enqueue(), and SnapshotThreadPool().

◆ workers

std::vector<std::thread> SnapshotThreadPool::workers
private

Persistent worker threads.

Definition at line 2032 of file ACMX2/acmx.cpp.

Referenced by SnapshotThreadPool(), and ~SnapshotThreadPool().


The documentation for this class was generated from the following file: