[-] platform specific thread apis
This commit is contained in:
parent
8fec93a0ce
commit
3859b24b0b
@ -1,16 +1,30 @@
|
||||
#include <AuroraRuntime.hpp>
|
||||
#include "GLFW/glfw3.h"
|
||||
|
||||
static bool TryReadFile(const AuString &path, AuString &out)
|
||||
{
|
||||
if (!AuFS::FileExists(path))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return AuFS::ReadString(path, out);
|
||||
}
|
||||
|
||||
extern "C" void _glfwInitAdditionalGamepads(void)
|
||||
{
|
||||
AuString file;
|
||||
|
||||
if (AuFS::ReadString("~/SDLGamepad.keys", file) ||
|
||||
AuFS::ReadString("!/SDLGamepad.keys", file))
|
||||
if (TryReadFile("~/SDLGamepad.keys", file) ||
|
||||
TryReadFile("!/SDLGamepad.keys", file))
|
||||
{
|
||||
if (GLFW_TRUE != glfwUpdateGamepadMappings(file.c_str()))
|
||||
{
|
||||
AuLogWarn("Couldn't parse gamepad mappings.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AuLogVerbose("No additional SDL gamepad database files loaded!");
|
||||
}
|
||||
}
|
46
src/aurora_thread.cpp
Normal file
46
src/aurora_thread.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include <AuroraRuntime.hpp>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
int _glfwPlatformCreateTls(void *tls)
|
||||
{
|
||||
new (tls) AuTLSVariable<void *>();
|
||||
return 1;
|
||||
}
|
||||
|
||||
void _glfwPlatformDestroyTls(void *tls)
|
||||
{
|
||||
((AuTLSVariable<void *> *)tls)->~TLSVariable();
|
||||
}
|
||||
|
||||
void *_glfwPlatformGetTls(void *tls)
|
||||
{
|
||||
return ((AuTLSVariable<void *> *)tls)->operator void *&();
|
||||
}
|
||||
|
||||
void _glfwPlatformSetTls(void *tls, void *value)
|
||||
{
|
||||
((AuTLSVariable<void *> *)tls)->operator void *&() = value;
|
||||
}
|
||||
|
||||
int _glfwPlatformCreateMutex(void *mutex)
|
||||
{
|
||||
new (mutex) AuMutex();
|
||||
return 1;
|
||||
}
|
||||
|
||||
void _glfwPlatformDestroyMutex(void *mutex)
|
||||
{
|
||||
((AuMutex *)mutex)->~AuMutex();
|
||||
}
|
||||
|
||||
void _glfwPlatformLockMutex(void *mutex)
|
||||
{
|
||||
((AuMutex *)mutex)->AsPointer()->Lock();
|
||||
}
|
||||
|
||||
void _glfwPlatformUnlockMutex(void *mutex)
|
||||
{
|
||||
((AuMutex *)mutex)->AsPointer()->Unlock();
|
||||
}
|
||||
}
|
@ -1,23 +1,19 @@
|
||||
#include <AuroraCommon.h>
|
||||
#include <AuroraRuntime.hpp>
|
||||
|
||||
namespace Aurora::Time
|
||||
extern "C"
|
||||
{
|
||||
uint64_ct SteadyClockMS();
|
||||
uint64_ct SteadyClock();
|
||||
uint64_ct SteadyClockJiffies();
|
||||
}
|
||||
void _glfwPlatformInitTimer(void)
|
||||
{
|
||||
|
||||
extern "C" void _glfwPlatformInitTimer(void)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
AuUInt64 _glfwPlatformGetTimerValue(void)
|
||||
{
|
||||
return Aurora::Time::SteadyClock();
|
||||
}
|
||||
|
||||
extern "C" uint64_ct _glfwPlatformGetTimerValue(void)
|
||||
{
|
||||
return Aurora::Time::SteadyClock();
|
||||
}
|
||||
|
||||
extern "C" uint64_ct _glfwPlatformGetTimerFrequency(void)
|
||||
{
|
||||
return Aurora::Time::SteadyClockJiffies();
|
||||
AuUInt64 _glfwPlatformGetTimerFrequency(void)
|
||||
{
|
||||
return Aurora::Time::SteadyClockJiffies();
|
||||
}
|
||||
}
|
@ -698,16 +698,14 @@ struct _GLFWjoystick
|
||||
//
|
||||
struct _GLFWtls
|
||||
{
|
||||
// This is defined in platform.h
|
||||
GLFW_PLATFORM_TLS_STATE
|
||||
char tls[32];
|
||||
};
|
||||
|
||||
// Mutex structure
|
||||
//
|
||||
struct _GLFWmutex
|
||||
{
|
||||
// This is defined in platform.h
|
||||
GLFW_PLATFORM_MUTEX_STATE
|
||||
char mutex[32];
|
||||
};
|
||||
|
||||
// Platform API structure
|
||||
|
@ -162,16 +162,6 @@
|
||||
#define GLFW_BUILD_POSIX_THREAD
|
||||
#endif
|
||||
|
||||
#if defined(GLFW_BUILD_WIN32_THREAD)
|
||||
#include "win32_thread.h"
|
||||
#define GLFW_PLATFORM_TLS_STATE GLFW_WIN32_TLS_STATE
|
||||
#define GLFW_PLATFORM_MUTEX_STATE GLFW_WIN32_MUTEX_STATE
|
||||
#elif defined(GLFW_BUILD_POSIX_THREAD)
|
||||
#include "posix_thread.h"
|
||||
#define GLFW_PLATFORM_TLS_STATE GLFW_POSIX_TLS_STATE
|
||||
#define GLFW_PLATFORM_MUTEX_STATE GLFW_POSIX_MUTEX_STATE
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#define GLFW_BUILD_WIN32_TIMER
|
||||
#elif defined(__APPLE__)
|
||||
|
@ -1,109 +0,0 @@
|
||||
//========================================================================
|
||||
// GLFW 3.4 POSIX - www.glfw.org
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Marcus Geelnard
|
||||
// Copyright (c) 2006-2017 Camilla Löwy <elmindreda@glfw.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
// It is fine to use C99 in this file because it will not be built with VS
|
||||
//========================================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#if defined(GLFW_BUILD_POSIX_THREAD)
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls)
|
||||
{
|
||||
assert(tls->posix.allocated == GLFW_FALSE);
|
||||
|
||||
if (pthread_key_create(&tls->posix.key, NULL) != 0)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"POSIX: Failed to create context TLS");
|
||||
return GLFW_FALSE;
|
||||
}
|
||||
|
||||
tls->posix.allocated = GLFW_TRUE;
|
||||
return GLFW_TRUE;
|
||||
}
|
||||
|
||||
void _glfwPlatformDestroyTls(_GLFWtls* tls)
|
||||
{
|
||||
if (tls->posix.allocated)
|
||||
pthread_key_delete(tls->posix.key);
|
||||
memset(tls, 0, sizeof(_GLFWtls));
|
||||
}
|
||||
|
||||
void* _glfwPlatformGetTls(_GLFWtls* tls)
|
||||
{
|
||||
assert(tls->posix.allocated == GLFW_TRUE);
|
||||
return pthread_getspecific(tls->posix.key);
|
||||
}
|
||||
|
||||
void _glfwPlatformSetTls(_GLFWtls* tls, void* value)
|
||||
{
|
||||
assert(tls->posix.allocated == GLFW_TRUE);
|
||||
pthread_setspecific(tls->posix.key, value);
|
||||
}
|
||||
|
||||
GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex)
|
||||
{
|
||||
assert(mutex->posix.allocated == GLFW_FALSE);
|
||||
|
||||
if (pthread_mutex_init(&mutex->posix.handle, NULL) != 0)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR, "POSIX: Failed to create mutex");
|
||||
return GLFW_FALSE;
|
||||
}
|
||||
|
||||
return mutex->posix.allocated = GLFW_TRUE;
|
||||
}
|
||||
|
||||
void _glfwPlatformDestroyMutex(_GLFWmutex* mutex)
|
||||
{
|
||||
if (mutex->posix.allocated)
|
||||
pthread_mutex_destroy(&mutex->posix.handle);
|
||||
memset(mutex, 0, sizeof(_GLFWmutex));
|
||||
}
|
||||
|
||||
void _glfwPlatformLockMutex(_GLFWmutex* mutex)
|
||||
{
|
||||
assert(mutex->posix.allocated == GLFW_TRUE);
|
||||
pthread_mutex_lock(&mutex->posix.handle);
|
||||
}
|
||||
|
||||
void _glfwPlatformUnlockMutex(_GLFWmutex* mutex)
|
||||
{
|
||||
assert(mutex->posix.allocated == GLFW_TRUE);
|
||||
pthread_mutex_unlock(&mutex->posix.handle);
|
||||
}
|
||||
|
||||
#endif // GLFW_BUILD_POSIX_THREAD
|
||||
|
@ -1,49 +0,0 @@
|
||||
//========================================================================
|
||||
// GLFW 3.4 POSIX - www.glfw.org
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Marcus Geelnard
|
||||
// Copyright (c) 2006-2017 Camilla Löwy <elmindreda@glfw.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#define GLFW_POSIX_TLS_STATE _GLFWtlsPOSIX posix;
|
||||
#define GLFW_POSIX_MUTEX_STATE _GLFWmutexPOSIX posix;
|
||||
|
||||
|
||||
// POSIX-specific thread local storage data
|
||||
//
|
||||
typedef struct _GLFWtlsPOSIX
|
||||
{
|
||||
GLFWbool allocated;
|
||||
pthread_key_t key;
|
||||
} _GLFWtlsPOSIX;
|
||||
|
||||
// POSIX-specific mutex data
|
||||
//
|
||||
typedef struct _GLFWmutexPOSIX
|
||||
{
|
||||
GLFWbool allocated;
|
||||
pthread_mutex_t handle;
|
||||
} _GLFWmutexPOSIX;
|
||||
|
@ -1,102 +0,0 @@
|
||||
//========================================================================
|
||||
// GLFW 3.4 Win32 - www.glfw.org
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Marcus Geelnard
|
||||
// Copyright (c) 2006-2017 Camilla Löwy <elmindreda@glfw.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
// Please use C89 style variable declarations in this file because VS 2010
|
||||
//========================================================================
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#if defined(GLFW_BUILD_WIN32_THREAD)
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
////// GLFW platform API //////
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls)
|
||||
{
|
||||
assert(tls->win32.allocated == GLFW_FALSE);
|
||||
|
||||
tls->win32.index = TlsAlloc();
|
||||
if (tls->win32.index == TLS_OUT_OF_INDEXES)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to allocate TLS index");
|
||||
return GLFW_FALSE;
|
||||
}
|
||||
|
||||
tls->win32.allocated = GLFW_TRUE;
|
||||
return GLFW_TRUE;
|
||||
}
|
||||
|
||||
void _glfwPlatformDestroyTls(_GLFWtls* tls)
|
||||
{
|
||||
if (tls->win32.allocated)
|
||||
TlsFree(tls->win32.index);
|
||||
memset(tls, 0, sizeof(_GLFWtls));
|
||||
}
|
||||
|
||||
void* _glfwPlatformGetTls(_GLFWtls* tls)
|
||||
{
|
||||
assert(tls->win32.allocated == GLFW_TRUE);
|
||||
return TlsGetValue(tls->win32.index);
|
||||
}
|
||||
|
||||
void _glfwPlatformSetTls(_GLFWtls* tls, void* value)
|
||||
{
|
||||
assert(tls->win32.allocated == GLFW_TRUE);
|
||||
TlsSetValue(tls->win32.index, value);
|
||||
}
|
||||
|
||||
GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex)
|
||||
{
|
||||
assert(mutex->win32.allocated == GLFW_FALSE);
|
||||
InitializeCriticalSection(&mutex->win32.section);
|
||||
return mutex->win32.allocated = GLFW_TRUE;
|
||||
}
|
||||
|
||||
void _glfwPlatformDestroyMutex(_GLFWmutex* mutex)
|
||||
{
|
||||
if (mutex->win32.allocated)
|
||||
DeleteCriticalSection(&mutex->win32.section);
|
||||
memset(mutex, 0, sizeof(_GLFWmutex));
|
||||
}
|
||||
|
||||
void _glfwPlatformLockMutex(_GLFWmutex* mutex)
|
||||
{
|
||||
assert(mutex->win32.allocated == GLFW_TRUE);
|
||||
EnterCriticalSection(&mutex->win32.section);
|
||||
}
|
||||
|
||||
void _glfwPlatformUnlockMutex(_GLFWmutex* mutex)
|
||||
{
|
||||
assert(mutex->win32.allocated == GLFW_TRUE);
|
||||
LeaveCriticalSection(&mutex->win32.section);
|
||||
}
|
||||
|
||||
#endif // GLFW_BUILD_WIN32_THREAD
|
||||
|
@ -1,48 +0,0 @@
|
||||
//========================================================================
|
||||
// GLFW 3.4 Win32 - www.glfw.org
|
||||
//------------------------------------------------------------------------
|
||||
// Copyright (c) 2002-2006 Marcus Geelnard
|
||||
// Copyright (c) 2006-2017 Camilla Löwy <elmindreda@glfw.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied
|
||||
// warranty. In no event will the authors be held liable for any damages
|
||||
// arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it
|
||||
// freely, subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented; you must not
|
||||
// claim that you wrote the original software. If you use this software
|
||||
// in a product, an acknowledgment in the product documentation would
|
||||
// be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such, and must not
|
||||
// be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source
|
||||
// distribution.
|
||||
//
|
||||
//========================================================================
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#define GLFW_WIN32_TLS_STATE _GLFWtlsWin32 win32;
|
||||
#define GLFW_WIN32_MUTEX_STATE _GLFWmutexWin32 win32;
|
||||
|
||||
// Win32-specific thread local storage data
|
||||
//
|
||||
typedef struct _GLFWtlsWin32
|
||||
{
|
||||
GLFWbool allocated;
|
||||
DWORD index;
|
||||
} _GLFWtlsWin32;
|
||||
|
||||
// Win32-specific mutex data
|
||||
//
|
||||
typedef struct _GLFWmutexWin32
|
||||
{
|
||||
GLFWbool allocated;
|
||||
CRITICAL_SECTION section;
|
||||
} _GLFWmutexWin32;
|
||||
|
Loading…
Reference in New Issue
Block a user