-
Notifications
You must be signed in to change notification settings - Fork 2
/
CThread.h
61 lines (51 loc) · 1.07 KB
/
CThread.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
#ifndef _CTHREAD_H__
#define _CTHREAD_H__
#include <pthread.h>
#ifdef _WIN32
#include <process.h>
#include <winsock2.h>
#include <windows.h>
#define STDPREFIX _stdcall;
#else
#include <unistd.h>
#define STDPREFIX
#endif
typedef void * threadparam_t;
class CThread
{
public:
CThread(const CThread &){}
CThread(bool release = true);
CThread& operator= (const CThread&){return *this;}
virtual ~CThread();
void onStart();
virtual void Run() = 0;
#ifdef _WIN32
static unsigned _stdcall StartThread(threadparam_t);
HANDLE GetThread(){return m_thread;}
unsigned GetThreadId(){return m_dwThreadId;}
#else
static void * StartThread(threadparam_t);
pthread_t GetThread(){return m_thread;}
#endif
bool IsRunning();
void SetRunning(bool x);
bool IsRelease();
void SetRelease(bool x);
bool DeleteOnExit();
void SetDeleteOnExit(bool x = true);
bool IsDestructor();
protected:
#ifdef _WIN32
HANDLE m_thread;
unsigned m_dwThreadId;
#else
pthread_t m_thread;
#endif
private:
bool m_running;
bool m_release;
bool m_b_delete_on_exit;
bool m_b_destructor;
};
#endif/*_THREAD_H__*/