QSC Post Quantum Cryptographic Library 1.0.0.6c (A6)
A post quantum secure library written in Ansi C
 
Loading...
Searching...
No Matches
threadpool.h File Reference

Asynchronous Thread Pool Management Functions. More...

#include "common.h"
#include "async.h"

Go to the source code of this file.

Data Structures

struct  qsc_threadpool_state
 The thread pool state. More...
 

Macros

#define QSC_THREADPOOL_THREADS_MAX   1024ULL
 The thread pool maximum threads.
 

Functions

QSC_EXPORT_API bool qsc_threadpool_add_task (qsc_threadpool_state *ctx, void(*func)(void *), void *state)
 Add a task to the thread-pool.
 
QSC_EXPORT_API void qsc_threadpool_clear (qsc_threadpool_state *ctx)
 Clear all tasks from the thread-pool.
 
QSC_EXPORT_API void qsc_threadpool_initialize (qsc_threadpool_state *ctx)
 Initialize the thread-pool.
 
QSC_EXPORT_API void qsc_threadpool_sort (qsc_threadpool_state *ctx)
 Sort the threads in the pool, placing active threads at the start of the array.
 
QSC_EXPORT_API bool qsc_threadpool_thread_active (const qsc_threadpool_state *ctx, size_t index)
 Check if a thread is active.
 
QSC_EXPORT_API void qsc_threadpool_remove_task (qsc_threadpool_state *ctx, size_t index)
 Remove a task from the thread-pool.
 

Detailed Description

Asynchronous Thread Pool Management Functions.

This header defines the public API for managing an asynchronous thread pool. The thread pool enables the scheduling and execution of tasks concurrently by spawning multiple threads. It provides functions to add tasks to the pool, clear all tasks, initialize the pool, sort the threads to prioritize active tasks, check thread activity, and remove individual tasks.

// Example: Initialize a thread pool, add a task, and check thread activity.
// Define a sample task function.
void sample_task(void* arg)
{
// Task implementation.
}
// Add the task to the thread pool.
bool success = qsc_threadpool_add_task(&pool, sample_task, NULL);
// Check if the first thread in the pool is active.
bool is_active = qsc_threadpool_thread_active(&pool, 0);
// Remove the task from the pool if needed.
// Clear the thread pool.
The thread pool state.
Definition threadpool.h:102
QSC_EXPORT_API void qsc_threadpool_initialize(qsc_threadpool_state *ctx)
Initialize the thread-pool.
QSC_EXPORT_API bool qsc_threadpool_thread_active(const qsc_threadpool_state *ctx, size_t index)
Check if a thread is active.
QSC_EXPORT_API void qsc_threadpool_clear(qsc_threadpool_state *ctx)
Clear all tasks from the thread-pool.
QSC_EXPORT_API bool qsc_threadpool_add_task(qsc_threadpool_state *ctx, void(*func)(void *), void *state)
Add a task to the thread-pool.
QSC_EXPORT_API void qsc_threadpool_remove_task(qsc_threadpool_state *ctx, size_t index)
Remove a task from the thread-pool.

Reference Links:

Function Documentation

◆ qsc_threadpool_add_task()

QSC_EXPORT_API bool qsc_threadpool_add_task ( qsc_threadpool_state * ctx,
void(* func )(void *),
void * state )

Add a task to the thread-pool.

Parameters
ctx[qsc_threadpool_state*] The thread pool state
func[(func)(void)] A pointer to the thread function
state[void*] The thread state

◆ qsc_threadpool_clear()

QSC_EXPORT_API void qsc_threadpool_clear ( qsc_threadpool_state * ctx)

Clear all tasks from the thread-pool.

Parameters
ctx[qsc_threadpool_state*] The thread pool state

◆ qsc_threadpool_initialize()

QSC_EXPORT_API void qsc_threadpool_initialize ( qsc_threadpool_state * ctx)

Initialize the thread-pool.

Parameters
ctx[qsc_threadpool_state*] The thread pool state

◆ qsc_threadpool_remove_task()

QSC_EXPORT_API void qsc_threadpool_remove_task ( qsc_threadpool_state * ctx,
size_t index )

Remove a task from the thread-pool.

Parameters
ctx[qsc_threadpool_state*] The thread pool state
index[size_t] The thread index

◆ qsc_threadpool_sort()

QSC_EXPORT_API void qsc_threadpool_sort ( qsc_threadpool_state * ctx)

Sort the threads in the pool, placing active threads at the start of the array.

Parameters
ctx[qsc_threadpool_state*] The thread pool state

◆ qsc_threadpool_thread_active()

QSC_EXPORT_API bool qsc_threadpool_thread_active ( const qsc_threadpool_state * ctx,
size_t index )

Check if a thread is active.

Parameters
ctx[const qsc_threadpool_state*] The thread pool state
index[size_t] The thread index
Returns
[bool] Returns true if the thread is currently used