-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThreadPool.h
59 lines (44 loc) · 1.03 KB
/
ThreadPool.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// Created by sunruoxu on 17-4-2.
//
#ifndef CHATSERVER_THREADPOOL_H
#define CHATSERVER_THREADPOOL_H
#include <sys/types.h>
#include <stdbool.h>
struct bsem{
pthread_mutex_t mutex;
pthread_cond_t cond;
int vaule;
};
struct thread{
pthread_t pthread;
int id;
struct ThreadPool* _threadPool;
};
struct ThreadQueue_item{
struct work* work;
struct ThreadQueue_item* next;
};
struct ThreadQueue{
pthread_mutex_t rwmutext;
struct bsem has_work;
int size;
struct ThreadQueue_item* pos;
struct ThreadQueue_item* head;
};
struct ThreadPool{
struct thread** threads;
struct ThreadQueue threadQueue;
int thread_alive_num;
int thread_running_num;
pthread_mutex_t mutex;
pthread_cond_t cond;
}ThreadPool;
struct work{
void (*func)(void*);
void* arg;
};
struct ThreadPool* ThreadPool_init(int num);
void ThreadPool_work_in(struct ThreadPool* threadPool,void* func,void* arg);
void ThreadPool_wait(struct ThreadPool* threadPool);
#endif //CHATSERVER_THREADPOOL_H