-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNA_Thread.h
44 lines (33 loc) · 1.17 KB
/
NA_Thread.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
#pragma once
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms737629(v=vs.85).aspx
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <Windows.h>
// http://www.flipcode.com/archives/Simple_Win32_Thread_Class.shtml
// http://kaisar-haque.blogspot.co.uk/2007/07/c-nice-thread-class_23.html <- mainly used this one
class NA_Thread //To make a thread, inherit this class and overload threadFunc, information will need to be global (or within the overloading object)
//threads should check if terminateRequested is true and cleanup and return
//code will not exit properly if thread doesn't eventually terminate
{
private:
static DWORD WINAPI threadProc(LPVOID lpParameter)
{
NA_Thread* t = reinterpret_cast<NA_Thread*> (lpParameter);
return t->threadFunc();
}
protected:
bool terminateRequested = false;
virtual DWORD threadFunc() = 0;
bool ready = false;
HANDLE threadHandle = NULL;
LPDWORD threadID;
public:
void startThread();
NA_Thread();
virtual ~NA_Thread();
void requestSelfTerminate();
LPDWORD getExitCode();
bool waitForTerminate(DWORD milliseconds = INFINITE);
bool isActive();
};