-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathThreadMgr.h
59 lines (50 loc) · 1.1 KB
/
ThreadMgr.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
#pragma once
#include <map>
#include <assert.h>
#include "Lock.h"
class ThreadMgr {
public:
ThreadMgr();
~ThreadMgr();
bool addAllThreads(DWORD excluded);
void clearThreads();
HANDLE addThread(DWORD tid);
bool delThread(DWORD tid);
void suspendAll(DWORD excluded);
void resumeAll(DWORD excluded);
HANDLE threadIdToHandle(DWORD tid);
DWORD threadHandleToId(HANDLE handle);
DWORD getFirstThread() const
{
if (_threads.size() == 0) {
assert(false);
return 0;
}
_cursor = _threads.begin();
return _cursor->first;
}
DWORD getNextThread() const
{
if (++ _cursor == _threads.end())
return 0;
return _cursor->first;
}
protected:
virtual HANDLE openThread(DWORD dwDesiredAccess, BOOL bInheritHandle,
DWORD dwThreadId)
{
return ::OpenThread(dwDesiredAccess, bInheritHandle, dwThreadId);
}
virtual DWORD suspendThread(HANDLE hThead)
{
return ::SuspendThread(hThead);
}
virtual DWORD resumeThread(HANDLE hThead)
{
return ::ResumeThread(hThead);
}
protected:
std::map<DWORD, HANDLE> _threads;
Mutex _lock;
mutable std::map<DWORD, HANDLE>::const_iterator _cursor;
};