mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-14 13:56:00 +00:00
@@ -339,8 +339,8 @@ SDL_Thread *SDL_CreateThreadWithPropertiesRuntime(SDL_PropertiesID props,
|
||||
SDL_FunctionPointer pfnBeginThread,
|
||||
SDL_FunctionPointer pfnEndThread)
|
||||
{
|
||||
// rather than check this in every backend, just make sure it's correct upfront. Only allow non-NULL if non-WinRT Windows, or Microsoft GDK.
|
||||
#if (!defined(SDL_PLATFORM_WIN32) && !defined(SDL_PLATFORM_GDK)) || defined(SDL_PLATFORM_WINRT)
|
||||
// rather than check this in every backend, just make sure it's correct upfront. Only allow non-NULL if Windows, or Microsoft GDK.
|
||||
#if (!defined(SDL_PLATFORM_WIN32) && !defined(SDL_PLATFORM_GDK))
|
||||
if (pfnBeginThread || pfnEndThread) {
|
||||
SDL_SetError("_beginthreadex/_endthreadex not supported on this platform");
|
||||
return NULL;
|
||||
|
@@ -38,8 +38,6 @@
|
||||
#include "vita/SDL_systhread_c.h"
|
||||
#elif defined(SDL_THREAD_N3DS)
|
||||
#include "n3ds/SDL_systhread_c.h"
|
||||
#elif defined(SDL_THREAD_STDCPP)
|
||||
#include "stdcpp/SDL_systhread_c.h"
|
||||
#elif defined(SDL_THREAD_NGAGE)
|
||||
#include "ngage/SDL_systhread_c.h"
|
||||
#else
|
||||
|
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.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 "SDL_internal.h"
|
||||
|
||||
extern "C" {
|
||||
}
|
||||
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <ratio>
|
||||
#include <system_error>
|
||||
|
||||
#include "SDL_sysmutex_c.h"
|
||||
|
||||
struct SDL_Condition
|
||||
{
|
||||
std::condition_variable_any cpp_cond;
|
||||
};
|
||||
|
||||
// Create a condition variable
|
||||
extern "C"
|
||||
SDL_Condition *SDL_CreateCondition(void)
|
||||
{
|
||||
// Allocate and initialize the condition variable
|
||||
try {
|
||||
SDL_Condition *cond = new SDL_Condition;
|
||||
return cond;
|
||||
} catch (std::system_error &ex) {
|
||||
SDL_SetError("unable to create a C++ condition variable: code=%d; %s", ex.code(), ex.what());
|
||||
return NULL;
|
||||
} catch (std::bad_alloc &) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy a condition variable
|
||||
extern "C"
|
||||
void SDL_DestroyCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (cond) {
|
||||
delete cond;
|
||||
}
|
||||
}
|
||||
|
||||
// Restart one of the threads that are waiting on the condition variable
|
||||
extern "C"
|
||||
void SDL_SignalCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (!cond) {
|
||||
return;
|
||||
}
|
||||
|
||||
cond->cpp_cond.notify_one();
|
||||
}
|
||||
|
||||
// Restart all threads that are waiting on the condition variable
|
||||
extern "C"
|
||||
void SDL_BroadcastCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (!cond) {
|
||||
return;
|
||||
}
|
||||
|
||||
cond->cpp_cond.notify_all();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
SDL_bool SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS)
|
||||
{
|
||||
if (!cond || !mutex) {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
std::unique_lock<std::recursive_mutex> cpp_lock(mutex->cpp_mutex, std::adopt_lock_t());
|
||||
if (timeoutNS < 0) {
|
||||
cond->cpp_cond.wait(cpp_lock);
|
||||
cpp_lock.release();
|
||||
return true;
|
||||
} else {
|
||||
auto wait_result = cond->cpp_cond.wait_for(
|
||||
cpp_lock,
|
||||
std::chrono::duration<Sint64, std::nano>(timeoutNS));
|
||||
cpp_lock.release();
|
||||
if (wait_result == std::cv_status::timeout) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (std::system_error &) {
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.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 "SDL_internal.h"
|
||||
|
||||
extern "C" {
|
||||
#include "SDL_systhread_c.h"
|
||||
}
|
||||
|
||||
#include <system_error>
|
||||
|
||||
#include "SDL_sysmutex_c.h"
|
||||
#include <windows.h>
|
||||
|
||||
extern "C"
|
||||
SDL_Mutex * SDL_CreateMutex(void)
|
||||
{
|
||||
// Allocate and initialize the mutex
|
||||
try {
|
||||
SDL_Mutex *mutex = new SDL_Mutex;
|
||||
return mutex;
|
||||
} catch (std::system_error &ex) {
|
||||
SDL_SetError("unable to create a C++ mutex: code=%d; %s", ex.code(), ex.what());
|
||||
} catch (std::bad_alloc &) {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void SDL_DestroyMutex(SDL_Mutex *mutex)
|
||||
{
|
||||
if (mutex) {
|
||||
delete mutex;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes
|
||||
{
|
||||
if (mutex) {
|
||||
try {
|
||||
mutex->cpp_mutex.lock();
|
||||
} catch (std::system_error &/*ex*/) {
|
||||
SDL_assert(!"Error trying to lock mutex"); // assume we're in a lot of trouble if this assert fails.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
SDL_bool SDL_TryLockMutex(SDL_Mutex *mutex)
|
||||
{
|
||||
bool result = true;
|
||||
if (mutex) {
|
||||
result = mutex->cpp_mutex.try_lock();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Unlock the mutex
|
||||
extern "C"
|
||||
void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes
|
||||
{
|
||||
if (mutex) {
|
||||
mutex->cpp_mutex.unlock();
|
||||
}
|
||||
}
|
||||
|
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.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 "SDL_internal.h"
|
||||
|
||||
#include <mutex>
|
||||
|
||||
struct SDL_Mutex
|
||||
{
|
||||
std::recursive_mutex cpp_mutex;
|
||||
};
|
||||
|
@@ -1,118 +0,0 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.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 "SDL_internal.h"
|
||||
|
||||
#include <shared_mutex>
|
||||
#include <system_error>
|
||||
#include <Windows.h>
|
||||
|
||||
struct SDL_RWLock
|
||||
{
|
||||
std::shared_mutex cpp_mutex;
|
||||
SDL_ThreadID write_owner;
|
||||
};
|
||||
|
||||
extern "C"
|
||||
SDL_RWLock *SDL_CreateRWLock(void)
|
||||
{
|
||||
try {
|
||||
SDL_RWLock *rwlock = new SDL_RWLock;
|
||||
return rwlock;
|
||||
} catch (std::system_error &ex) {
|
||||
SDL_SetError("unable to create a C++ rwlock: code=%d; %s", ex.code(), ex.what());
|
||||
return NULL;
|
||||
} catch (std::bad_alloc &) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void SDL_DestroyRWLock(SDL_RWLock *rwlock)
|
||||
{
|
||||
if (rwlock) {
|
||||
delete rwlock;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void SDL_LockRWLockForReading(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes
|
||||
{
|
||||
if (rwlock) {
|
||||
try {
|
||||
rwlock->cpp_mutex.lock_shared();
|
||||
} catch (std::system_error &/*ex*/) {
|
||||
SDL_assert(!"Error trying to lock rwlock for reading"); // assume we're in a lot of trouble if this assert fails.
|
||||
//return SDL_SetError("unable to lock a C++ rwlock: code=%d; %s", ex.code(), ex.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void SDL_LockRWLockForWriting(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes
|
||||
{
|
||||
if (rwlock) {
|
||||
try {
|
||||
rwlock->cpp_mutex.lock();
|
||||
rwlock->write_owner = SDL_GetCurrentThreadID();
|
||||
} catch (std::system_error &/*ex*/) {
|
||||
SDL_assert(!"Error trying to lock rwlock for writing"); // assume we're in a lot of trouble if this assert fails.
|
||||
//return SDL_SetError("unable to lock a C++ rwlock: code=%d; %s", ex.code(), ex.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
SDL_bool SDL_TryLockRWLockForReading(SDL_RWLock *rwlock)
|
||||
{
|
||||
bool result = true;
|
||||
if (rwlock) {
|
||||
result = rwlock->cpp_mutex.try_lock_shared();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
SDL_bool SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock)
|
||||
{
|
||||
bool result = true;
|
||||
if (rwlock) {
|
||||
result = rwlock->cpp_mutex.try_lock();
|
||||
if (result) {
|
||||
rwlock->write_owner = SDL_GetCurrentThreadID();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void SDL_UnlockRWLock(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes
|
||||
{
|
||||
if (rwlock) {
|
||||
if (rwlock->write_owner == SDL_GetCurrentThreadID()) {
|
||||
rwlock->write_owner = 0;
|
||||
rwlock->cpp_mutex.unlock();
|
||||
} else {
|
||||
rwlock->cpp_mutex.unlock_shared();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,169 +0,0 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.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 "SDL_internal.h"
|
||||
|
||||
// Thread management routines for SDL
|
||||
|
||||
extern "C" {
|
||||
#include "../SDL_thread_c.h"
|
||||
#include "../SDL_systhread.h"
|
||||
}
|
||||
|
||||
#include <thread>
|
||||
#include <system_error>
|
||||
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
static void RunThread(void *args)
|
||||
{
|
||||
SDL_RunThread((SDL_Thread *)args);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
bool SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
SDL_FunctionPointer pfnBeginThread,
|
||||
SDL_FunctionPointer pfnEndThread)
|
||||
{
|
||||
try {
|
||||
// !!! FIXME: no way to set a thread stack size here.
|
||||
thread->handle = (void *)new std::thread(RunThread, thread);
|
||||
return true;
|
||||
} catch (std::system_error &ex) {
|
||||
return SDL_SetError("unable to start a C++ thread: code=%d; %s", ex.code().value(), ex.what());
|
||||
} catch (std::bad_alloc &) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
extern "C"
|
||||
SDL_ThreadID SDL_GetCurrentThreadID(void)
|
||||
{
|
||||
static_assert(sizeof(std::thread::id) <= sizeof(SDL_ThreadID), "std::thread::id must not be bigger than SDL_ThreadID");
|
||||
SDL_ThreadID thread_id{};
|
||||
const auto cpp_thread_id = std::this_thread::get_id();
|
||||
SDL_memcpy(&thread_id, &cpp_thread_id, sizeof(std::thread::id));
|
||||
return thread_id;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
{
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
int value;
|
||||
|
||||
if (priority == SDL_THREAD_PRIORITY_LOW) {
|
||||
value = THREAD_PRIORITY_LOWEST;
|
||||
} else if (priority == SDL_THREAD_PRIORITY_HIGH) {
|
||||
value = THREAD_PRIORITY_HIGHEST;
|
||||
} else if (priority == SDL_THREAD_PRIORITY_TIME_CRITICAL) {
|
||||
// FIXME: WinRT does not support TIME_CRITICAL! -flibit
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_SYSTEM, "TIME_CRITICAL unsupported, falling back to HIGHEST");
|
||||
value = THREAD_PRIORITY_HIGHEST;
|
||||
} else {
|
||||
value = THREAD_PRIORITY_NORMAL;
|
||||
}
|
||||
if (!SetThreadPriority(GetCurrentThread(), value)) {
|
||||
return WIN_SetError("SetThreadPriority()");
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
return SDL_Unsupported();
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void SDL_SYS_WaitThread(SDL_Thread *thread)
|
||||
{
|
||||
if (!thread) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
std::thread *cpp_thread = (std::thread *)thread->handle;
|
||||
if (cpp_thread) {
|
||||
if (cpp_thread->joinable()) {
|
||||
cpp_thread->join();
|
||||
}
|
||||
delete cpp_thread;
|
||||
thread->handle = nullptr;
|
||||
}
|
||||
} catch (std::system_error &) {
|
||||
// An error occurred when joining the thread. SDL_WaitThread does not,
|
||||
// however, seem to provide a means to report errors to its callers
|
||||
// though!
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void SDL_SYS_DetachThread(SDL_Thread *thread)
|
||||
{
|
||||
if (!thread) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
std::thread *cpp_thread = (std::thread *)thread->handle;
|
||||
if (cpp_thread) {
|
||||
if (cpp_thread->joinable()) {
|
||||
cpp_thread->detach();
|
||||
}
|
||||
delete cpp_thread;
|
||||
thread->handle = nullptr;
|
||||
}
|
||||
} catch (std::system_error &) {
|
||||
// An error occurred when detaching the thread. SDL_DetachThread does not,
|
||||
// however, seem to provide a means to report errors to its callers
|
||||
// though!
|
||||
}
|
||||
}
|
||||
|
||||
static thread_local SDL_TLSData *thread_local_storage;
|
||||
|
||||
extern "C"
|
||||
void SDL_SYS_InitTLSData(void)
|
||||
{
|
||||
}
|
||||
|
||||
extern "C"
|
||||
SDL_TLSData * SDL_SYS_GetTLSData(void)
|
||||
{
|
||||
return thread_local_storage;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
bool SDL_SYS_SetTLSData(SDL_TLSData *data)
|
||||
{
|
||||
thread_local_storage = data;
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
void SDL_SYS_QuitTLSData(void)
|
||||
{
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.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 "SDL_internal.h"
|
||||
|
||||
// For a thread handle, use a void pointer to a std::thread
|
||||
typedef void *SYS_ThreadHandle;
|
@@ -56,12 +56,6 @@ typedef struct CONDITION_VARIABLE
|
||||
} CONDITION_VARIABLE, *PCONDITION_VARIABLE;
|
||||
#endif
|
||||
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
#define pWakeConditionVariable WakeConditionVariable
|
||||
#define pWakeAllConditionVariable WakeAllConditionVariable
|
||||
#define pSleepConditionVariableSRW SleepConditionVariableSRW
|
||||
#define pSleepConditionVariableCS SleepConditionVariableCS
|
||||
#else
|
||||
typedef VOID(WINAPI *pfnWakeConditionVariable)(PCONDITION_VARIABLE);
|
||||
typedef VOID(WINAPI *pfnWakeAllConditionVariable)(PCONDITION_VARIABLE);
|
||||
typedef BOOL(WINAPI *pfnSleepConditionVariableSRW)(PCONDITION_VARIABLE, PSRWLOCK, DWORD, ULONG);
|
||||
@@ -71,7 +65,6 @@ static pfnWakeConditionVariable pWakeConditionVariable = NULL;
|
||||
static pfnWakeAllConditionVariable pWakeAllConditionVariable = NULL;
|
||||
static pfnSleepConditionVariableSRW pSleepConditionVariableSRW = NULL;
|
||||
static pfnSleepConditionVariableCS pSleepConditionVariableCS = NULL;
|
||||
#endif
|
||||
|
||||
typedef struct SDL_cond_cv
|
||||
{
|
||||
@@ -152,7 +145,6 @@ static const SDL_cond_impl_t SDL_cond_impl_cv = {
|
||||
};
|
||||
|
||||
|
||||
#ifndef SDL_PLATFORM_WINRT
|
||||
// Generic Condition Variable implementation using SDL_Mutex and SDL_Semaphore
|
||||
static const SDL_cond_impl_t SDL_cond_impl_generic = {
|
||||
&SDL_CreateCondition_generic,
|
||||
@@ -161,7 +153,6 @@ static const SDL_cond_impl_t SDL_cond_impl_generic = {
|
||||
&SDL_BroadcastCondition_generic,
|
||||
&SDL_WaitConditionTimeoutNS_generic,
|
||||
};
|
||||
#endif
|
||||
|
||||
SDL_Condition *SDL_CreateCondition(void)
|
||||
{
|
||||
@@ -179,10 +170,6 @@ SDL_Condition *SDL_CreateCondition(void)
|
||||
SDL_assert(SDL_mutex_impl_active.Type != SDL_MUTEX_INVALID);
|
||||
}
|
||||
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
// Link statically on this platform
|
||||
impl = &SDL_cond_impl_cv;
|
||||
#else
|
||||
// Default to generic implementation, works with all mutex implementations
|
||||
impl = &SDL_cond_impl_generic;
|
||||
{
|
||||
@@ -198,7 +185,6 @@ SDL_Condition *SDL_CreateCondition(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_copyp(&SDL_cond_impl_active, impl);
|
||||
}
|
||||
|
@@ -39,13 +39,6 @@ SDL_mutex_impl_t SDL_mutex_impl_active = { 0 };
|
||||
* Implementation based on Slim Reader/Writer (SRW) Locks for Win 7 and newer.
|
||||
*/
|
||||
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
// Functions are guaranteed to be available
|
||||
#define pInitializeSRWLock InitializeSRWLock
|
||||
#define pReleaseSRWLockExclusive ReleaseSRWLockExclusive
|
||||
#define pAcquireSRWLockExclusive AcquireSRWLockExclusive
|
||||
#define pTryAcquireSRWLockExclusive TryAcquireSRWLockExclusive
|
||||
#else
|
||||
typedef VOID(WINAPI *pfnInitializeSRWLock)(PSRWLOCK);
|
||||
typedef VOID(WINAPI *pfnReleaseSRWLockExclusive)(PSRWLOCK);
|
||||
typedef VOID(WINAPI *pfnAcquireSRWLockExclusive)(PSRWLOCK);
|
||||
@@ -54,7 +47,6 @@ static pfnInitializeSRWLock pInitializeSRWLock = NULL;
|
||||
static pfnReleaseSRWLockExclusive pReleaseSRWLockExclusive = NULL;
|
||||
static pfnAcquireSRWLockExclusive pAcquireSRWLockExclusive = NULL;
|
||||
static pfnTryAcquireSRWLockExclusive pTryAcquireSRWLockExclusive = NULL;
|
||||
#endif
|
||||
|
||||
static SDL_Mutex *SDL_CreateMutex_srw(void)
|
||||
{
|
||||
@@ -143,12 +135,8 @@ static SDL_Mutex *SDL_CreateMutex_cs(void)
|
||||
if (mutex) {
|
||||
// Initialize
|
||||
// On SMP systems, a non-zero spin count generally helps performance
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
InitializeCriticalSectionEx(&mutex->cs, 2000, 0);
|
||||
#else
|
||||
// This function always succeeds
|
||||
(void)InitializeCriticalSectionAndSpinCount(&mutex->cs, 2000);
|
||||
#endif
|
||||
}
|
||||
return (SDL_Mutex *)mutex;
|
||||
}
|
||||
@@ -194,9 +182,6 @@ static const SDL_mutex_impl_t SDL_mutex_impl_cs = {
|
||||
SDL_Mutex *SDL_CreateMutex(void)
|
||||
{
|
||||
if (!SDL_mutex_impl_active.Create) {
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
const SDL_mutex_impl_t *impl = &SDL_mutex_impl_srw;
|
||||
#else
|
||||
const SDL_mutex_impl_t *impl = &SDL_mutex_impl_cs;
|
||||
|
||||
// Try faster implementation for Windows 7 and newer
|
||||
@@ -212,7 +197,6 @@ SDL_Mutex *SDL_CreateMutex(void)
|
||||
impl = &SDL_mutex_impl_srw;
|
||||
}
|
||||
}
|
||||
#endif // SDL_PLATFORM_WINRT
|
||||
|
||||
// Copy instead of using pointer to save one level of indirection
|
||||
SDL_copyp(&SDL_mutex_impl_active, impl);
|
||||
|
@@ -35,17 +35,6 @@ typedef VOID(WINAPI *pfnReleaseSRWLockExclusive)(PSRWLOCK);
|
||||
typedef VOID(WINAPI *pfnAcquireSRWLockExclusive)(PSRWLOCK);
|
||||
typedef BOOLEAN(WINAPI *pfnTryAcquireSRWLockExclusive)(PSRWLOCK);
|
||||
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
// Functions are guaranteed to be available
|
||||
#define pTryAcquireSRWLockExclusive TryAcquireSRWLockExclusive
|
||||
#define pInitializeSRWLock InitializeSRWLock
|
||||
#define pReleaseSRWLockShared ReleaseSRWLockShared
|
||||
#define pAcquireSRWLockShared AcquireSRWLockShared
|
||||
#define pTryAcquireSRWLockShared TryAcquireSRWLockShared
|
||||
#define pReleaseSRWLockExclusive ReleaseSRWLockExclusive
|
||||
#define pAcquireSRWLockExclusive AcquireSRWLockExclusive
|
||||
#define pTryAcquireSRWLockExclusive TryAcquireSRWLockExclusive
|
||||
#else
|
||||
static pfnInitializeSRWLock pInitializeSRWLock = NULL;
|
||||
static pfnReleaseSRWLockShared pReleaseSRWLockShared = NULL;
|
||||
static pfnAcquireSRWLockShared pAcquireSRWLockShared = NULL;
|
||||
@@ -53,7 +42,6 @@ static pfnTryAcquireSRWLockShared pTryAcquireSRWLockShared = NULL;
|
||||
static pfnReleaseSRWLockExclusive pReleaseSRWLockExclusive = NULL;
|
||||
static pfnAcquireSRWLockExclusive pAcquireSRWLockExclusive = NULL;
|
||||
static pfnTryAcquireSRWLockExclusive pTryAcquireSRWLockExclusive = NULL;
|
||||
#endif
|
||||
|
||||
typedef SDL_RWLock *(*pfnSDL_CreateRWLock)(void);
|
||||
typedef void (*pfnSDL_DestroyRWLock)(SDL_RWLock *);
|
||||
@@ -152,7 +140,6 @@ static const SDL_rwlock_impl_t SDL_rwlock_impl_srw = {
|
||||
&SDL_UnlockRWLock_srw
|
||||
};
|
||||
|
||||
#ifndef SDL_PLATFORM_WINRT
|
||||
|
||||
#include "../generic/SDL_sysrwlock_c.h"
|
||||
|
||||
@@ -166,19 +153,12 @@ static const SDL_rwlock_impl_t SDL_rwlock_impl_generic = {
|
||||
&SDL_TryLockRWLockForWriting_generic,
|
||||
&SDL_UnlockRWLock_generic
|
||||
};
|
||||
#endif
|
||||
|
||||
SDL_RWLock *SDL_CreateRWLock(void)
|
||||
{
|
||||
if (!SDL_rwlock_impl_active.Create) {
|
||||
const SDL_rwlock_impl_t *impl;
|
||||
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
// Link statically on this platform
|
||||
impl = &SDL_rwlock_impl_srw;
|
||||
#else
|
||||
// Default to generic implementation, works with all mutex implementations
|
||||
impl = &SDL_rwlock_impl_generic;
|
||||
const SDL_rwlock_impl_t *impl = &SDL_rwlock_impl_generic;
|
||||
{
|
||||
HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
|
||||
if (kernel32) {
|
||||
@@ -197,7 +177,6 @@ SDL_RWLock *SDL_CreateRWLock(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_copyp(&SDL_rwlock_impl_active, impl);
|
||||
}
|
||||
|
@@ -60,18 +60,11 @@ static SDL_sem_impl_t SDL_sem_impl_active = { 0 };
|
||||
// APIs not available on WinPhone 8.1
|
||||
// https://www.microsoft.com/en-us/download/details.aspx?id=47328
|
||||
|
||||
#if !SDL_WINAPI_FAMILY_PHONE
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
// Functions are guaranteed to be available
|
||||
#define pWaitOnAddress WaitOnAddress
|
||||
#define pWakeByAddressSingle WakeByAddressSingle
|
||||
#else
|
||||
typedef BOOL(WINAPI *pfnWaitOnAddress)(volatile VOID *, PVOID, SIZE_T, DWORD);
|
||||
typedef VOID(WINAPI *pfnWakeByAddressSingle)(PVOID);
|
||||
|
||||
static pfnWaitOnAddress pWaitOnAddress = NULL;
|
||||
static pfnWakeByAddressSingle pWakeByAddressSingle = NULL;
|
||||
#endif
|
||||
|
||||
typedef struct SDL_semaphore_atom
|
||||
{
|
||||
@@ -196,7 +189,6 @@ static const SDL_sem_impl_t SDL_sem_impl_atom = {
|
||||
&SDL_GetSemaphoreValue_atom,
|
||||
&SDL_SignalSemaphore_atom,
|
||||
};
|
||||
#endif // !SDL_WINAPI_FAMILY_PHONE
|
||||
|
||||
/**
|
||||
* Fallback Semaphore implementation using Kernel Semaphores
|
||||
@@ -217,12 +209,7 @@ static SDL_Semaphore *SDL_CreateSemaphore_kern(Uint32 initial_value)
|
||||
sem = (SDL_sem_kern *)SDL_malloc(sizeof(*sem));
|
||||
if (sem) {
|
||||
// Create the semaphore, with max value 32K
|
||||
// !!! FIXME: CreateSemaphoreEx is available in Vista and later, so if XP support is dropped, we can lose this #ifdef.
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
sem->id = CreateSemaphoreEx(NULL, initial_value, 32 * 1024, NULL, 0, SEMAPHORE_ALL_ACCESS);
|
||||
#else
|
||||
sem->id = CreateSemaphore(NULL, initial_value, 32 * 1024, NULL);
|
||||
#endif
|
||||
sem->count = initial_value;
|
||||
if (!sem->id) {
|
||||
SDL_SetError("Couldn't create semaphore");
|
||||
@@ -316,12 +303,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
// Default to fallback implementation
|
||||
const SDL_sem_impl_t *impl = &SDL_sem_impl_kern;
|
||||
|
||||
#if !SDL_WINAPI_FAMILY_PHONE
|
||||
if (!SDL_GetHintBoolean(SDL_HINT_WINDOWS_FORCE_SEMAPHORE_KERNEL, false)) {
|
||||
#ifdef SDL_PLATFORM_WINRT
|
||||
// Link statically on this platform
|
||||
impl = &SDL_sem_impl_atom;
|
||||
#else
|
||||
/* We already statically link to features from this Api
|
||||
* Set (e.g. WaitForSingleObject). Dynamically loading
|
||||
* API Sets is not explicitly documented but according to
|
||||
@@ -338,9 +320,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
impl = &SDL_sem_impl_atom;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// Copy instead of using pointer to save one level of indirection
|
||||
SDL_copyp(&SDL_sem_impl_active, impl);
|
||||
|
@@ -109,7 +109,6 @@ void SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
if (name) {
|
||||
PVOID exceptionHandlerHandle;
|
||||
#ifndef SDL_PLATFORM_WINRT // !!! FIXME: There's no LoadLibrary() in WinRT; don't know if SetThreadDescription is available there at all at the moment.
|
||||
static pfnSetThreadDescription pSetThreadDescription = NULL;
|
||||
static HMODULE kernel32 = NULL;
|
||||
|
||||
@@ -133,7 +132,6 @@ void SDL_SYS_SetupThread(const char *name)
|
||||
SDL_free(strw);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Presumably some version of Visual Studio will understand SetThreadDescription(),
|
||||
but we still need to deal with older OSes and debuggers. Set it with the arcane
|
||||
|
@@ -27,18 +27,6 @@
|
||||
|
||||
#include "../SDL_thread_c.h"
|
||||
|
||||
#if WINAPI_FAMILY_WINRT
|
||||
#include <fibersapi.h>
|
||||
|
||||
#ifndef TLS_OUT_OF_INDEXES
|
||||
#define TLS_OUT_OF_INDEXES FLS_OUT_OF_INDEXES
|
||||
#endif
|
||||
|
||||
#define TlsAlloc() FlsAlloc(NULL)
|
||||
#define TlsSetValue FlsSetValue
|
||||
#define TlsGetValue FlsGetValue
|
||||
#endif
|
||||
|
||||
static DWORD thread_local_storage = TLS_OUT_OF_INDEXES;
|
||||
static bool generic_local_storage = false;
|
||||
|
||||
|
Reference in New Issue
Block a user