Add docker file
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
#include "TessesFramework/Threading/Mutex.hpp"
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
namespace Tesses::Framework::Threading
|
||||
{
|
||||
Mutex::Mutex()
|
||||
@ -10,9 +11,10 @@ namespace Tesses::Framework::Threading
|
||||
mtx = LWP_MUTEX_NULL;
|
||||
LWP_MutexInit(&mtx, true);
|
||||
#else
|
||||
memset(&mtx, 0, sizeof(mtx_t));
|
||||
mtx_init(&mtx, mtx_recursive);
|
||||
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&mtx,&attr);
|
||||
|
||||
#endif
|
||||
}
|
||||
void Mutex::Lock()
|
||||
@ -22,7 +24,7 @@ namespace Tesses::Framework::Threading
|
||||
#elif defined(GEKKO)
|
||||
LWP_MutexLock(mtx);
|
||||
#else
|
||||
mtx_lock(&mtx);
|
||||
pthread_mutex_lock(&mtx);
|
||||
#endif
|
||||
}
|
||||
void Mutex::Unlock()
|
||||
@ -32,7 +34,7 @@ namespace Tesses::Framework::Threading
|
||||
#elif defined(GEKKO)
|
||||
LWP_MutexUnlock(mtx);
|
||||
#else
|
||||
mtx_unlock(&mtx);
|
||||
pthread_mutex_unlock(&mtx);
|
||||
#endif
|
||||
}
|
||||
bool Mutex::TryLock()
|
||||
@ -42,7 +44,7 @@ namespace Tesses::Framework::Threading
|
||||
#elif defined(GEKKO)
|
||||
return LWP_MutexTryLock(mtx) == 0;
|
||||
#else
|
||||
return mtx_trylock(&mtx) == thrd_success;
|
||||
return pthread_mutex_trylock(&mtx) == 0;
|
||||
#endif
|
||||
}
|
||||
Mutex::~Mutex()
|
||||
@ -52,8 +54,9 @@ namespace Tesses::Framework::Threading
|
||||
#elif defined(GEKKO)
|
||||
LWP_MutexDestroy(mtx);
|
||||
#else
|
||||
mtx_destroy(&mtx);
|
||||
pthread_mutex_destroy(&mtx);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
#endif
|
||||
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@ -18,22 +18,17 @@ namespace Tesses::Framework::Threading
|
||||
}
|
||||
#else
|
||||
|
||||
#if defined(GEKKO)
|
||||
|
||||
void* Thread::cb(void* data)
|
||||
#else
|
||||
int Thread::cb(void* data)
|
||||
#endif
|
||||
{
|
||||
{
|
||||
|
||||
auto thrd = static_cast<Thread*>(data);
|
||||
|
||||
auto fn = thrd->fn;
|
||||
thrd->hasInvoked=true;
|
||||
fn();
|
||||
#if defined(GEKKO)
|
||||
return NULL;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif
|
||||
Thread::Thread(std::function<void()> fn)
|
||||
@ -43,10 +38,10 @@ namespace Tesses::Framework::Threading
|
||||
#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);
|
||||
auto res = LWP_CreateThread(&this->thrd, cb, static_cast<void*>(this), nullptr,12000, 98);
|
||||
#else
|
||||
thrd_create(&thrd, cb, static_cast<void*>(this));
|
||||
pthread_create(&thrd,NULL,cb,static_cast<void*>(this));
|
||||
//thrd_create(&thrd, cb, static_cast<void*>(this));
|
||||
#endif
|
||||
while(!this->hasInvoked);
|
||||
}
|
||||
@ -56,7 +51,7 @@ namespace Tesses::Framework::Threading
|
||||
#if defined(_WIN32)
|
||||
CloseHandle(thrd);
|
||||
#else
|
||||
thrd_detach(thrd);
|
||||
pthread_detach(thrd);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
@ -69,9 +64,8 @@ namespace Tesses::Framework::Threading
|
||||
void* res;
|
||||
LWP_JoinThread(thrd,&res);
|
||||
#else
|
||||
int res;
|
||||
thrd_join(thrd,&res);
|
||||
pthread_join(thrd,NULL);
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user