-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEMThread.h
66 lines (55 loc) · 1.91 KB
/
EMThread.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
/*******************************************************
* Creator: Martin Rudefelt
* Component: none
* Portability: non-native
*-------------------------------------------------------
* Contains a native code section
*******************************************************/
#include "EMGlobals.h"
#ifndef __EM_THREAD
#define __EM_THREAD
#include "EMSemaphore.h"
#include <list>
#include <string>
class EMThreadListener;
// Thread priorities are between 0 and 120 where 120 is the highest priority
const int32 EM_THREAD_IDLE_PRIORITY = 1;
const int32 EM_THREAD_LOW_PRIORITY = 5;
const int32 EM_THREAD_MEDIUM_PRIORITY = 15;
const int32 EM_THREAD_HIGH_PRIORITY = 90;
const int32 EM_THREAD_REALTIME_PRIORITY = 110;
const int32 EM_THREAD_HIGH_REALTIME_PRIORITY = 120;
class EMThread
{
public:
virtual ~EMThread();
void AddListener(EMThreadListener* p_opListener);
static EMThread* CreateEMThread(const char* p_vpName, int32 p_vPriority = EM_THREAD_MEDIUM_PRIORITY, int32 p_vSleepTime = 1000);
bool IsListening(EMThreadListener* p_opListener);
bool IsRunning() const;
virtual void Kill(bool p_vCalledFromThreadRun = false) = 0;
void Notify();
void NotifyCreated();
void NotifyKilled();
void RemoveListener(EMThreadListener* p_opListener);
virtual void SetPriority(int32 p_vPriority) = 0;
virtual void Sleep(int64 p_vMicroSeconds) = 0;
virtual void Start() = 0;
// virtual void StartSuspended() = 0;
// virtual void Suspend(bool p_vCalledFromThreadRun = false) = 0;
// virtual void Resume() = 0;
virtual void WaitForThread() = 0;
protected:
EMThread(const char* p_vpName);
protected:
string m_oThreadName;
bool m_vIsAlive;
bool m_vShouldRun;
int32 m_vSleepTime;
private:
list<EMThreadListener*> m_oListeners; // Does not own its listeners
list<EMThreadListener*> m_oScheduledAdditions;
list<EMThreadListener*> m_oScheduledRemovals;
bool m_vDoNotModify;
};
#endif