poser
A C framework for POsix SERvices
|
A thread pool. More...
#include <poser/core/threadpool.h>
Static Public Member Functions | |
int | PSC_ThreadPool_init (void) |
Initialize the thread pool. | |
int | PSC_ThreadPool_active (void) |
Check whether thread pool is active. | |
int | PSC_ThreadPool_enqueue (PSC_ThreadJob *job) |
Enqueue a thread job. | |
void | PSC_ThreadPool_cancel (PSC_ThreadJob *job) |
Cancel a thread job. | |
void | PSC_ThreadPool_done (void) |
Stop the thread pool. | |
A thread pool.
This class creates a fixed set of worker threads and a queue of PSC_ThreadJob objects for jobs to be executed on a worker thread. An event will be fired when a job completes. Running jobs can also be canceled.
|
static |
Check whether thread pool is active.
|
static |
Cancel a thread job.
If the job is already running, it is sent an interrupting signal and have a flag set that can be checked with PSC_ThreadJob_canceled(). If it is still waiting in the queue, it is just removed and destroyed. In any case, its finished event will fire.
job | the job to cancel |
|
static |
Stop the thread pool.
All worker threads are stopped.
|
static |
Enqueue a thread job.
If a worker thread is available, the job is started on it directly, otherwise it is put in the queue of waiting jobs.
Note this takes ownership of the PSC_ThreadJob object.
job | the job to enqueue/start |
|
static |
Initialize the thread pool.
This launches the worker threads, according to the configuration from PSC_ThreadOpts.