carb::tasking::IThreadPool

Defined in carb/tasking/IThreadPool.h

struct carb::tasking::IThreadPool

Optional plugin providing helpful facilities for utilizing a pool of threads to perform basic small tasks.

Warning

It is not recommended to use IThreadPool in conjunction with ITasking; the latter is a much richer feature set and generally preferred over IThreadPool. IThreadPool is a simple thread pool with the ability to run individual tasks.

Warning

If multiple ThreadPool objects are used, caution must be taken to not overburden the system with too many threads.

Note

Prefer using ThreadPoolWrapper.

Public Functions

inline ThreadPool *create() const

Creates a new thread pool where the number of worker equals to a value returned by the “getDefaultWorkerCount” function.

Returns

A newly created thread pool.

Public Members

ThreadPool *(*createEx)(size_t workerCount)

Creates a new thread pool where the number of worker equals to the number specified by the user.

Parameters

workerCount – Required number of worker threads.

Returns

A newly created thread pool.

void (*destroy)(ThreadPool *threadPool)

Destroys previously created thread pool.

Parameters

threadPool – Previously created thread pool.

size_t (*getDefaultWorkerCount)()

Returns default number of workers used for creation of a new thread pool.

Returns

The default number of workers.

size_t (*getWorkerCount)(ThreadPool *threadPool)

Returns the number of worker threads in the threaad pool.

Parameters

threadPoolThreadPool previously created with create().

Returns

The number of worker threads.

bool (*enqueueJob)(ThreadPool *threadPool, JobFn jobFunction, void *jobData)

Adds a new task to be executed by the thread pool.

Parameters
  • threadPool – Thread pool for execution of the job.

  • jobFunction – User provided function to be executed by a worker.

  • jobData – User provided data for the job, the memory must not be released until it no longer needed by the task.

Returns

Returns true if the task was successfully added into the thread pool.

size_t (*getCurrentlyRunningJobCount)(ThreadPool *threadPool)

Returns the number of currently executed tasks in the thread pool.

Parameters

threadPool – Thread pool to be inspected.

Returns

The number of currently executed tasks in the thread pool.

void (*waitUntilFinished)(ThreadPool *threadPool)

Blocks execution of the current thread until the thread pool finishes all enqueued jobs.

Parameters

threadPool – Thread pool to wait on.

Public Static Functions

static inline carb::InterfaceDesc getInterfaceDesc()

Returns

The carb::InterfaceDesc struct with information about this interface.