Got it working on Windows using Mingw
This commit is contained in:
@ -4,7 +4,9 @@ namespace Tesses::Framework::Threading
|
||||
{
|
||||
Mutex::Mutex()
|
||||
{
|
||||
#if defined(GEKKO)
|
||||
#if defined(_WIN32)
|
||||
this->mtx = CreateMutex(NULL,false,NULL);
|
||||
#elif defined(GEKKO)
|
||||
mtx = LWP_MUTEX_NULL;
|
||||
LWP_MutexInit(&mtx, true);
|
||||
#else
|
||||
@ -15,7 +17,9 @@ namespace Tesses::Framework::Threading
|
||||
}
|
||||
void Mutex::Lock()
|
||||
{
|
||||
#if defined(GEKKO)
|
||||
#if defined(_WIN32)
|
||||
WaitForSingleObject(mtx, INFINITE);
|
||||
#elif defined(GEKKO)
|
||||
LWP_MutexLock(mtx);
|
||||
#else
|
||||
mtx_lock(&mtx);
|
||||
@ -23,7 +27,9 @@ namespace Tesses::Framework::Threading
|
||||
}
|
||||
void Mutex::Unlock()
|
||||
{
|
||||
#if defined(GEKKO)
|
||||
#if defined(_WIN32)
|
||||
ReleaseMutex(mtx);
|
||||
#elif defined(GEKKO)
|
||||
LWP_MutexUnlock(mtx);
|
||||
#else
|
||||
mtx_unlock(&mtx);
|
||||
@ -31,7 +37,9 @@ namespace Tesses::Framework::Threading
|
||||
}
|
||||
bool Mutex::TryLock()
|
||||
{
|
||||
#if defined(GEKKO)
|
||||
#if defined(_WIN32)
|
||||
return WaitForSingleObject(mtx, 100) == WAIT_OBJECT_0;
|
||||
#elif defined(GEKKO)
|
||||
return LWP_MutexTryLock(mtx) == 0;
|
||||
#else
|
||||
return mtx_trylock(&mtx) == thrd_success;
|
||||
@ -39,7 +47,9 @@ namespace Tesses::Framework::Threading
|
||||
}
|
||||
Mutex::~Mutex()
|
||||
{
|
||||
#if defined(GEKKO)
|
||||
#if defined(_WIN32)
|
||||
CloseHandle(mtx);
|
||||
#elif defined(GEKKO)
|
||||
LWP_MutexDestroy(mtx);
|
||||
#else
|
||||
mtx_destroy(&mtx);
|
||||
|
||||
@ -2,6 +2,22 @@
|
||||
#include <iostream>
|
||||
namespace Tesses::Framework::Threading
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
static DWORD __stdcall cb(LPVOID data)
|
||||
{
|
||||
auto thrd = static_cast<Thread*>(data);
|
||||
|
||||
auto fn = thrd->fn;
|
||||
thrd->hasInvoked=true;
|
||||
fn();
|
||||
#if defined(GEKKO)
|
||||
return NULL;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
|
||||
#if defined(GEKKO)
|
||||
void* Thread::cb(void* data)
|
||||
#else
|
||||
@ -19,12 +35,14 @@ namespace Tesses::Framework::Threading
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
Thread::Thread(std::function<void()> fn)
|
||||
{
|
||||
this->hasInvoked=false;
|
||||
this->fn = fn;
|
||||
|
||||
#if defined(GEKKO)
|
||||
#if defined(_WIN32)
|
||||
this->thrd = CreateThread(NULL,0,cb,static_cast<LPVOID>(this), 0, &this->thrdId);
|
||||
#elif defined(GEKKO)
|
||||
thrd = LWP_THREAD_NULL;
|
||||
LWP_CreateThread(&thrd, cb, static_cast<void*>(this), NULL, 12000, LWP_PRIO_HIGHEST);
|
||||
#else
|
||||
@ -35,13 +53,19 @@ namespace Tesses::Framework::Threading
|
||||
void Thread::Detach()
|
||||
{
|
||||
#if !defined(GEKKO)
|
||||
#if defined(_WIN32)
|
||||
CloseHandle(thrd);
|
||||
#else
|
||||
thrd_detach(thrd);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void Thread::Join()
|
||||
{
|
||||
#if defined(GEKKO)
|
||||
#if defined(_WIN32)
|
||||
WaitForSingleObject(this->thrd, INFINITE);
|
||||
#elif defined(GEKKO)
|
||||
void* res;
|
||||
LWP_JoinThread(thrd,&res);
|
||||
#else
|
||||
|
||||
Reference in New Issue
Block a user