Nilorea Library
C utilities for networking, threading, graphics
n_thread_pool.h File Reference

Thread pool declaration. More...

#include "n_list.h"
#include <pthread.h>
#include <semaphore.h>
+ Include dependency graph for n_thread_pool.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  THREAD_POOL
 Structure of a trhead pool. More...
 
struct  THREAD_POOL_NODE
 A thread pool node. More...
 
struct  THREAD_WAITING_PROC
 Structure of a waiting process item. More...
 

Macros

#define DIRECT_PROC   2
 processing mode for added func, direct start More...
 
#define EXITED_THREAD   256
 indicate that the pool is off, all jobs have been consumed More...
 
#define EXITING_THREAD   128
 indicate that the pool is exiting, unfinished jobs will finish and the pool will exit the threads and enter the EXITED state More...
 
#define IDLE_PROC   8
 status of a thread which is waiting for some proc More...
 
#define NO_LOCK   512
 if passed to add_threaded_process, skip main table lock in case we are in a func which is already locking it More...
 
#define NOQUEUE   4
 processing mode for waiting_list: do not readd the work in queue More...
 
#define RUNNING_PROC   32
 status of a thread which proc is currently running More...
 
#define RUNNING_THREAD   64
 indicate that the pool is running and ready to use More...
 
#define SYNCED_PROC   1
 processing mode for added func, synced start More...
 
#define WAITING_PROC   16
 status of a thread who have proc waiting to be processed
More...
 

Functions

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 More...
 
int destroy_threaded_pool (THREAD_POOL **thread_pool, int delay)
 delete a thread_pool, exit the threads and free the structs More...
 
int get_nb_cpu_cores ()
 get number of core of current system More...
 
THREAD_POOLnew_thread_pool (int nbmaxthr, int nb_max_waiting)
 Create a new pool of nbmaxthr threads. More...
 
int refresh_thread_pool (THREAD_POOL *thread_pool)
 try to add some waiting DIRECT_PROCs on some free thread slots, else do nothing More...
 
int start_threaded_pool (THREAD_POOL *thread_pool)
 Launch the process waiting for exectution in the thread pool. More...
 
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 More...
 
int wait_for_threaded_pool (THREAD_POOL *thread_pool, int delay)
 Wait for all the launched process in the thread pool to terminate. More...
 

Detailed Description

Thread pool declaration.

Author
Castagnier Mickael
Version
1.0
Date
30/04/2014

Definition in file n_thread_pool.h.