ftwin 0.8.10
|
A simple fixed-size thread pool for concurrent task processing. More...
#include <apr_pools.h>
Go to the source code of this file.
Typedefs | |
typedef struct napr_threadpool_t | napr_threadpool_t |
Opaque thread pool structure. | |
typedef apr_status_t() | threadpool_process_data_callback_fn_t(void *ctx, void *data) |
The worker function executed by threads in the pool. | |
Functions | |
apr_status_t | napr_threadpool_init (napr_threadpool_t **threadpool, void *ctx, unsigned long nb_thread, threadpool_process_data_callback_fn_t *process_data, apr_pool_t *pool) |
Initializes a thread pool. | |
apr_status_t | napr_threadpool_add (napr_threadpool_t *threadpool, void *data) |
Adds a task (a data item) to the thread pool's processing queue. | |
apr_status_t | napr_threadpool_wait (napr_threadpool_t *threadpool) |
Waits until all tasks currently in the queue have been processed. | |
apr_status_t | napr_threadpool_shutdown (napr_threadpool_t *threadpool) |
Shuts down the thread pool. | |
A simple fixed-size thread pool for concurrent task processing.
Definition in file napr_threadpool.h.
typedef apr_status_t() threadpool_process_data_callback_fn_t(void *ctx, void *data) |
The worker function executed by threads in the pool.
This function is called for each data item added to the pool's queue.
[in] | ctx | A pointer to the shared context, provided during pool initialization. |
[in] | data | A pointer to the data item to be processed. |
Definition at line 41 of file napr_threadpool.h.
apr_status_t napr_threadpool_add | ( | napr_threadpool_t * | threadpool, |
void * | data | ||
) |
Adds a task (a data item) to the thread pool's processing queue.
A waiting worker thread will pick up and process this item.
[in] | threadpool | The thread pool. |
[in] | data | A pointer to the data item to be processed. |
Definition at line 245 of file napr_threadpool.c.
References DEBUG_ERR.
apr_status_t napr_threadpool_init | ( | napr_threadpool_t ** | threadpool, |
void * | ctx, | ||
unsigned long | nb_thread, | ||
threadpool_process_data_callback_fn_t * | process_data, | ||
apr_pool_t * | pool | ||
) |
Initializes a thread pool.
This creates a pool with a fixed number of worker threads that will process tasks from a queue.
[out] | threadpool | A pointer to a napr_threadpool_t* that will be allocated and initialized. |
[in] | ctx | A user-defined context pointer that will be passed to the worker function. |
[in] | nb_thread | The number of worker threads to create in the pool. |
[in] | process_data | The callback function that threads will execute to process tasks. |
[in] | pool | The APR pool to use for allocating the thread pool and its resources. |
Definition at line 200 of file napr_threadpool.c.
References DEBUG_ERR.
apr_status_t napr_threadpool_shutdown | ( | napr_threadpool_t * | threadpool | ) |
Shuts down the thread pool.
This function signals all worker threads to terminate, waits for them to finish their current tasks, and then joins them. No new tasks can be added after this
function is called.
[in] | threadpool | The thread pool to shut down. |
Definition at line 390 of file napr_threadpool.c.
References DEBUG_ERR.
apr_status_t napr_threadpool_wait | ( | napr_threadpool_t * | threadpool | ) |
Waits until all tasks currently in the queue have been processed.
This function blocks until the number of pending tasks reaches zero.
[in] | threadpool | The thread pool. |
Definition at line 268 of file napr_threadpool.c.
References DEBUG_ERR.