-
Notifications
You must be signed in to change notification settings - Fork 6
/
threadWrapper.h
56 lines (49 loc) · 1.32 KB
/
threadWrapper.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
#ifndef THREAD_WRAPPER_
#define THREAD_WRAPPER_
#include <thread>
#include <functional>
#include <memory>
#include <queue>
#include <mutex>
#include <string>
#include "Buffer.h"
#include <atomic>
#include <vector>
#include <set>
typedef std::function<void(Buffer*&)> Callback;
typedef std::function<void()> BeginInThreadCallback;
class threadWrapper {
private:
threadWrapper(const threadWrapper&);
threadWrapper& operator=(const threadWrapper&);
threadWrapper();
threadWrapper(int n32BlockSize, int n32BufferSize);
void Run();
void RunWithUpdate();
void setCallBack(Callback aCallBack);
bool IfEmpty();
void Consume();
std::queue<Buffer*> m_Queue;
std::thread m_Thread;
Callback m_Callback;
std::mutex m_IOMutex;
std::condition_variable m_ConditionVar;
std::atomic<int> m_PendingWorkNum;
std::atomic<bool> m_IfNeedSig;
unsigned m_ThreadID;
std::queue<Buffer*> m_SwapQueue;
bool m_IfUpdate;
bool m_IsStop;
public:
~threadWrapper();
void send(Buffer* apBuffer);
void stop();
static threadWrapper* createThread(Callback aCallBack, int n32BlockSize, int b32BufferSize);
int getPendingWorkNum()const{return m_PendingWorkNum;}
unsigned getThreadID();
void start();
void setThreadStartCallback(BeginInThreadCallback pBeginInThreadCallback);
private:
BeginInThreadCallback m_BeginInThreadCallback;
};
#endif