-
Notifications
You must be signed in to change notification settings - Fork 0
/
thread-pool.h
35 lines (26 loc) · 866 Bytes
/
thread-pool.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
* Copyright (C) 2015, CompuLab ltd.
* Author: Andrey Gelman <[email protected]>
* License: GNU GPLv2 or later, at your option
*/
#ifndef _THREAD_POOL_H
#define _THREAD_POOL_H
#include <pthread.h>
#include "queue.h"
typedef void (*ThreadPoolWork)(void *priv_context, void *shared_context);
typedef struct {
pthread_mutex_t lock;
pthread_cond_t queue_not_empty;
pthread_cond_t queue_not_full;
Queue *work_queue;
void *shared_context;
int thread_count;
/* 'thread_pool' must be the last */
pthread_t thread_pool[0];
} ThreadPool;
ThreadPool *thread_pool_create(int thread_count, int queue_size, void *shared_context);
void thread_pool_join(ThreadPool *p);
void thread_pool_destroy(ThreadPool *p);
void thread_pool_add_request(ThreadPool *p, ThreadPoolWork func, void *context);
int thread_pool_test(void);
#endif /* _THREAD_POOL_H */