From 37c4373dce60b31ccc0100d85d0013aef82809e7 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Tue, 30 Aug 2022 22:55:26 +0200 Subject: implement thread pools --- src/threading/pool.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/threading/pool.h (limited to 'src/threading/pool.h') diff --git a/src/threading/pool.h b/src/threading/pool.h new file mode 100644 index 0000000..73655d0 --- /dev/null +++ b/src/threading/pool.h @@ -0,0 +1,38 @@ +#ifndef POOL_H +#define POOL_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +typedef void *(*worker_func)(void *); + +struct pool_task_t { + worker_func func; + void* arg; + int done; +}; + +struct pool_t { + int workers; + + struct pool_task_t* tasks; + struct pool_task_t* task_next; + size_t pool_size; + + int* condition; +}; + +struct pool_t* pool_init(); +void pool_free(struct pool_t*); + +void pool_submit(struct pool_t*, worker_func, void*); +void pool_complete(struct pool_t*); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file -- cgit v1.2.3