TinyChatEngine
|
Go to the source code of this file.
Functions | |
void * | pool_start (void *(*thread_func)(void *), unsigned int threads) |
void | pool_enqueue (void *pool, void *arg, char free) |
void | pool_wait (void *pool) |
void | pool_end (void *pool) |
This file provides prototypes for an implementation of a pthread pool.
void pool_end | ( | void * | pool | ) |
Stop all threads in the pool.
Note that this function will block until all threads have terminated. All queued items will also be freed, along with the pool itself. Remaining work item arguments will be freed depending on the free argument to pool_enqueue.
void pool_enqueue | ( | void * | pool, |
void * | arg, | ||
char | free ) |
Enqueue a new task for the thread pool.
pool | A thread pool returned by start_pool. |
arg | The argument to pass to the thread worker function. |
free | If true, the argument will be freed after the task has completed. |
void * pool_start | ( | void *(* | thread_func )(void *), |
unsigned int | threads ) |
Create a new thread pool.
New tasks should be enqueued with pool_enqueue. thread_func will be called once per queued task with its sole argument being the argument given to pool_enqueue.
thread_func | The function executed by each thread for each work item. |
threads | The number of threads in the pool. |
void pool_wait | ( | void * | pool | ) |
Wait for all queued tasks to be completed.