Nilorea Library
C utilities for networking, threading, graphics
|
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_POOL * | new_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... | |
struct THREAD_POOL |
Structure of a trhead pool.
Definition at line 80 of file n_thread_pool.h.
Data Fields | ||
---|---|---|
pthread_mutex_t | lock | mutex to prevent mutual access of waiting_list parameters |
int | max_threads | Maximum number of running threads in the list. |
int | nb_actives | number of threads actually doing a proc |
int | nb_max_waiting | Maximum number of waiting procedures int the list, 0 or -1 for unlimited. |
sem_t | nb_tasks | semaphore to store the number of tasks |
THREAD_POOL_NODE ** | thread_list | Dynamically allocated but fixed size thread array. |
LIST * | waiting_list | Waiting list handling. |
struct THREAD_POOL_NODE |
A thread pool node.
Definition at line 48 of file n_thread_pool.h.
Data Fields | |
void *(* | func )(void *param) |
function to call in the thread More... | |
pthread_mutex_t | lock |
mutex to prevent mutual access of node parameters More... | |
void * | param |
if not NULL , passed as argument More... | |
int | state |
state of the proc , RUNNING_PROC when it is busy processing func( param) , IDLE_PROC when it waits for some func and param to process , WAITING_PROC when it has things waiting to be processed More... | |
sem_t | th_end |
thread ending semaphore More... | |
sem_t | th_start |
thread starting semaphore More... | |
pthread_t | thr |
thread id More... | |
struct THREAD_POOL * | thread_pool |
pointer to assigned thread pool More... | |
int | thread_state |
state of the managing thread , RUNNING_THREAD, EXITING_THREAD, EXITED_THREAD More... | |
int | type |
SYNCED or DIRECT process start. More... | |
void *(* THREAD_POOL_NODE::func) (void *param) |
function to call in the thread
Definition at line 51 of file n_thread_pool.h.
pthread_mutex_t THREAD_POOL_NODE::lock |
mutex to prevent mutual access of node parameters
Definition at line 71 of file n_thread_pool.h.
void* THREAD_POOL_NODE::param |
if not NULL , passed as argument
Definition at line 54 of file n_thread_pool.h.
int THREAD_POOL_NODE::state |
state of the proc , RUNNING_PROC when it is busy processing func( param) , IDLE_PROC when it waits for some func and param to process , WAITING_PROC when it has things waiting to be processed
Definition at line 59 of file n_thread_pool.h.
sem_t THREAD_POOL_NODE::th_end |
thread ending semaphore
Definition at line 68 of file n_thread_pool.h.
sem_t THREAD_POOL_NODE::th_start |
thread starting semaphore
Definition at line 66 of file n_thread_pool.h.
pthread_t THREAD_POOL_NODE::thr |
thread id
Definition at line 63 of file n_thread_pool.h.
struct THREAD_POOL* THREAD_POOL_NODE::thread_pool |
pointer to assigned thread pool
Definition at line 74 of file n_thread_pool.h.
int THREAD_POOL_NODE::thread_state |
state of the managing thread , RUNNING_THREAD, EXITING_THREAD, EXITED_THREAD
Definition at line 61 of file n_thread_pool.h.
int THREAD_POOL_NODE::type |
SYNCED or DIRECT process start.
Definition at line 57 of file n_thread_pool.h.
struct THREAD_WAITING_PROC |
Structure of a waiting process item.
Definition at line 106 of file n_thread_pool.h.
Data Fields | |
void *(* | func )(void *param) |
function to call in the thread More... | |
void * | param |
if not NULL , passed as argument More... | |
void *(* THREAD_WAITING_PROC::func) (void *param) |
function to call in the thread
Definition at line 109 of file n_thread_pool.h.
void* THREAD_WAITING_PROC::param |
if not NULL , passed as argument
Definition at line 111 of file n_thread_pool.h.
#define DIRECT_PROC 2 |
processing mode for added func, direct start
Definition at line 29 of file n_thread_pool.h.
#define EXITED_THREAD 256 |
indicate that the pool is off, all jobs have been consumed
Definition at line 43 of file n_thread_pool.h.
#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
Definition at line 41 of file n_thread_pool.h.
#define IDLE_PROC 8 |
status of a thread which is waiting for some proc
Definition at line 33 of file n_thread_pool.h.
#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
Definition at line 45 of file n_thread_pool.h.
#define NOQUEUE 4 |
processing mode for waiting_list: do not readd the work in queue
Definition at line 31 of file n_thread_pool.h.
#define RUNNING_PROC 32 |
status of a thread which proc is currently running
Definition at line 37 of file n_thread_pool.h.
#define RUNNING_THREAD 64 |
indicate that the pool is running and ready to use
Definition at line 39 of file n_thread_pool.h.
#define SYNCED_PROC 1 |
processing mode for added func, synced start
Definition at line 27 of file n_thread_pool.h.
#define WAITING_PROC 16 |
status of a thread who have proc waiting to be processed
Definition at line 35 of file n_thread_pool.h.
int add_threaded_process | ( | THREAD_POOL * | thread_pool, |
void *(*)(void *param) | func_ptr, | ||
void * | param, | ||
int | mode | ||
) |
add a function and params to a thread pool
thread_pool | The target thread pool |
func_ptr | The function pointer to launch |
param | Eventual parameter struct to pass to the function |
mode | SYNCED_PROC: added to pool, but wait for a start call with other waiting procs. DIRECT_PROC: the function actually starts as quick as possible |
Definition at line 205 of file n_thread_pool.c.
References DIRECT_PROC, IDLE_PROC, list_push(), LOG_DEBUG, LOG_ERR, Malloc, n_log, NO_LOCK, NOQUEUE, RUNNING_THREAD, SYNCED_PROC, and WAITING_PROC.
Referenced by n_fluid_simulate_threaded(), n_vigenere_cypher(), and refresh_thread_pool().
int destroy_threaded_pool | ( | THREAD_POOL ** | pool, |
int | delay | ||
) |
delete a thread_pool, exit the threads and free the structs
pool | The THREAD_POOL *object to kill |
delay | The THREAD_POOL *object to kill |
Definition at line 403 of file n_thread_pool.c.
References __n_assert, EXITING_THREAD, Free, IDLE_PROC, list_destroy(), and u_sleep().
Referenced by n_vigenere_cypher().
int get_nb_cpu_cores | ( | ) |
get number of core of current system
Definition at line 27 of file n_thread_pool.c.
Referenced by new_n_fluid().
THREAD_POOL * new_thread_pool | ( | int | nbmaxthr, |
int | nb_max_waiting | ||
) |
Create a new pool of nbmaxthr threads.
nbmaxthr | number of active threads in the pool |
nb_max_waiting | max number of waiting procs in the pool. Negative or zero value for no limit |
Definition at line 125 of file n_thread_pool.c.
References Free, IDLE_PROC, LOG_ERR, Malloc, n_log, new_generic_list(), RUNNING_THREAD, and thread_pool_processing_function().
Referenced by n_vigenere_cypher().
int refresh_thread_pool | ( | THREAD_POOL * | thread_pool | ) |
try to add some waiting DIRECT_PROCs on some free thread slots, else do nothing
thread_pool | The thread pool to refresh |
Definition at line 469 of file n_thread_pool.c.
References __n_assert, add_threaded_process(), DIRECT_PROC, Free, NO_LOCK, NOQUEUE, remove_list_node, and RUNNING_PROC.
Referenced by n_fluid_simulate_threaded(), n_vigenere_cypher(), thread_pool_processing_function(), and wait_for_threaded_pool().
int start_threaded_pool | ( | THREAD_POOL * | thread_pool | ) |
Launch the process waiting for exectution in the thread pool.
thread_pool | The thread pool to launche |
Definition at line 286 of file n_thread_pool.c.
References LOG_ERR, n_log, SYNCED_PROC, and WAITING_PROC.
Referenced by n_fluid_simulate_threaded().
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
thread_pool | The thread pool to wait |
Definition at line 326 of file n_thread_pool.c.
References __n_assert, LOG_ERR, and n_log.
Referenced by n_fluid_simulate_threaded().
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 | The thread pool to wait |
delay | time between each check |
Definition at line 352 of file n_thread_pool.c.
References IDLE_PROC, refresh_thread_pool(), and u_sleep().
Referenced by n_vigenere_cypher().