14#ifndef VL_THREAD_POOL_H
15#define VL_THREAD_POOL_H
124 VL_THREAD_POOL_PRIORITY_HIGH = 0,
125 VL_THREAD_POOL_PRIORITY_MEDIUM = 1,
126 VL_THREAD_POOL_PRIORITY_LOW = 2,
127 VL_THREAD_POOL_PRIORITY_COUNT = 3
128} vl_thread_pool_priority;
159typedef struct vl_thread_pool_
162 vl_async_queue* workQueues[VL_THREAD_POOL_PRIORITY_COUNT];
165 vl_semaphore semaphores[VL_THREAD_POOL_PRIORITY_COUNT];
193 vl_uint32_t tasksPending[VL_THREAD_POOL_PRIORITY_COUNT];
440static inline vl_uint32_t vlThreadPoolQueueDepth(
vl_thread_pool* pool)
#define VL_ATOMIC
Definition vl_atomic.h:40
struct vl_mutex_ * vl_mutex
Definition vl_mutex.h:23
VL_UINT_T vl_uint_t
Standard unsigned integer type.
Definition vl_numtypes.h:158
VL_BOOL_T vl_bool_t
Definition vl_numtypes.h:191
VL_ULARGE_T vl_ularge_t
Largest available unsigned integer type.
Definition vl_numtypes.h:136
void * user_data
Definition vl_thread_pool.h:153
vl_uint_t workerCount
Definition vl_thread_pool.h:169
vl_ularge_t tasks_completed
Definition vl_thread_pool.h:192
VL_ATOMIC vl_thread_pool_state state
Definition vl_thread_pool.h:172
VL_API vl_bool_t vlThreadPoolEnqueuePriority(vl_thread_pool *pool, vl_thread_pool_priority priority, const vl_thread_pool_task *task)
Enqueues a single work item at the specified priority level.
Definition vl_thread_pool.c:266
void(* vl_thread_pool_task_proc)(void *user_data)
Function signature for worker thread task procedures.
Definition vl_thread_pool.h:142
vl_thread_pool_task_proc proc
Definition vl_thread_pool.h:152
VL_ATOMIC vl_uint_t active_workers
Definition vl_thread_pool.h:178
VL_API vl_thread_pool * vlThreadPoolNew(vl_uint_t worker_count)
Creates a new priority-aware thread pool with work-stealing.
Definition vl_thread_pool.c:94
VL_API vl_uint_t vlThreadPoolEnqueueBatchPriority(vl_thread_pool *pool, vl_thread_pool_priority priority, const vl_thread_pool_task *tasks, vl_uint_t count)
Enqueues multiple work items at the same priority level in a batch.
Definition vl_thread_pool.c:290
vl_uint_t worker_count
Definition vl_thread_pool.h:194
VL_API void vlThreadPoolGetStats(vl_thread_pool *pool, vl_thread_pool_stats *out_stats)
Retrieves a snapshot of current thread pool statistics.
Definition vl_thread_pool.c:401
vl_mutex idle_lock
Definition vl_thread_pool.h:177
VL_API void vlThreadPoolDelete(vl_thread_pool *pool)
Deletes a thread pool and frees all associated resources.
Definition vl_thread_pool.c:231
VL_ATOMIC vl_ularge_t tasksCompleted
Definition vl_thread_pool.h:173
vl_thread * workers
Definition vl_thread_pool.h:168
VL_API vl_bool_t vlThreadPoolWait(vl_thread_pool *pool, vl_uint_t timeout_ms)
Waits until all enqueued tasks across all priority tiers have completed.
Definition vl_thread_pool.c:318
VL_API void vlThreadPoolShutdown(vl_thread_pool *pool)
Initiates graceful shutdown of the thread pool.
Definition vl_thread_pool.c:375
vl_thread_pool_state
Definition vl_thread_pool.h:131
@ VL_THREAD_POOL_SHUTTING_DOWN
Definition vl_thread_pool.h:133
@ VL_THREAD_POOL_RUNNING
Definition vl_thread_pool.h:132
@ VL_THREAD_POOL_SHUT_DOWN
Definition vl_thread_pool.h:134
vl_uint32_t tasksPending[VL_THREAD_POOL_PRIORITY_COUNT]
Definition vl_thread_pool.h:193
vl_condition all_idle
Definition vl_thread_pool.h:176
Opaque thread pool handle.
Definition vl_thread_pool.h:160
Statistics snapshot from a thread pool.
Definition vl_thread_pool.h:191
A single work item for the thread pool.
Definition vl_thread_pool.h:151