TinyChatEngine
Loading...
Searching...
No Matches
pthread_pool.h File Reference

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)
 

Detailed Description

This file provides prototypes for an implementation of a pthread pool.

Function Documentation

◆ pool_end()

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.

◆ pool_enqueue()

void pool_enqueue ( void * pool,
void * arg,
char free )

Enqueue a new task for the thread pool.

Parameters
poolA thread pool returned by start_pool.
argThe argument to pass to the thread worker function.
freeIf true, the argument will be freed after the task has completed.

◆ pool_start()

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.

Parameters
thread_funcThe function executed by each thread for each work item.
threadsThe number of threads in the pool.
Returns
A pointer to the thread pool.

◆ pool_wait()

void pool_wait ( void * pool)

Wait for all queued tasks to be completed.