for mingw

This commit is contained in:
Damiano 2020-01-27 00:16:30 +01:00 committed by GitHub
parent 0b5018c1b4
commit d0a16676a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,11 +2,11 @@
#include "Thread.h" #include "Thread.h"
#if NV_OS_WIN32 #if NV_OS_USE_PTHREAD
#include "Win32.h"
#elif NV_OS_USE_PTHREAD
#include <pthread.h> #include <pthread.h>
#include <unistd.h> // usleep #include <unistd.h> // usleep
#elif NV_OS_WIN32
#include "Win32.h"
#endif #endif
#include "nvcore/StrLib.h" #include "nvcore/StrLib.h"
@ -23,10 +23,10 @@ using namespace nv;
struct Thread::Private struct Thread::Private
{ {
#if NV_OS_WIN32 #if NV_OS_USE_PTHREAD
HANDLE thread;
#elif NV_OS_USE_PTHREAD
pthread_t thread; pthread_t thread;
#elif NV_OS_WIN32
HANDLE thread;
#endif #endif
ThreadFunc * func; ThreadFunc * func;
@ -35,7 +35,7 @@ struct Thread::Private
}; };
#if NV_OS_WIN32 #if NV_OS_WIN32 && !NV_OS_MINGW
unsigned long __stdcall threadFunc(void * arg) { unsigned long __stdcall threadFunc(void * arg) {
Thread::Private * thread = (Thread::Private *)arg; Thread::Private * thread = (Thread::Private *)arg;
@ -115,7 +115,7 @@ void Thread::start(ThreadFunc * func, void * arg)
p->func = func; p->func = func;
p->arg = arg; p->arg = arg;
#if NV_OS_WIN32 #if NV_OS_WIN32 && !NV_OS_MINGW
DWORD threadId; DWORD threadId;
p->thread = CreateThread(NULL, 0, threadFunc, p.ptr(), 0, &threadId); p->thread = CreateThread(NULL, 0, threadFunc, p.ptr(), 0, &threadId);
//p->thread = (HANDLE)_beginthreadex (0, 0, threadFunc, p.ptr(), 0, NULL); // @@ So that we can call CRT functions... //p->thread = (HANDLE)_beginthreadex (0, 0, threadFunc, p.ptr(), 0, NULL); // @@ So that we can call CRT functions...
@ -136,7 +136,7 @@ void Thread::start(ThreadFunc * func, void * arg)
void Thread::wait() void Thread::wait()
{ {
#if NV_OS_WIN32 #if NV_OS_WIN32 && !NV_OS_MINGW
DWORD status = WaitForSingleObject (p->thread, INFINITE); DWORD status = WaitForSingleObject (p->thread, INFINITE);
nvCheck (status == WAIT_OBJECT_0); nvCheck (status == WAIT_OBJECT_0);
BOOL ok = CloseHandle (p->thread); BOOL ok = CloseHandle (p->thread);
@ -151,7 +151,7 @@ void Thread::wait()
bool Thread::isRunning () const bool Thread::isRunning () const
{ {
#if NV_OS_WIN32 #if NV_OS_WIN32 && !NV_OS_MINGW
return p->thread != NULL; return p->thread != NULL;
#elif NV_OS_USE_PTHREAD #elif NV_OS_USE_PTHREAD
return p->thread != 0; return p->thread != 0;
@ -165,7 +165,7 @@ bool Thread::isRunning () const
/*static*/ void Thread::yield() /*static*/ void Thread::yield()
{ {
#if NV_OS_WIN32 #if NV_OS_WIN32 && !NV_OS_MINGW
SwitchToThread(); SwitchToThread();
#elif NV_OS_USE_PTHREAD #elif NV_OS_USE_PTHREAD
int result = sched_yield(); int result = sched_yield();
@ -175,7 +175,7 @@ bool Thread::isRunning () const
/*static*/ void Thread::sleep(uint ms) /*static*/ void Thread::sleep(uint ms)
{ {
#if NV_OS_WIN32 #if NV_OS_WIN32 && !NV_OS_MINGW
Sleep(ms); Sleep(ms);
#elif NV_OS_USE_PTHREAD #elif NV_OS_USE_PTHREAD
usleep(1000 * ms); usleep(1000 * ms);
@ -207,4 +207,3 @@ bool Thread::isRunning () const
} }
//#endif //#endif
} }