Go to the documentation of this file.
9 #ifndef __THREADPOOL_H__
10 #define __THREADPOOL_H__
12 #include <semaphore.h>
21 void (*
function)(
void *, size_t);
81 #endif // __THREADPOOL_H__
queue_t * queue
pointer to the queue of tasks;
Definition: threadpool.h:50
bool finished
information about finishing all tasks;
Definition: threadpool.h:52
Runnable function.
Definition: threadpool.h:20
struct sigaction old_action
old sigaction;
Definition: threadpool.c:86
int thread_pool_init(thread_pool_t *pool, size_t num_threads)
Initialize the thread-pool.
Definition: threadpool.c:185
size_t pools_size
size of the known_pools array;
Definition: threadpool.c:88
node_t * last
pointer to the last element;
Definition: threadpool.h:39
Single queue node.
Definition: threadpool.h:29
pthread_t * threads
array of threads;
Definition: threadpool.h:51
Thread-pool.
Definition: threadpool.h:46
size_t size
size of the queue;
Definition: threadpool.h:40
struct @0 handler
Signal handler.
runnable_t runnable
runnable function;
Definition: threadpool.h:30
static void free_queue(queue_t *queue)
Deallocate the queue.
Definition: threadpool.c:72
size_t pool_size
number of threads;
Definition: threadpool.h:47
Standard FIFO queue.
Definition: threadpool.h:37
sem_t waiting_threads
semaphore for free threads;
Definition: threadpool.h:49
struct node node_t
Single queue node.
static void sigint_destroy()
Destroy all pools after receiving SIGINT.
Definition: threadpool.c:97
__attribute__((constructor))
Constructor of the exception handler.
Definition: threadpool.c:115
node_t * first
pointer to the first element;
Definition: threadpool.h:38
int thread_pool_init(thread_pool_t *pool, size_t pool_size)
Initialize the thread-pool.
Definition: threadpool.c:185
void thread_pool_destroy(thread_pool_t *pool)
Destroy the thread-pool.
Definition: threadpool.c:256
void(* function)(void *, size_t)
f(arg, argsz);
Definition: threadpool.h:21
static void * thread_function(void *arg)
Function run by every thread.
Definition: threadpool.c:145
void thread_pool_destroy(thread_pool_t *pool)
Destroy the thread-pool.
Definition: threadpool.c:256
static void push(queue_t *queue, runnable_t runnable)
Add a new element to the queue.
Definition: threadpool.c:21
int defer(thread_pool_t *pool, runnable_t runnable)
Add a new task to the pool.
Definition: threadpool.c:318
struct sigaction action
new sigaction;
Definition: threadpool.c:85
struct thread_pool thread_pool_t
Thread-pool.
sem_t mutex
thread-pool mutex;
Definition: threadpool.h:48
thread_pool_t ** known_pools
array of pointers to all known pools;
Definition: threadpool.c:87
size_t argsz
number of arguments;
Definition: threadpool.h:23
struct queue queue_t
Standard FIFO queue.
void * arg
array of arguments;
Definition: threadpool.h:22
sigset_t block_mask
mask with blocked signals;
Definition: threadpool.c:90
unsigned last
number of initialized pools;
Definition: threadpool.c:89
static runnable_t pop(queue_t *queue)
Read and pop the first element in queue.
Definition: threadpool.c:48
struct runnable runnable_t
Runnable function.
pthread_attr_t attr
standard pthread attribute;
Definition: threadpool.h:53
struct node * next
pointer to the next node;
Definition: threadpool.h:31
int defer(struct thread_pool *pool, runnable_t runnable)
Add a new task to the pool.
Definition: threadpool.c:318