8#ifndef NILOREA_THREAD_POOL_LIBRARY
9#define NILOREA_THREAD_POOL_LIBRARY
35#define WAITING_PROC 16
37#define RUNNING_PROC 32
39#define RUNNING_THREAD 64
41#define EXITING_THREAD 128
43#define EXITED_THREAD 256
Structure of a generic LIST container.
int state
state of the proc , RUNNING_PROC when it is busy processing func( param) , IDLE_PROC when it waits fo...
int nb_actives
number of threads actually doing a proc
int type
SYNCED or DIRECT process start.
void * param
if not NULL , passed as argument
sem_t th_end
thread ending semaphore
pthread_mutex_t lock
mutex to prevent mutual access of node parameters
struct THREAD_POOL * thread_pool
pointer to assigned thread pool
sem_t th_start
thread starting semaphore
THREAD_POOL_NODE ** thread_list
Dynamically allocated but fixed size thread array.
LIST * waiting_list
Waiting list handling.
sem_t nb_tasks
semaphore to store the number of tasks
int nb_max_waiting
Maximum number of waiting procedures int the list, 0 or -1 for unlimited.
int thread_state
state of the managing thread , RUNNING_THREAD, EXITING_THREAD, EXITED_THREAD
int max_threads
Maximum number of running threads in the list.
pthread_mutex_t lock
mutex to prevent mutual access of waiting_list parameters
void * param
if not NULL , passed as argument
int start_threaded_pool(THREAD_POOL *thread_pool)
Launch the process waiting for exectution in the thread pool.
int get_nb_cpu_cores()
get number of core of current system
int destroy_threaded_pool(THREAD_POOL **thread_pool, int delay)
delete a thread_pool, exit the threads and free the structs
int add_threaded_process(THREAD_POOL *thread_pool, void *(*func_ptr)(void *param), void *param, int mode)
add a function and params to a thread pool
int refresh_thread_pool(THREAD_POOL *thread_pool)
try to add some waiting DIRECT_PROCs on some free thread slots, else do nothing
int wait_for_synced_threaded_pool(THREAD_POOL *thread_pool)
wait for all the launched process, blocking but light on the CPU as there is no polling
int wait_for_threaded_pool(THREAD_POOL *thread_pool, int delay)
Wait for all the launched process in the thread pool to terminate.
THREAD_POOL * new_thread_pool(int nbmaxthr, int nb_max_waiting)
Create a new pool of nbmaxthr threads.
Structure of a trhead pool.
Structure of a waiting process item.
List structures and definitions.