-
Notifications
You must be signed in to change notification settings - Fork 5
/
ThreadPool.h
51 lines (46 loc) · 1.37 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
/*************************************************************************
> File Name: ThreadPool.h
> Author: zhangfeng
> Mail: [email protected]
> Created Time: Wed 16 Oct 2019 03:40:44 PM CST
> Target:
************************************************************************/
#ifndef _THREADPOOL_H
#define _THREADPOOL_H
#include "Thread.h"
#include <vector>
#include <queue>
#include <memory>
#include <functional>
#include <deque>
#include <unistd.h>
class ThreadPool{
public:
ThreadPool(unsigned int minThreadNum, unsigned int maxThreadNum);
~ThreadPool();
unsigned int TaskSize();
unsigned int GetBusy(){return busyThreadNum_;}
std::shared_ptr<ThreadTask> GetThreadTask();
void Run();
void Shut() {shutDown_ = true;}
void IncBusy();
void DscBusy();
void Destroy();
void AdjustThread();
void TaskAdd(std::shared_ptr<ThreadTask> threadTask);
unsigned int GetLivThreadNum() {return livThreadNum_;}
private:
bool shutDown_;
unsigned int livThreadNum_;
unsigned int minThreadNum_;
unsigned int maxThreadNum_;
unsigned int taskSize_;
unsigned int busyThreadNum_;
pthread_cond_t cond_;
pthread_mutex_t mutex_;
pthread_mutex_t counterMutex_;
pthread_mutex_t taskMutex_;
std::queue<std::shared_ptr<ThreadTask>> taskQueue_;
std::deque<std::shared_ptr<Thread>> threadVector_;
};
#endif