poser
A C framework for POsix SERvices
Loading...
Searching...
No Matches
PSC_ThreadPool Class Reference

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.
 

Detailed Description

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.

Member Function Documentation

◆ PSC_ThreadPool_active()

int PSC_ThreadPool_active ( void  )
static

Check whether thread pool is active.

Returns
1 when thread pool is active, 0 otherwise

◆ PSC_ThreadPool_cancel()

void PSC_ThreadPool_cancel ( PSC_ThreadJob job)
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.

Parameters
jobthe job to cancel

◆ PSC_ThreadPool_done()

void PSC_ThreadPool_done ( void  )
static

Stop the thread pool.

All worker threads are stopped.

◆ PSC_ThreadPool_enqueue()

int PSC_ThreadPool_enqueue ( PSC_ThreadJob job)
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.

Parameters
jobthe job to enqueue/start
Returns
-1 on error (queue overflow), 0 on success

◆ PSC_ThreadPool_init()

int PSC_ThreadPool_init ( void  )
static

Initialize the thread pool.

This launches the worker threads, according to the configuration from PSC_ThreadOpts.

Returns
-1 on error, 0 on success

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