Nilorea Library

- Main Page
- Modules
- Data Structures
- Files

All Data Structures Files Functions Variables Typedefs Macros Groups
Data Structures | Macros | Typedefs | Functions
THREADS: tools to create and manage a thread pool

## Data Structures

struct | THREAD_POOL_NODE
struct | THREAD_POOL

## Macros

#define | SYNCED_PROC 1
#define | DIRECT_PROC 2
#define | IDLE_THREAD 1
#define | BUSY_THREAD 2
#define | RUNNING_THREAD 3
#define | EXITING_THREAD 4

## Typedefs

typedef struct THREAD_POOL_NODE | THREAD_POOL_NODE
typedef struct THREAD_POOL | THREAD_POOL

## Functions

THREAD_POOL * | new_thread_pool (int nbmaxthr)
| Create a new pool of nbmaxthr threads. More...
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 | start_threaded_pool (THREAD_POOL *thread_pool)
| Launch the process waiting for exectution in the thread pool. More...
int | wait_for_threaded_pool (THREAD_POOL *thread_pool)
| Wait for all the launched process in the thread pool to terminate. More...

## Detailed Description

## Macro Definition Documentation

#define BUSY_THREAD 2

status of a busy thread

Definition at line 33 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 EXITING_THREAD 4

status of an exiting thread

Definition at line 37 of file n_thread_pool.h.

#define IDLE_THREAD 1

status of an idle thread

Definition at line 31 of file n_thread_pool.h.

#define RUNNING_THREAD 3

status for a running thread

Definition at line 35 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.

## Typedef Documentation

typedef struct THREAD_POOL THREAD_POOL

Structure of a trhead pool

typedef struct THREAD_POOL_NODE THREAD_POOL_NODE

A thread pool node

## Function Documentation

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

Parameters

  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

Returns
  TRUE or FALSE

Definition at line 120 of file n_thread_pool.c.

THREAD_POOL * new_thread_pool | ( | int | nbmaxthr | ) |

Create a new pool of nbmaxthr threads.

Parameters

  nbmaxthr | number of waiting threads in the pool

Returns
  NULL or a new trhead pool object

Definition at line 62 of file n_thread_pool.c.

Here is the call graph for this function:

int start_threaded_pool | ( | THREAD_POOL * | thread_pool | ) |

Launch the process waiting for exectution in the thread pool.

Parameters

  thread_pool | The thread pool to launche

Returns
  TRUE or FALSE

Definition at line 178 of file n_thread_pool.c.

int wait_for_threaded_pool | ( | THREAD_POOL * | thread_pool | ) |

Wait for all the launched process in the thread pool to terminate.

Parameters

  thread_pool | The thread pool to wait

Returns
  TRUE or FALSE

Definition at line 211 of file n_thread_pool.c.