-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathThreadTools.cpp
57 lines (43 loc) · 1.15 KB
/
ThreadTools.cpp
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
#include "ThreadTools.h"
#include "LogTools.h"
TOOLSPACE_BEGIN
#ifdef WIN32 //define the macro for Win32 thread
THREAD_HANDLE ThreadTools::CREATE_THREAD(int (* pThreadFun)( void * ), void * pParam)
{
//uintptr_t tmp_res = _beginthreadex(NULL, 0, (THREAD_FUN_TYPE) pThreadFun, pParam, NULL, NULL);
//LOG_TO_CONSOLE("tmp_res", tmp_res);
return _beginthreadex(NULL, 0, (THREAD_FUN_TYPE) pThreadFun, pParam, NULL, NULL);
}
void ThreadTools::END_THREAD()
{
_endthreadex(0);
}
void ThreadTools::CLOSE_THREAD(THREAD_HANDLE hThread)
{
CloseHandle((HANDLE *) hThread);
}
void ThreadTools::WAIT_THREAD(THREAD_HANDLE hThread)
{
WaitForSingleObject((HANDLE*)hThread, INFINITE);
}
#else //define the macro for POSIX thread
THREAD_HANDLE ThreadTools::CREATE_THREAD(int (* pThreadFun)( void * ), void * pParam)
{
pthread_t threadID;
pthread_create(&threadID, NULL, (THREAD_FUN_TYPE)pThreadFun, pParam);
return threadID;
}
void ThreadTools::END_THREAD()
{
pthread_exit(0);
}
void ThreadTools::CLOSE_THREAD(THREAD_HANDLE hThread)
{
}
void ThreadTools::WAIT_THREAD(THREAD_HANDLE hThread)
{
void * retval;
pthread_join(hThread, &retval);
}
#endif // WIN32
TOOLSPACE_END