-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreads.h
79 lines (72 loc) · 1.65 KB
/
threads.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
76
77
78
79
// Template, UU version
// IGAD/NHTV/UU - Jacco Bikker - 2006-2017
#pragma once
class Thread
{
public:
Thread() { m_hThread = 0; }
unsigned long* handle() { return m_hThread; }
void start();
virtual void run() {};
void sleep(long ms);
void suspend();
void resume();
void kill();
void stop();
void setPriority( int p );
void SetName( char* _Name );
private:
unsigned long* m_hThread;
static const int P_ABOVE_NORMAL;
static const int P_BELOW_NORMAL;
static const int P_HIGHEST;
static const int P_IDLE;
static const int P_LOWEST;
static const int P_NORMAL;
static const int P_CRITICAL;
};
extern "C" { unsigned int sthread_proc( void* param ); }
namespace Tmpl8 {
class Job
{
public:
virtual void Main() = 0;
protected:
friend class JobThread;
void RunCodeWrapper();
};
class JobThread
{
public:
void CreateAndStartThread( unsigned int threadId );
void WaitForThreadToStop();
void Go();
void BackgroundTask();
HANDLE m_GoSignal, m_ThreadHandle;
int m_ThreadID;
};
class JobManager // singleton class!
{
protected:
JobManager( unsigned int numThreads );
public:
~JobManager();
static void CreateJobManager( unsigned int numThreads );
static JobManager* GetJobManager() { return m_JobManager; }
void AddJob2( Job* a_Job );
unsigned int GetNumThreads() { return m_NumThreads; }
void RunJobs();
void ThreadDone( unsigned int n );
int MaxConcurrent() { return m_NumThreads; }
protected:
friend class JobThread;
Job* GetNextJob();
Job* FindNextJob();
static JobManager* m_JobManager;
Job* m_JobList[64];
CRITICAL_SECTION m_CS;
HANDLE m_ThreadDone[4];
unsigned int m_NumThreads, m_JobCount;
JobThread* m_JobThreadList;
};
}; // namespace Tmpl8