Crinit -- Configurable Rootfs Init
thrpool.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: MIT
7 #ifndef __THRPOOL_H__
8 #define __THRPOOL_H__
9 
10 #include <limits.h>
11 #include <pthread.h>
12 
16 typedef struct crinitThreadPool_t {
17  size_t poolSize;
19  size_t threadAvail;
20  pthread_mutex_t lock;
21  pthread_cond_t threadAvailChanged;
22  pthread_t dryPoolWdRef;
23 
24  void *(*threadFunc)(void *args);
25  void *thrArgs;
26  size_t thrArgsSize;
28 
32 #define CRINIT_THREADPOOL_DEFAULT_INITIAL_SIZE 8
36 #define CRINIT_THREADPOOL_THREAD_STACK_SIZE (PTHREAD_STACK_MIN + 112 * 1024)
37 
50 int crinitThreadPoolInit(crinitThreadPool_t *ctx, size_t initialSize, void *(*threadFunc)(void *), const void *thrArgs,
51  size_t thrArgsSize);
52 
69 
70 #endif /* __THRPOOL_H__ */
Definition: thrpool.h:16
pthread_cond_t threadAvailChanged
Condition variable signalled if crinitThreadPool_t::threadAvail is changed.
Definition: thrpool.h:21
size_t thrArgsSize
Number of arguments in crinitThreadPool_t::thrArgs.
Definition: thrpool.h:26
size_t poolSize
Current size of the pool.
Definition: thrpool.h:17
void * thrArgs
Arguments to the thread function.
Definition: thrpool.h:25
size_t threadAvail
Number of available worker threads.
Definition: thrpool.h:19
pthread_mutex_t lock
Mutex protecting changes to the thread pool structure.
Definition: thrpool.h:20
pthread_t dryPoolWdRef
Reference to the dry pool watchdog thread, see dryPoolWatchdog() in thrpool.c.
Definition: thrpool.h:22
size_t poolSizeIncrement
How many new threads to create if the pool runs dry.
Definition: thrpool.h:18
int crinitThreadPoolThreadAvailCallback(crinitThreadPool_t *ctx)
Definition: thrpool.c:147
struct crinitThreadPool_t crinitThreadPool_t
int crinitThreadPoolThreadBusyCallback(crinitThreadPool_t *ctx)
Definition: thrpool.c:130
int crinitThreadPoolInit(crinitThreadPool_t *ctx, size_t initialSize, void *(*threadFunc)(void *), const void *thrArgs, size_t thrArgsSize)
Definition: thrpool.c:48