solidc
Robust collection of general-purpose cross-platform C libraries and data structures designed for rapid and safe development in C
Loading...
Searching...
No Matches
threadpool.h
Go to the documentation of this file.
1
82#ifndef __THREADPOOL_H__
83#define __THREADPOOL_H__
84
85#include <stdbool.h>
86#include <stddef.h>
87#include <stdint.h>
88
89#ifdef __cplusplus
90extern "C" {
91#endif
92
99typedef struct Threadpool Threadpool;
100
108typedef struct Task {
109 void (*function)(void* arg);
110 void* arg;
112
134Threadpool* threadpool_create(size_t num_threads);
135
167bool threadpool_submit(Threadpool* pool, void (*function)(void*), void* arg);
168
220size_t threadpool_submit_batch(Threadpool* pool, void (**functions)(void*), void** args, size_t count);
221
258void threadpool_wait(Threadpool* pool);
259
294void threadpool_destroy(Threadpool* pool, int timeout_ms);
295
296#ifdef __cplusplus
297}
298#endif
299
300#endif /* __THREADPOOL_H__ */
A unit of work submitted to the pool.
Definition threadpool.h:108
void * arg
Definition threadpool.h:110
void(* function)(void *arg)
Definition threadpool.h:109
bool threadpool_submit(Threadpool *pool, void(*function)(void *), void *arg)
Submit a single task to the pool.
Definition threadpool.c:656
size_t threadpool_submit_batch(Threadpool *pool, void(**functions)(void *), void **args, size_t count)
Submit multiple tasks to the pool in a single call.
Definition threadpool.c:690
Threadpool * threadpool_create(size_t num_threads)
Create a new thread pool.
Definition threadpool.c:597
void threadpool_destroy(Threadpool *pool, int timeout_ms)
Drain all pending tasks, stop all workers, and free the pool.
Definition threadpool.c:774
void threadpool_wait(Threadpool *pool)
Block until all currently submitted tasks have completed.
Definition threadpool.c:750
struct Threadpool Threadpool
Opaque handle to a thread pool instance.
Definition threadpool.h:99