-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIThreadImpl_win.h
More file actions
61 lines (52 loc) · 1.26 KB
/
IThreadImpl_win.h
File metadata and controls
61 lines (52 loc) · 1.26 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
/**
* \file IThreadImpl_win.h
* \brief
*/
#include "IThreadImpl.h"
#if USE_THREADIMPL_WIN
#include <windows.h>
//-------------------------------------------------------------------------------------------------
class Thread_win :
IThreadImpl
{
public:
Thread_win()
{
}
virtual ~Thread_win()
{
}
virtual void start(Thread* thread)
{
_handle = ::CreateThread(NULL, 0, _worker, thread, 0, &_id);
}
protected:
DWORD _id;
HANDLE _handle;
static DWORD _worker(void* param)
{
((Thread*)param)->run();
return 0;
}
};
//-------------------------------------------------------------------------------------------------
IThreadImpl*
IThreadImpl::construct()
{
return new Thread_win;
}
//-------------------------------------------------------------------------------------------------
void
IThreadImpl::waitFor(Thread* thread)
{
Thread_win* impl = (Thread_win*)thread->impl;
::WaitForSingleObjectEx(impl->_handle, INFINITY, TRUE);
}
//-------------------------------------------------------------------------------------------------
void
IThreadImpl::yield()
{
::SwitchToThread();
}
//-------------------------------------------------------------------------------------------------
#endif