|
|
|
@ -539,65 +539,14 @@ public:
@@ -539,65 +539,14 @@ public:
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
bool CreateThread(void(*pfn)(void*), void* parg); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Note: It turns out we might have been able to use boost::thread
|
|
|
|
|
// by using TerminateThread(boost::thread.native_handle(), 0);
|
|
|
|
|
#ifdef WIN32 |
|
|
|
|
typedef HANDLE pthread_t; |
|
|
|
|
|
|
|
|
|
inline pthread_t CreateThread(void(*pfn)(void*), void* parg, bool fWantHandle=false) |
|
|
|
|
{ |
|
|
|
|
DWORD nUnused = 0; |
|
|
|
|
HANDLE hthread = |
|
|
|
|
CreateThread( |
|
|
|
|
NULL, // default security
|
|
|
|
|
0, // inherit stack size from parent
|
|
|
|
|
(LPTHREAD_START_ROUTINE)pfn, // function pointer
|
|
|
|
|
parg, // argument
|
|
|
|
|
0, // creation option, start immediately
|
|
|
|
|
&nUnused); // thread identifier
|
|
|
|
|
if (hthread == NULL) |
|
|
|
|
{ |
|
|
|
|
printf("Error: CreateThread() returned %d\n", GetLastError()); |
|
|
|
|
return (pthread_t)0; |
|
|
|
|
} |
|
|
|
|
if (!fWantHandle) |
|
|
|
|
{ |
|
|
|
|
CloseHandle(hthread); |
|
|
|
|
return (pthread_t)-1; |
|
|
|
|
} |
|
|
|
|
return hthread; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline void SetThreadPriority(int nPriority) |
|
|
|
|
{ |
|
|
|
|
SetThreadPriority(GetCurrentThread(), nPriority); |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
inline pthread_t CreateThread(void(*pfn)(void*), void* parg, bool fWantHandle=false) |
|
|
|
|
{ |
|
|
|
|
pthread_t hthread = 0; |
|
|
|
|
int ret = pthread_create(&hthread, NULL, (void*(*)(void*))pfn, parg); |
|
|
|
|
if (ret != 0) |
|
|
|
|
{ |
|
|
|
|
printf("Error: pthread_create() returned %d\n", ret); |
|
|
|
|
return (pthread_t)0; |
|
|
|
|
} |
|
|
|
|
if (!fWantHandle) |
|
|
|
|
{ |
|
|
|
|
pthread_detach(hthread); |
|
|
|
|
return (pthread_t)-1; |
|
|
|
|
} |
|
|
|
|
return hthread; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#define THREAD_PRIORITY_LOWEST PRIO_MAX |
|
|
|
|
#define THREAD_PRIORITY_BELOW_NORMAL 2 |
|
|
|
|