Core/Misc: update g3dlite lib (#2904)

* Core/Misc: update g3dlite lib

* update

Co-authored-by: Francesco Borzì <borzifrancesco@gmail.com>
This commit is contained in:
Viste
2020-07-30 13:35:45 +03:00
committed by GitHub
parent 91bbbf08eb
commit fcaf91b8b2
183 changed files with 13258 additions and 8022 deletions

View File

@@ -4,7 +4,7 @@
GThread class.
@created 2005-09-24
@edited 2005-10-22
@edited 2010-09-22
*/
#include "G3D/GThread.h"
@@ -38,7 +38,7 @@ GThread::GThread(const std::string& name):
m_status(STATUS_CREATED),
m_name(name) {
#ifdef G3D_WIN32
#ifdef G3D_WINDOWS
m_event = NULL;
#endif
@@ -56,15 +56,16 @@ GThread::~GThread() {
# pragma warning( pop )
#endif
#ifdef G3D_WIN32
#ifdef G3D_WINDOWS
if (m_event) {
::CloseHandle(m_event);
}
#endif
}
GThreadRef GThread::create(const std::string& name, void (*proc)(void*), void* param) {
return new _internal::BasicThread(name, proc, param);
return shared_ptr<GThread>(new _internal::BasicThread(name, proc, param));
}
@@ -72,6 +73,38 @@ bool GThread::started() const {
return m_status != STATUS_CREATED;
}
int GThread::numCores() {
return System::numCores();
}
#ifdef G3D_WINDOWS
// From http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
const DWORD MS_VC_EXCEPTION=0x406D1388;
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO {
DWORD dwType; // Must be 0x1000.
LPCSTR szName; // Pointer to name (in user addr space).
DWORD dwThreadID; // Thread ID (-1=caller thread).
DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)
static void SetThreadName(DWORD dwThreadID, const char* threadName) {
THREADNAME_INFO info;
info.dwType = 0x1000;
info.szName = threadName;
info.dwThreadID = dwThreadID;
info.dwFlags = 0;
__try {
RaiseException( MS_VC_EXCEPTION, 0, sizeof(info)/sizeof(ULONG_PTR), (ULONG_PTR*)&info );
} __except(EXCEPTION_EXECUTE_HANDLER) {}
}
#endif
bool GThread::start(SpawnBehavior behavior) {
debugAssertM(! started(), "Thread has already executed.");
@@ -89,7 +122,7 @@ bool GThread::start(SpawnBehavior behavior) {
return true;
}
# ifdef G3D_WIN32
# ifdef G3D_WINDOWS
DWORD threadId;
m_event = ::CreateEvent(NULL, TRUE, FALSE, NULL);
@@ -102,6 +135,8 @@ bool GThread::start(SpawnBehavior behavior) {
m_event = NULL;
}
SetThreadName(threadId, m_name.c_str());
return (m_handle != NULL);
# else
if (!pthread_create(&m_handle, NULL, &internalThreadProc, this)) {
@@ -117,7 +152,7 @@ bool GThread::start(SpawnBehavior behavior) {
void GThread::terminate() {
if (m_handle) {
# ifdef G3D_WIN32
# ifdef G3D_WINDOWS
::TerminateThread(m_handle, 0);
# else
pthread_kill(m_handle, SIGSTOP);
@@ -144,7 +179,7 @@ void GThread::waitForCompletion() {
return;
}
# ifdef G3D_WIN32
# ifdef G3D_WINDOWS
debugAssert(m_event);
::WaitForSingleObject(m_event, INFINITE);
# else
@@ -154,7 +189,7 @@ void GThread::waitForCompletion() {
}
#ifdef G3D_WIN32
#ifdef G3D_WINDOWS
DWORD WINAPI GThread::internalThreadProc(LPVOID param) {
GThread* current = reinterpret_cast<GThread*>(param);
debugAssert(current->m_event);
@@ -178,7 +213,7 @@ void* GThread::internalThreadProc(void* param) {
//GMutex implementation
GMutex::GMutex() {
#ifdef G3D_WIN32
#ifdef G3D_WINDOWS
::InitializeCriticalSection(&m_handle);
#else
int ret = pthread_mutexattr_init(&m_attr);
@@ -192,7 +227,7 @@ GMutex::GMutex() {
GMutex::~GMutex() {
//TODO: Debug check for locked
#ifdef G3D_WIN32
#ifdef G3D_WINDOWS
::DeleteCriticalSection(&m_handle);
#else
int ret = pthread_mutex_destroy(&m_handle);
@@ -203,7 +238,7 @@ GMutex::~GMutex() {
}
bool GMutex::tryLock() {
#ifdef G3D_WIN32
#ifdef G3D_WINDOWS
return (::TryEnterCriticalSection(&m_handle) != 0);
#else
return (pthread_mutex_trylock(&m_handle) == 0);
@@ -211,7 +246,7 @@ bool GMutex::tryLock() {
}
void GMutex::lock() {
#ifdef G3D_WIN32
#ifdef G3D_WINDOWS
::EnterCriticalSection(&m_handle);
#else
pthread_mutex_lock(&m_handle);
@@ -219,7 +254,7 @@ void GMutex::lock() {
}
void GMutex::unlock() {
#ifdef G3D_WIN32
#ifdef G3D_WINDOWS
::LeaveCriticalSection(&m_handle);
#else
pthread_mutex_unlock(&m_handle);