-
Notifications
You must be signed in to change notification settings - Fork 2
/
CThreadPool.h
75 lines (75 loc) · 2.08 KB
/
CThreadPool.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* =====================================================================================
*
* Filename: CThreadPool.h
*
* Description: :`
*
* Version: 1.0
* Created: 12/18/2015 09:35:19 PM
* Revision: none
* Compiler: gcc
*
* Author: Dengbzh (),
* Organization:
*
* =====================================================================================
*/
#ifndef CTHREADPOOL_H
#define CTHREADPOOL_H
#include"CJob.h"
#include"CWorkerThread.h"
#include"Utility.h"
class CThreadPool
{
friend class CWorkerThread;
private:
unsigned int m_MaxNum;
unsigned int m_AvaliLow;
unsigned int m_AvaliHigh;
unsigned int m_AvaliNum;
unsigned int m_InitNum;
unsigned int m_Threadno;
int m_busyTheashold;
protected:
CWorkerThread *getIdleThread(void);
void moveToBusyList(CWorkerThread*busywork);
void moveToIdleList(CWorkerThread*idlework);
void deleteIdleThread(int num);
void createIdleThread(int num);
public:
CThreadPool();
CThreadPool(int initSize);
virtual ~CThreadPool();
// pthread_mutex_t m_JobListMutex;
// pthread_mutex_t m_val_mutex;
pthread_mutex_t m_busyListMutex;
pthread_mutex_t m_idleListMutex;
sem_t m_avaliThreads;
sem_t m_avaliWork;
// sem_t m_jobSem;
// vector<CJob*> m_JobQuere;
// vector<void*> m_JobData;
vector<CWorkerThread*> m_allTheads;
vector<CWorkerThread*> m_busyList;
vector<CWorkerThread*> m_idleList;
int m_totThreadNum;
// void invoking(CJob *job,void*jobdata);
unsigned int getMaxNum()const;
unsigned int getAvaliLow()const;
unsigned int getAvaliHigh()const;
unsigned int getAvaliNum()const;
unsigned int getInitNum()const;
void setMaxnum(unsigned int maxnum);
void setAvaliLow(unsigned int avalilow);
void setAvaliHigh(unsigned int avalihigh);
void setbusyThreashold(int threashold);
void printState();
unsigned int getBusyNum();
unsigned int getidleNum();
unsigned int getAll();
void terminateAll();
void Run(CJob *job,void *jobdata);
// void Adjust();
};
#endif