-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cpp
More file actions
74 lines (66 loc) · 2.03 KB
/
Utils.cpp
File metadata and controls
74 lines (66 loc) · 2.03 KB
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
//------------------------------------------------------------------------
#include "Utils.h"
//------------------------------------------------------------------------
Thread::Thread()
#if FRAMEPRO_WIN_BASED_PLATFORM
: m_Handle(0),
m_Alive(false),
m_ThreadTerminatedEvent(false, false)
#else
: m_Alive(false),
m_ThreadTerminatedEvent(false, false)
#endif
{
}
//------------------------------------------------------------------------
void Thread::CreateThread(ThreadMain p_thread_main, void* p_param)
{
mp_ThreadMain = p_thread_main;
mp_Param = p_param;
#if FRAMEPRO_WIN_BASED_PLATFORM
m_Handle = ::CreateThread(NULL, 0, PlatformThreadMain, this, 0, NULL);
#else
pthread_create(&m_Thread, NULL, PlatformThreadMain, this);
#endif
}
//------------------------------------------------------------------------
#if FRAMEPRO_WIN_BASED_PLATFORM
unsigned long WINAPI Thread::PlatformThreadMain(void* p_param)
{
Thread* p_thread = (Thread*)p_param;
p_thread->m_Alive = true;
unsigned long ret = (unsigned long)p_thread->mp_ThreadMain(p_thread->mp_Param);
p_thread->m_Alive = false;
p_thread->m_ThreadTerminatedEvent.Set();
return ret;
}
#else
void* Thread::PlatformThreadMain(void* p_param)
{
Thread* p_thread = (Thread*)p_param;
p_thread->m_Alive = true;
p_thread->mp_ThreadMain(p_thread->mp_Param);
p_thread->m_Alive = false;
p_thread->m_ThreadTerminatedEvent.Set();
return NULL;
}
#endif
//------------------------------------------------------------------------
void Thread::SetPriority(int priority)
{
#if FRAMEPRO_WIN_BASED_PLATFORM
::SetThreadPriority(m_Handle, priority);
#endif
}
//------------------------------------------------------------------------
void Thread::SetAffinity(int affinity)
{
#if FRAMEPRO_WIN_BASED_PLATFORM && !FRAMEPRO_PLATFORM_UWP
SetThreadAffinityMask(m_Handle, affinity);
#endif
}
//------------------------------------------------------------------------
void Thread::WaitForThreadToTerminate(int timeout)
{
m_ThreadTerminatedEvent.Wait(timeout);
}