45 lines
1.3 KiB
C
45 lines
1.3 KiB
C
#ifndef INCLUDED_C_THREADPOOL_H
|
|||
|
|
#define INCLUDED_C_THREADPOOL_H
|
||
|
|
|
||
|
|
#ifndef INCLUDED_C_LOCKQUEUE_H
|
||
|
|
#include <c_LockQueue.h>
|
||
|
|
#endif /*INCLUDED_C_LOCKQUEUE_H*/
|
||
|
|
|
||
|
|
#ifndef INCLUDED_C_THREAD_H
|
||
|
|
#include <c_Thread.h>
|
||
|
|
#endif /*INCLUDED_C_THREAD_H*/
|
||
|
|
|
||
|
|
#ifndef INCLUDED_C_POOL_H
|
||
|
|
#include <c_Pool.h>
|
||
|
|
#endif /*INCLUDED_C_POOL_H*/
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
/* ------------------------------------------------------------------------------------------------------------------ */
|
||
|
|
/* */
|
||
|
|
|
||
|
|
// Struct representing a single executable unit of work
|
||
|
|
typedef struct {
|
||
|
|
void (*function)(void*); // Pointer to the user function
|
||
|
|
void* argument; // Argument passed to the function
|
||
|
|
} c_ThreadPoolTask_t;
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
c_LockQueue_t task_queue; // Safe queue storing thread_pool_task_t pointers
|
||
|
|
c_Thread_t* threads; // Array of worker thread handles
|
||
|
|
int thread_count; // Total number of worker threads
|
||
|
|
volatile c_bool_t is_shutdown; // Shutdown flag
|
||
|
|
int check_interval_ms;
|
||
|
|
c_Pool_t task_pool;
|
||
|
|
} c_ThreadPool_t;
|
||
|
|
|
||
|
|
// Public Core API
|
||
|
|
c_err_t c_ThreadPool_Init(c_ThreadPool_t* pool, int thread_count, int queue_capacity, int task_pool_size, int check_interval_ms);
|
||
|
|
|
||
|
|
void c_ThreadPool_Destroy(c_ThreadPool_t* pool);
|
||
|
|
|
||
|
|
c_bool_t c_ThreadPool_Submit(c_ThreadPool_t* pool, void (*function)(void*), void* argument);
|
||
|
|
|
||
|
|
|
||
|
|
#endif /*INCLUDED_C_THREADPOOL_H*/
|