carb::tasking::IThreadPool
Defined in carb/tasking/IThreadPool.h
-
struct IThreadPool
Optional plugin providing helpful facilities for utilizing a pool of threads to perform basic small tasks.
Note
Prefer using ThreadPoolWrapper.
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.
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.
- Param workerCount
Required number of worker threads.
- Return
A newly created thread pool.
-
void (*destroy)(ThreadPool *threadPool)
Destroys previously created thread pool.
- Param threadPool
Previously created thread pool.
-
size_t (*getDefaultWorkerCount)()
Returns default number of workers used for creation of a new thread pool.
- Return
The default number of workers.
-
size_t (*getWorkerCount)(ThreadPool *threadPool)
Returns the number of worker threads in the thread pool.
- Param threadPool
ThreadPool previously created with create().
- Return
The number of worker threads.
-
bool (*enqueueJob)(ThreadPool *threadPool, JobFn jobFunction, void *jobData)
Adds a new task to be executed by the thread pool.
- Param threadPool
Thread pool for execution of the job.
- Param jobFunction
User provided function to be executed by a worker.
- Param jobData
User provided data for the job, the memory must not be released until it no longer needed by the task.
- Return
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.
- Param threadPool
Thread pool to be inspected.
- Return
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 queued jobs.
- Param threadPool
Thread pool to wait on.
Public Static Functions
-
static inline constexpr carb::InterfaceDesc getInterfaceDesc() noexcept
Returns information about this interface.
Auto-generated by CARB_PLUGIN_INTERFACE() or CARB_PLUGIN_INTERFACE_EX.
- Returns
The carb::InterfaceDesc struct with information about this interface.
-
static inline constexpr carb::InterfaceDesc getLatestInterfaceDesc() noexcept
Returns information about the latest version of this interface.
Auto-generated by CARB_PLUGIN_INTERFACE() or CARB_PLUGIN_INTERFACE_EX.
- Returns
The carb::InterfaceDesc struct with information about the latest version of this interface.
-
inline ThreadPool *create() const