ftwin 0.8.10
napr_threadpool.c File Reference

Implementation of the fixed-size thread pool. More...

#include <stdlib.h>
#include <stdio.h>
#include <apr_thread_proc.h>
#include <apr_thread_mutex.h>
#include <apr_thread_cond.h>
#include "napr_threadpool.h"
#include "debug.h"
Include dependency graph for napr_threadpool.c:

Go to the source code of this file.

Functions

static int napr_list_cons (napr_list_t *napr_list, void *element)
 
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.
 

Detailed Description

Implementation of the fixed-size thread pool.

Definition in file napr_threadpool.c.

Function Documentation

◆ napr_list_cons()

static int napr_list_cons ( napr_list_t *  napr_list,
void *  element 
)
static

return code.

Definition at line 69 of file napr_threadpool.c.

◆ napr_threadpool_add()

apr_status_t napr_threadpool_add ( napr_threadpool_t *  threadpool,
void *  data 
)
extern

Adds a task (a data item) to the thread pool's processing queue.

A waiting worker thread will pick up and process this item.

Parameters
[in]threadpoolThe thread pool.
[in]dataA pointer to the data item to be processed.
Returns
APR_SUCCESS on success, or an error code if the task could not be added.

Definition at line 245 of file napr_threadpool.c.

References DEBUG_ERR.

◆ napr_threadpool_init()

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 
)
extern

Initializes a thread pool.

This creates a pool with a fixed number of worker threads that will process tasks from a queue.

Parameters
[out]threadpoolA pointer to a napr_threadpool_t* that will be allocated and initialized.
[in]ctxA user-defined context pointer that will be passed to the worker function.
[in]nb_threadThe number of worker threads to create in the pool.
[in]process_dataThe callback function that threads will execute to process tasks.
[in]poolThe APR pool to use for allocating the thread pool and its resources.
Returns
APR_SUCCESS on success, or an error code on failure.

Definition at line 200 of file napr_threadpool.c.

References DEBUG_ERR.

◆ napr_threadpool_shutdown()

apr_status_t napr_threadpool_shutdown ( napr_threadpool_t *  threadpool)
extern

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.

Parameters
[in]threadpoolThe thread pool to shut down.
Returns
APR_SUCCESS on success.

Definition at line 390 of file napr_threadpool.c.

References DEBUG_ERR.

◆ napr_threadpool_wait()

apr_status_t napr_threadpool_wait ( napr_threadpool_t *  threadpool)
extern

Waits until all tasks currently in the queue have been processed.

This function blocks until the number of pending tasks reaches zero.

Parameters
[in]threadpoolThe thread pool.
Returns
APR_SUCCESS on success.

Definition at line 268 of file napr_threadpool.c.

References DEBUG_ERR.