Update for SDL3 coding style (#6717)
I updated .clang-format and ran clang-format 14 over the src and test directories to standardize the code base. In general I let clang-format have it's way, and added markup to prevent formatting of code that would break or be completely unreadable if formatted. The script I ran for the src directory is added as build-scripts/clang-format-src.sh This fixes: #6592 #6593 #6594
This commit is contained in:
@@ -20,11 +20,10 @@
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
|
||||
#include "../generic/SDL_syscond_c.h"
|
||||
#include "SDL_sysmutex_c.h"
|
||||
|
||||
typedef SDL_cond * (*pfnSDL_CreateCond)(void);
|
||||
typedef SDL_cond *(*pfnSDL_CreateCond)(void);
|
||||
typedef void (*pfnSDL_DestroyCond)(SDL_cond *);
|
||||
typedef int (*pfnSDL_CondSignal)(SDL_cond *);
|
||||
typedef int (*pfnSDL_CondBroadcast)(SDL_cond *);
|
||||
@@ -33,39 +32,42 @@ typedef int (*pfnSDL_CondWaitTimeout)(SDL_cond *, SDL_mutex *, Uint32);
|
||||
|
||||
typedef struct SDL_cond_impl_t
|
||||
{
|
||||
pfnSDL_CreateCond Create;
|
||||
pfnSDL_DestroyCond Destroy;
|
||||
pfnSDL_CondSignal Signal;
|
||||
pfnSDL_CondBroadcast Broadcast;
|
||||
pfnSDL_CondWait Wait;
|
||||
pfnSDL_CondWaitTimeout WaitTimeout;
|
||||
pfnSDL_CreateCond Create;
|
||||
pfnSDL_DestroyCond Destroy;
|
||||
pfnSDL_CondSignal Signal;
|
||||
pfnSDL_CondBroadcast Broadcast;
|
||||
pfnSDL_CondWait Wait;
|
||||
pfnSDL_CondWaitTimeout WaitTimeout;
|
||||
} SDL_cond_impl_t;
|
||||
|
||||
/* Implementation will be chosen at runtime based on available Kernel features */
|
||||
static SDL_cond_impl_t SDL_cond_impl_active = {0};
|
||||
|
||||
static SDL_cond_impl_t SDL_cond_impl_active = { 0 };
|
||||
|
||||
/**
|
||||
* Native Windows Condition Variable (SRW Locks)
|
||||
*/
|
||||
|
||||
#ifndef CONDITION_VARIABLE_INIT
|
||||
#define CONDITION_VARIABLE_INIT {0}
|
||||
typedef struct CONDITION_VARIABLE {
|
||||
#define CONDITION_VARIABLE_INIT \
|
||||
{ \
|
||||
0 \
|
||||
}
|
||||
typedef struct CONDITION_VARIABLE
|
||||
{
|
||||
PVOID Ptr;
|
||||
} CONDITION_VARIABLE, *PCONDITION_VARIABLE;
|
||||
#endif
|
||||
|
||||
#if __WINRT__
|
||||
#define pWakeConditionVariable WakeConditionVariable
|
||||
#define pWakeAllConditionVariable WakeAllConditionVariable
|
||||
#define pWakeConditionVariable WakeConditionVariable
|
||||
#define pWakeAllConditionVariable WakeAllConditionVariable
|
||||
#define pSleepConditionVariableSRW SleepConditionVariableSRW
|
||||
#define pSleepConditionVariableCS SleepConditionVariableCS
|
||||
#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);
|
||||
typedef BOOL(WINAPI* pfnSleepConditionVariableCS)(PCONDITION_VARIABLE, PCRITICAL_SECTION, DWORD);
|
||||
typedef BOOL(WINAPI *pfnSleepConditionVariableCS)(PCONDITION_VARIABLE, PCRITICAL_SECTION, DWORD);
|
||||
|
||||
static pfnWakeConditionVariable pWakeConditionVariable = NULL;
|
||||
static pfnWakeAllConditionVariable pWakeAllConditionVariable = NULL;
|
||||
@@ -78,14 +80,12 @@ typedef struct SDL_cond_cv
|
||||
CONDITION_VARIABLE cond;
|
||||
} SDL_cond_cv;
|
||||
|
||||
|
||||
static SDL_cond *
|
||||
SDL_CreateCond_cv(void)
|
||||
static SDL_cond *SDL_CreateCond_cv(void)
|
||||
{
|
||||
SDL_cond_cv *cond;
|
||||
|
||||
/* Relies on CONDITION_VARIABLE_INIT == 0. */
|
||||
cond = (SDL_cond_cv *) SDL_calloc(1, sizeof(*cond));
|
||||
cond = (SDL_cond_cv *)SDL_calloc(1, sizeof(*cond));
|
||||
if (cond == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
@@ -93,8 +93,7 @@ SDL_CreateCond_cv(void)
|
||||
return (SDL_cond *)cond;
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_DestroyCond_cv(SDL_cond * cond)
|
||||
static void SDL_DestroyCond_cv(SDL_cond *cond)
|
||||
{
|
||||
if (cond != NULL) {
|
||||
/* There are no kernel allocated resources */
|
||||
@@ -102,8 +101,7 @@ SDL_DestroyCond_cv(SDL_cond * cond)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_CondSignal_cv(SDL_cond * _cond)
|
||||
static int SDL_CondSignal_cv(SDL_cond *_cond)
|
||||
{
|
||||
SDL_cond_cv *cond = (SDL_cond_cv *)_cond;
|
||||
if (cond == NULL) {
|
||||
@@ -115,8 +113,7 @@ SDL_CondSignal_cv(SDL_cond * _cond)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_CondBroadcast_cv(SDL_cond * _cond)
|
||||
static int SDL_CondBroadcast_cv(SDL_cond *_cond)
|
||||
{
|
||||
SDL_cond_cv *cond = (SDL_cond_cv *)_cond;
|
||||
if (cond == NULL) {
|
||||
@@ -128,8 +125,7 @@ SDL_CondBroadcast_cv(SDL_cond * _cond)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_CondWaitTimeout_cv(SDL_cond * _cond, SDL_mutex * _mutex, Uint32 ms)
|
||||
static int SDL_CondWaitTimeout_cv(SDL_cond *_cond, SDL_mutex *_mutex, Uint32 ms)
|
||||
{
|
||||
SDL_cond_cv *cond = (SDL_cond_cv *)_cond;
|
||||
DWORD timeout;
|
||||
@@ -145,7 +141,7 @@ SDL_CondWaitTimeout_cv(SDL_cond * _cond, SDL_mutex * _mutex, Uint32 ms)
|
||||
if (ms == SDL_MUTEX_MAXWAIT) {
|
||||
timeout = INFINITE;
|
||||
} else {
|
||||
timeout = (DWORD) ms;
|
||||
timeout = (DWORD)ms;
|
||||
}
|
||||
|
||||
if (SDL_mutex_impl_active.Type == SDL_MUTEX_SRW) {
|
||||
@@ -192,13 +188,12 @@ SDL_CondWaitTimeout_cv(SDL_cond * _cond, SDL_mutex * _mutex, Uint32 ms)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_CondWait_cv(SDL_cond * cond, SDL_mutex * mutex) {
|
||||
static int SDL_CondWait_cv(SDL_cond *cond, SDL_mutex *mutex)
|
||||
{
|
||||
return SDL_CondWaitTimeout_cv(cond, mutex, SDL_MUTEX_MAXWAIT);
|
||||
}
|
||||
|
||||
static const SDL_cond_impl_t SDL_cond_impl_cv =
|
||||
{
|
||||
static const SDL_cond_impl_t SDL_cond_impl_cv = {
|
||||
&SDL_CreateCond_cv,
|
||||
&SDL_DestroyCond_cv,
|
||||
&SDL_CondSignal_cv,
|
||||
@@ -211,8 +206,7 @@ static const SDL_cond_impl_t SDL_cond_impl_cv =
|
||||
* Generic Condition Variable implementation using SDL_mutex and SDL_sem
|
||||
*/
|
||||
|
||||
static const SDL_cond_impl_t SDL_cond_impl_generic =
|
||||
{
|
||||
static const SDL_cond_impl_t SDL_cond_impl_generic = {
|
||||
&SDL_CreateCond_generic,
|
||||
&SDL_DestroyCond_generic,
|
||||
&SDL_CondSignal_generic,
|
||||
@@ -221,13 +215,12 @@ static const SDL_cond_impl_t SDL_cond_impl_generic =
|
||||
&SDL_CondWaitTimeout_generic,
|
||||
};
|
||||
|
||||
|
||||
SDL_cond *
|
||||
SDL_CreateCond(void)
|
||||
{
|
||||
if (SDL_cond_impl_active.Create == NULL) {
|
||||
/* Default to generic implementation, works with all mutex implementations */
|
||||
const SDL_cond_impl_t * impl = &SDL_cond_impl_generic;
|
||||
const SDL_cond_impl_t *impl = &SDL_cond_impl_generic;
|
||||
|
||||
if (SDL_mutex_impl_active.Type == SDL_MUTEX_INVALID) {
|
||||
/* The mutex implementation isn't decided yet, trigger it */
|
||||
@@ -247,10 +240,10 @@ SDL_CreateCond(void)
|
||||
{
|
||||
HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
|
||||
if (kernel32) {
|
||||
pWakeConditionVariable = (pfnWakeConditionVariable) GetProcAddress(kernel32, "WakeConditionVariable");
|
||||
pWakeAllConditionVariable = (pfnWakeAllConditionVariable) GetProcAddress(kernel32, "WakeAllConditionVariable");
|
||||
pSleepConditionVariableSRW = (pfnSleepConditionVariableSRW) GetProcAddress(kernel32, "SleepConditionVariableSRW");
|
||||
pSleepConditionVariableCS = (pfnSleepConditionVariableCS) GetProcAddress(kernel32, "SleepConditionVariableCS");
|
||||
pWakeConditionVariable = (pfnWakeConditionVariable)GetProcAddress(kernel32, "WakeConditionVariable");
|
||||
pWakeAllConditionVariable = (pfnWakeAllConditionVariable)GetProcAddress(kernel32, "WakeAllConditionVariable");
|
||||
pSleepConditionVariableSRW = (pfnSleepConditionVariableSRW)GetProcAddress(kernel32, "SleepConditionVariableSRW");
|
||||
pSleepConditionVariableCS = (pfnSleepConditionVariableCS)GetProcAddress(kernel32, "SleepConditionVariableCS");
|
||||
if (pWakeConditionVariable && pWakeAllConditionVariable && pSleepConditionVariableSRW && pSleepConditionVariableCS) {
|
||||
/* Use the Windows provided API */
|
||||
impl = &SDL_cond_impl_cv;
|
||||
@@ -264,32 +257,27 @@ SDL_CreateCond(void)
|
||||
return SDL_cond_impl_active.Create();
|
||||
}
|
||||
|
||||
void
|
||||
SDL_DestroyCond(SDL_cond * cond)
|
||||
void SDL_DestroyCond(SDL_cond *cond)
|
||||
{
|
||||
SDL_cond_impl_active.Destroy(cond);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_CondSignal(SDL_cond * cond)
|
||||
int SDL_CondSignal(SDL_cond *cond)
|
||||
{
|
||||
return SDL_cond_impl_active.Signal(cond);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_CondBroadcast(SDL_cond * cond)
|
||||
int SDL_CondBroadcast(SDL_cond *cond)
|
||||
{
|
||||
return SDL_cond_impl_active.Broadcast(cond);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
|
||||
int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
|
||||
{
|
||||
return SDL_cond_impl_active.WaitTimeout(cond, mutex, ms);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
|
||||
int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex)
|
||||
{
|
||||
return SDL_cond_impl_active.Wait(cond, mutex);
|
||||
}
|
||||
|
||||
@@ -30,14 +30,10 @@
|
||||
* which are chosen at runtime.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "SDL_sysmutex_c.h"
|
||||
|
||||
|
||||
/* Implementation will be chosen at runtime based on available Kernel features */
|
||||
SDL_mutex_impl_t SDL_mutex_impl_active = {0};
|
||||
|
||||
SDL_mutex_impl_t SDL_mutex_impl_active = { 0 };
|
||||
|
||||
/**
|
||||
* Implementation based on Slim Reader/Writer (SRW) Locks for Win 7 and newer.
|
||||
@@ -45,8 +41,8 @@ SDL_mutex_impl_t SDL_mutex_impl_active = {0};
|
||||
|
||||
#if __WINRT__
|
||||
/* Functions are guaranteed to be available */
|
||||
#define pReleaseSRWLockExclusive ReleaseSRWLockExclusive
|
||||
#define pAcquireSRWLockExclusive AcquireSRWLockExclusive
|
||||
#define pReleaseSRWLockExclusive ReleaseSRWLockExclusive
|
||||
#define pAcquireSRWLockExclusive AcquireSRWLockExclusive
|
||||
#define pTryAcquireSRWLockExclusive TryAcquireSRWLockExclusive
|
||||
#else
|
||||
typedef VOID(WINAPI *pfnReleaseSRWLockExclusive)(PSRWLOCK);
|
||||
@@ -57,13 +53,12 @@ static pfnAcquireSRWLockExclusive pAcquireSRWLockExclusive = NULL;
|
||||
static pfnTryAcquireSRWLockExclusive pTryAcquireSRWLockExclusive = NULL;
|
||||
#endif
|
||||
|
||||
static SDL_mutex *
|
||||
SDL_CreateMutex_srw(void)
|
||||
static SDL_mutex *SDL_CreateMutex_srw(void)
|
||||
{
|
||||
SDL_mutex_srw *mutex;
|
||||
|
||||
/* Relies on SRWLOCK_INIT == 0. */
|
||||
mutex = (SDL_mutex_srw *) SDL_calloc(1, sizeof(*mutex));
|
||||
mutex = (SDL_mutex_srw *)SDL_calloc(1, sizeof(*mutex));
|
||||
if (mutex == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
@@ -71,8 +66,7 @@ SDL_CreateMutex_srw(void)
|
||||
return (SDL_mutex *)mutex;
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_DestroyMutex_srw(SDL_mutex * mutex)
|
||||
static void SDL_DestroyMutex_srw(SDL_mutex *mutex)
|
||||
{
|
||||
if (mutex != NULL) {
|
||||
/* There are no kernel allocated resources */
|
||||
@@ -80,8 +74,7 @@ SDL_DestroyMutex_srw(SDL_mutex * mutex)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_LockMutex_srw(SDL_mutex * _mutex)
|
||||
static int SDL_LockMutex_srw(SDL_mutex *_mutex)
|
||||
{
|
||||
SDL_mutex_srw *mutex = (SDL_mutex_srw *)_mutex;
|
||||
DWORD this_thread;
|
||||
@@ -106,8 +99,7 @@ SDL_LockMutex_srw(SDL_mutex * _mutex)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_TryLockMutex_srw(SDL_mutex * _mutex)
|
||||
static int SDL_TryLockMutex_srw(SDL_mutex *_mutex)
|
||||
{
|
||||
SDL_mutex_srw *mutex = (SDL_mutex_srw *)_mutex;
|
||||
DWORD this_thread;
|
||||
@@ -132,8 +124,7 @@ SDL_TryLockMutex_srw(SDL_mutex * _mutex)
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_UnlockMutex_srw(SDL_mutex * _mutex)
|
||||
static int SDL_UnlockMutex_srw(SDL_mutex *_mutex)
|
||||
{
|
||||
SDL_mutex_srw *mutex = (SDL_mutex_srw *)_mutex;
|
||||
|
||||
@@ -153,8 +144,7 @@ SDL_UnlockMutex_srw(SDL_mutex * _mutex)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const SDL_mutex_impl_t SDL_mutex_impl_srw =
|
||||
{
|
||||
static const SDL_mutex_impl_t SDL_mutex_impl_srw = {
|
||||
&SDL_CreateMutex_srw,
|
||||
&SDL_DestroyMutex_srw,
|
||||
&SDL_LockMutex_srw,
|
||||
@@ -163,19 +153,17 @@ static const SDL_mutex_impl_t SDL_mutex_impl_srw =
|
||||
SDL_MUTEX_SRW,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Fallback Mutex implementation using Critical Sections (before Win 7)
|
||||
*/
|
||||
|
||||
/* Create a mutex */
|
||||
static SDL_mutex *
|
||||
SDL_CreateMutex_cs(void)
|
||||
static SDL_mutex *SDL_CreateMutex_cs(void)
|
||||
{
|
||||
SDL_mutex_cs *mutex;
|
||||
|
||||
/* Allocate mutex memory */
|
||||
mutex = (SDL_mutex_cs *) SDL_malloc(sizeof(*mutex));
|
||||
mutex = (SDL_mutex_cs *)SDL_malloc(sizeof(*mutex));
|
||||
if (mutex != NULL) {
|
||||
/* Initialize */
|
||||
/* On SMP systems, a non-zero spin count generally helps performance */
|
||||
@@ -191,8 +179,7 @@ SDL_CreateMutex_cs(void)
|
||||
}
|
||||
|
||||
/* Free the mutex */
|
||||
static void
|
||||
SDL_DestroyMutex_cs(SDL_mutex * mutex_)
|
||||
static void SDL_DestroyMutex_cs(SDL_mutex *mutex_)
|
||||
{
|
||||
SDL_mutex_cs *mutex = (SDL_mutex_cs *)mutex_;
|
||||
if (mutex != NULL) {
|
||||
@@ -202,8 +189,7 @@ SDL_DestroyMutex_cs(SDL_mutex * mutex_)
|
||||
}
|
||||
|
||||
/* Lock the mutex */
|
||||
static int
|
||||
SDL_LockMutex_cs(SDL_mutex * mutex_)
|
||||
static int SDL_LockMutex_cs(SDL_mutex *mutex_)
|
||||
{
|
||||
SDL_mutex_cs *mutex = (SDL_mutex_cs *)mutex_;
|
||||
if (mutex == NULL) {
|
||||
@@ -215,8 +201,7 @@ SDL_LockMutex_cs(SDL_mutex * mutex_)
|
||||
}
|
||||
|
||||
/* TryLock the mutex */
|
||||
static int
|
||||
SDL_TryLockMutex_cs(SDL_mutex * mutex_)
|
||||
static int SDL_TryLockMutex_cs(SDL_mutex *mutex_)
|
||||
{
|
||||
SDL_mutex_cs *mutex = (SDL_mutex_cs *)mutex_;
|
||||
int retval = 0;
|
||||
@@ -231,8 +216,7 @@ SDL_TryLockMutex_cs(SDL_mutex * mutex_)
|
||||
}
|
||||
|
||||
/* Unlock the mutex */
|
||||
static int
|
||||
SDL_UnlockMutex_cs(SDL_mutex * mutex_)
|
||||
static int SDL_UnlockMutex_cs(SDL_mutex *mutex_)
|
||||
{
|
||||
SDL_mutex_cs *mutex = (SDL_mutex_cs *)mutex_;
|
||||
if (mutex == NULL) {
|
||||
@@ -243,8 +227,7 @@ SDL_UnlockMutex_cs(SDL_mutex * mutex_)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const SDL_mutex_impl_t SDL_mutex_impl_cs =
|
||||
{
|
||||
static const SDL_mutex_impl_t SDL_mutex_impl_cs = {
|
||||
&SDL_CreateMutex_cs,
|
||||
&SDL_DestroyMutex_cs,
|
||||
&SDL_LockMutex_cs,
|
||||
@@ -253,7 +236,6 @@ static const SDL_mutex_impl_t SDL_mutex_impl_cs =
|
||||
SDL_MUTEX_CS,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Runtime selection and redirection
|
||||
*/
|
||||
@@ -263,7 +245,7 @@ SDL_CreateMutex(void)
|
||||
{
|
||||
if (SDL_mutex_impl_active.Create == NULL) {
|
||||
/* Default to fallback implementation */
|
||||
const SDL_mutex_impl_t * impl = &SDL_mutex_impl_cs;
|
||||
const SDL_mutex_impl_t *impl = &SDL_mutex_impl_cs;
|
||||
|
||||
if (!SDL_GetHintBoolean(SDL_HINT_WINDOWS_FORCE_MUTEX_CRITICAL_SECTIONS, SDL_FALSE)) {
|
||||
#if __WINRT__
|
||||
@@ -274,10 +256,10 @@ SDL_CreateMutex(void)
|
||||
HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
|
||||
if (kernel32) {
|
||||
/* Requires Vista: */
|
||||
pReleaseSRWLockExclusive = (pfnReleaseSRWLockExclusive) GetProcAddress(kernel32, "ReleaseSRWLockExclusive");
|
||||
pAcquireSRWLockExclusive = (pfnAcquireSRWLockExclusive) GetProcAddress(kernel32, "AcquireSRWLockExclusive");
|
||||
pReleaseSRWLockExclusive = (pfnReleaseSRWLockExclusive)GetProcAddress(kernel32, "ReleaseSRWLockExclusive");
|
||||
pAcquireSRWLockExclusive = (pfnAcquireSRWLockExclusive)GetProcAddress(kernel32, "AcquireSRWLockExclusive");
|
||||
/* Requires 7: */
|
||||
pTryAcquireSRWLockExclusive = (pfnTryAcquireSRWLockExclusive) GetProcAddress(kernel32, "TryAcquireSRWLockExclusive");
|
||||
pTryAcquireSRWLockExclusive = (pfnTryAcquireSRWLockExclusive)GetProcAddress(kernel32, "TryAcquireSRWLockExclusive");
|
||||
if (pReleaseSRWLockExclusive && pAcquireSRWLockExclusive && pTryAcquireSRWLockExclusive) {
|
||||
impl = &SDL_mutex_impl_srw;
|
||||
}
|
||||
@@ -291,23 +273,23 @@ SDL_CreateMutex(void)
|
||||
return SDL_mutex_impl_active.Create();
|
||||
}
|
||||
|
||||
void
|
||||
SDL_DestroyMutex(SDL_mutex * mutex) {
|
||||
void SDL_DestroyMutex(SDL_mutex *mutex)
|
||||
{
|
||||
SDL_mutex_impl_active.Destroy(mutex);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_LockMutex(SDL_mutex * mutex) {
|
||||
int SDL_LockMutex(SDL_mutex *mutex)
|
||||
{
|
||||
return SDL_mutex_impl_active.Lock(mutex);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_TryLockMutex(SDL_mutex * mutex) {
|
||||
int SDL_TryLockMutex(SDL_mutex *mutex)
|
||||
{
|
||||
return SDL_mutex_impl_active.TryLock(mutex);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_UnlockMutex(SDL_mutex * mutex) {
|
||||
int SDL_UnlockMutex(SDL_mutex *mutex)
|
||||
{
|
||||
return SDL_mutex_impl_active.Unlock(mutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,8 +22,7 @@
|
||||
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
|
||||
|
||||
typedef SDL_mutex * (*pfnSDL_CreateMutex)(void);
|
||||
typedef SDL_mutex *(*pfnSDL_CreateMutex)(void);
|
||||
typedef int (*pfnSDL_LockMutex)(SDL_mutex *);
|
||||
typedef int (*pfnSDL_TryLockMutex)(SDL_mutex *);
|
||||
typedef int (*pfnSDL_UnlockMutex)(SDL_mutex *);
|
||||
@@ -38,21 +37,24 @@ typedef enum
|
||||
|
||||
typedef struct SDL_mutex_impl_t
|
||||
{
|
||||
pfnSDL_CreateMutex Create;
|
||||
pfnSDL_CreateMutex Create;
|
||||
pfnSDL_DestroyMutex Destroy;
|
||||
pfnSDL_LockMutex Lock;
|
||||
pfnSDL_LockMutex Lock;
|
||||
pfnSDL_TryLockMutex TryLock;
|
||||
pfnSDL_UnlockMutex Unlock;
|
||||
pfnSDL_UnlockMutex Unlock;
|
||||
/* Needed by SDL_cond: */
|
||||
SDL_MutexType Type;
|
||||
SDL_MutexType Type;
|
||||
} SDL_mutex_impl_t;
|
||||
|
||||
extern SDL_mutex_impl_t SDL_mutex_impl_active;
|
||||
|
||||
|
||||
#ifndef SRWLOCK_INIT
|
||||
#define SRWLOCK_INIT {0}
|
||||
typedef struct _SRWLOCK {
|
||||
#define SRWLOCK_INIT \
|
||||
{ \
|
||||
0 \
|
||||
}
|
||||
typedef struct _SRWLOCK
|
||||
{
|
||||
PVOID Ptr;
|
||||
} SRWLOCK, *PSRWLOCK;
|
||||
#endif
|
||||
|
||||
@@ -31,12 +31,11 @@
|
||||
* Faster due to significantly less context switches.
|
||||
* Requires Windows 8 or newer.
|
||||
* which are chosen at runtime.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
|
||||
|
||||
typedef SDL_sem * (*pfnSDL_CreateSemaphore)(Uint32);
|
||||
typedef SDL_sem *(*pfnSDL_CreateSemaphore)(Uint32);
|
||||
typedef void (*pfnSDL_DestroySemaphore)(SDL_sem *);
|
||||
typedef int (*pfnSDL_SemWaitTimeout)(SDL_sem *, Uint32);
|
||||
typedef int (*pfnSDL_SemTryWait)(SDL_sem *);
|
||||
@@ -46,18 +45,17 @@ typedef int (*pfnSDL_SemPost)(SDL_sem *);
|
||||
|
||||
typedef struct SDL_semaphore_impl_t
|
||||
{
|
||||
pfnSDL_CreateSemaphore Create;
|
||||
pfnSDL_CreateSemaphore Create;
|
||||
pfnSDL_DestroySemaphore Destroy;
|
||||
pfnSDL_SemWaitTimeout WaitTimeout;
|
||||
pfnSDL_SemTryWait TryWait;
|
||||
pfnSDL_SemWait Wait;
|
||||
pfnSDL_SemValue Value;
|
||||
pfnSDL_SemPost Post;
|
||||
pfnSDL_SemWaitTimeout WaitTimeout;
|
||||
pfnSDL_SemTryWait TryWait;
|
||||
pfnSDL_SemWait Wait;
|
||||
pfnSDL_SemValue Value;
|
||||
pfnSDL_SemPost Post;
|
||||
} SDL_sem_impl_t;
|
||||
|
||||
/* Implementation will be chosen at runtime based on available Kernel features */
|
||||
static SDL_sem_impl_t SDL_sem_impl_active = {0};
|
||||
|
||||
static SDL_sem_impl_t SDL_sem_impl_active = { 0 };
|
||||
|
||||
/**
|
||||
* Atomic + WaitOnAddress implementation
|
||||
@@ -67,7 +65,7 @@ static SDL_sem_impl_t SDL_sem_impl_active = {0};
|
||||
/* https://www.microsoft.com/en-us/download/details.aspx?id=47328 */
|
||||
|
||||
#if (HAVE_WINAPIFAMILY_H) && defined(WINAPI_FAMILY_PHONE_APP)
|
||||
#define SDL_WINAPI_FAMILY_PHONE (WINAPI_FAMILY==WINAPI_FAMILY_PHONE_APP)
|
||||
#define SDL_WINAPI_FAMILY_PHONE (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
|
||||
#else
|
||||
#define SDL_WINAPI_FAMILY_PHONE 0
|
||||
#endif
|
||||
@@ -75,10 +73,10 @@ static SDL_sem_impl_t SDL_sem_impl_active = {0};
|
||||
#if !SDL_WINAPI_FAMILY_PHONE
|
||||
#if __WINRT__
|
||||
/* Functions are guaranteed to be available */
|
||||
#define pWaitOnAddress WaitOnAddress
|
||||
#define pWaitOnAddress WaitOnAddress
|
||||
#define pWakeByAddressSingle WakeByAddressSingle
|
||||
#else
|
||||
typedef BOOL(WINAPI *pfnWaitOnAddress)(volatile VOID*, PVOID, SIZE_T, DWORD);
|
||||
typedef BOOL(WINAPI *pfnWaitOnAddress)(volatile VOID *, PVOID, SIZE_T, DWORD);
|
||||
typedef VOID(WINAPI *pfnWakeByAddressSingle)(PVOID);
|
||||
|
||||
static pfnWaitOnAddress pWaitOnAddress = NULL;
|
||||
@@ -90,12 +88,11 @@ typedef struct SDL_semaphore_atom
|
||||
LONG count;
|
||||
} SDL_sem_atom;
|
||||
|
||||
static SDL_sem *
|
||||
SDL_CreateSemaphore_atom(Uint32 initial_value)
|
||||
static SDL_sem *SDL_CreateSemaphore_atom(Uint32 initial_value)
|
||||
{
|
||||
SDL_sem_atom *sem;
|
||||
|
||||
sem = (SDL_sem_atom *) SDL_malloc(sizeof(*sem));
|
||||
sem = (SDL_sem_atom *)SDL_malloc(sizeof(*sem));
|
||||
if (sem != NULL) {
|
||||
sem->count = initial_value;
|
||||
} else {
|
||||
@@ -104,16 +101,14 @@ SDL_CreateSemaphore_atom(Uint32 initial_value)
|
||||
return (SDL_sem *)sem;
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_DestroySemaphore_atom(SDL_sem * sem)
|
||||
static void SDL_DestroySemaphore_atom(SDL_sem *sem)
|
||||
{
|
||||
if (sem != NULL) {
|
||||
SDL_free(sem);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_SemTryWait_atom(SDL_sem * _sem)
|
||||
static int SDL_SemTryWait_atom(SDL_sem *_sem)
|
||||
{
|
||||
SDL_sem_atom *sem = (SDL_sem_atom *)_sem;
|
||||
LONG count;
|
||||
@@ -134,8 +129,7 @@ SDL_SemTryWait_atom(SDL_sem * _sem)
|
||||
return SDL_MUTEX_TIMEDOUT;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_SemWait_atom(SDL_sem * _sem)
|
||||
static int SDL_SemWait_atom(SDL_sem *_sem)
|
||||
{
|
||||
SDL_sem_atom *sem = (SDL_sem_atom *)_sem;
|
||||
LONG count;
|
||||
@@ -159,8 +153,7 @@ SDL_SemWait_atom(SDL_sem * _sem)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_SemWaitTimeout_atom(SDL_sem * _sem, Uint32 timeout)
|
||||
static int SDL_SemWaitTimeout_atom(SDL_sem *_sem, Uint32 timeout)
|
||||
{
|
||||
SDL_sem_atom *sem = (SDL_sem_atom *)_sem;
|
||||
LONG count;
|
||||
@@ -181,7 +174,7 @@ SDL_SemWaitTimeout_atom(SDL_sem * _sem, Uint32 timeout)
|
||||
* need to recalculate the effective timeout before every wait
|
||||
*/
|
||||
now = SDL_GetTicks();
|
||||
deadline = now + (DWORD) timeout;
|
||||
deadline = now + (DWORD)timeout;
|
||||
|
||||
for (;;) {
|
||||
count = sem->count;
|
||||
@@ -210,8 +203,7 @@ SDL_SemWaitTimeout_atom(SDL_sem * _sem, Uint32 timeout)
|
||||
}
|
||||
}
|
||||
|
||||
static Uint32
|
||||
SDL_SemValue_atom(SDL_sem * _sem)
|
||||
static Uint32 SDL_SemValue_atom(SDL_sem *_sem)
|
||||
{
|
||||
SDL_sem_atom *sem = (SDL_sem_atom *)_sem;
|
||||
|
||||
@@ -223,8 +215,7 @@ SDL_SemValue_atom(SDL_sem * _sem)
|
||||
return (Uint32)sem->count;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_SemPost_atom(SDL_sem * _sem)
|
||||
static int SDL_SemPost_atom(SDL_sem *_sem)
|
||||
{
|
||||
SDL_sem_atom *sem = (SDL_sem_atom *)_sem;
|
||||
|
||||
@@ -238,8 +229,7 @@ SDL_SemPost_atom(SDL_sem * _sem)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const SDL_sem_impl_t SDL_sem_impl_atom =
|
||||
{
|
||||
static const SDL_sem_impl_t SDL_sem_impl_atom = {
|
||||
&SDL_CreateSemaphore_atom,
|
||||
&SDL_DestroySemaphore_atom,
|
||||
&SDL_SemWaitTimeout_atom,
|
||||
@@ -250,7 +240,6 @@ static const SDL_sem_impl_t SDL_sem_impl_atom =
|
||||
};
|
||||
#endif /* !SDL_WINAPI_FAMILY_PHONE */
|
||||
|
||||
|
||||
/**
|
||||
* Fallback Semaphore implementation using Kernel Semaphores
|
||||
*/
|
||||
@@ -262,13 +251,12 @@ typedef struct SDL_semaphore_kern
|
||||
} SDL_sem_kern;
|
||||
|
||||
/* Create a semaphore */
|
||||
static SDL_sem *
|
||||
SDL_CreateSemaphore_kern(Uint32 initial_value)
|
||||
static SDL_sem *SDL_CreateSemaphore_kern(Uint32 initial_value)
|
||||
{
|
||||
SDL_sem_kern *sem;
|
||||
|
||||
/* Allocate sem memory */
|
||||
sem = (SDL_sem_kern *) SDL_malloc(sizeof(*sem));
|
||||
sem = (SDL_sem_kern *)SDL_malloc(sizeof(*sem));
|
||||
if (sem != NULL) {
|
||||
/* Create the semaphore, with max value 32K */
|
||||
#if __WINRT__
|
||||
@@ -289,8 +277,7 @@ SDL_CreateSemaphore_kern(Uint32 initial_value)
|
||||
}
|
||||
|
||||
/* Free the semaphore */
|
||||
static void
|
||||
SDL_DestroySemaphore_kern(SDL_sem * _sem)
|
||||
static void SDL_DestroySemaphore_kern(SDL_sem *_sem)
|
||||
{
|
||||
SDL_sem_kern *sem = (SDL_sem_kern *)_sem;
|
||||
if (sem != NULL) {
|
||||
@@ -302,8 +289,7 @@ SDL_DestroySemaphore_kern(SDL_sem * _sem)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_SemWaitTimeout_kern(SDL_sem * _sem, Uint32 timeout)
|
||||
static int SDL_SemWaitTimeout_kern(SDL_sem *_sem, Uint32 timeout)
|
||||
{
|
||||
SDL_sem_kern *sem = (SDL_sem_kern *)_sem;
|
||||
int retval;
|
||||
@@ -316,7 +302,7 @@ SDL_SemWaitTimeout_kern(SDL_sem * _sem, Uint32 timeout)
|
||||
if (timeout == SDL_MUTEX_MAXWAIT) {
|
||||
dwMilliseconds = INFINITE;
|
||||
} else {
|
||||
dwMilliseconds = (DWORD) timeout;
|
||||
dwMilliseconds = (DWORD)timeout;
|
||||
}
|
||||
switch (WaitForSingleObjectEx(sem->id, dwMilliseconds, FALSE)) {
|
||||
case WAIT_OBJECT_0:
|
||||
@@ -333,21 +319,18 @@ SDL_SemWaitTimeout_kern(SDL_sem * _sem, Uint32 timeout)
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_SemTryWait_kern(SDL_sem * sem)
|
||||
static int SDL_SemTryWait_kern(SDL_sem *sem)
|
||||
{
|
||||
return SDL_SemWaitTimeout_kern(sem, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_SemWait_kern(SDL_sem * sem)
|
||||
static int SDL_SemWait_kern(SDL_sem *sem)
|
||||
{
|
||||
return SDL_SemWaitTimeout_kern(sem, SDL_MUTEX_MAXWAIT);
|
||||
}
|
||||
|
||||
/* Returns the current count of the semaphore */
|
||||
static Uint32
|
||||
SDL_SemValue_kern(SDL_sem * _sem)
|
||||
static Uint32 SDL_SemValue_kern(SDL_sem *_sem)
|
||||
{
|
||||
SDL_sem_kern *sem = (SDL_sem_kern *)_sem;
|
||||
if (sem == NULL) {
|
||||
@@ -357,8 +340,7 @@ SDL_SemValue_kern(SDL_sem * _sem)
|
||||
return (Uint32)sem->count;
|
||||
}
|
||||
|
||||
static int
|
||||
SDL_SemPost_kern(SDL_sem * _sem)
|
||||
static int SDL_SemPost_kern(SDL_sem *_sem)
|
||||
{
|
||||
SDL_sem_kern *sem = (SDL_sem_kern *)_sem;
|
||||
if (sem == NULL) {
|
||||
@@ -371,14 +353,13 @@ SDL_SemPost_kern(SDL_sem * _sem)
|
||||
*/
|
||||
InterlockedIncrement(&sem->count);
|
||||
if (ReleaseSemaphore(sem->id, 1, NULL) == FALSE) {
|
||||
InterlockedDecrement(&sem->count); /* restore */
|
||||
InterlockedDecrement(&sem->count); /* restore */
|
||||
return SDL_SetError("ReleaseSemaphore() failed");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const SDL_sem_impl_t SDL_sem_impl_kern =
|
||||
{
|
||||
static const SDL_sem_impl_t SDL_sem_impl_kern = {
|
||||
&SDL_CreateSemaphore_kern,
|
||||
&SDL_DestroySemaphore_kern,
|
||||
&SDL_SemWaitTimeout_kern,
|
||||
@@ -388,7 +369,6 @@ static const SDL_sem_impl_t SDL_sem_impl_kern =
|
||||
&SDL_SemPost_kern,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Runtime selection and redirection
|
||||
*/
|
||||
@@ -398,7 +378,7 @@ SDL_CreateSemaphore(Uint32 initial_value)
|
||||
{
|
||||
if (SDL_sem_impl_active.Create == NULL) {
|
||||
/* Default to fallback implementation */
|
||||
const SDL_sem_impl_t * impl = &SDL_sem_impl_kern;
|
||||
const SDL_sem_impl_t *impl = &SDL_sem_impl_kern;
|
||||
|
||||
#if !SDL_WINAPI_FAMILY_PHONE
|
||||
if (!SDL_GetHintBoolean(SDL_HINT_WINDOWS_FORCE_SEMAPHORE_KERNEL, SDL_FALSE)) {
|
||||
@@ -415,8 +395,8 @@ SDL_CreateSemaphore(Uint32 initial_value)
|
||||
HMODULE synch120 = GetModuleHandle(TEXT("api-ms-win-core-synch-l1-2-0.dll"));
|
||||
if (synch120) {
|
||||
/* Try to load required functions provided by Win 8 or newer */
|
||||
pWaitOnAddress = (pfnWaitOnAddress) GetProcAddress(synch120, "WaitOnAddress");
|
||||
pWakeByAddressSingle = (pfnWakeByAddressSingle) GetProcAddress(synch120, "WakeByAddressSingle");
|
||||
pWaitOnAddress = (pfnWaitOnAddress)GetProcAddress(synch120, "WaitOnAddress");
|
||||
pWakeByAddressSingle = (pfnWakeByAddressSingle)GetProcAddress(synch120, "WakeByAddressSingle");
|
||||
|
||||
if (pWaitOnAddress && pWakeByAddressSingle) {
|
||||
impl = &SDL_sem_impl_atom;
|
||||
@@ -432,38 +412,33 @@ SDL_CreateSemaphore(Uint32 initial_value)
|
||||
return SDL_sem_impl_active.Create(initial_value);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_DestroySemaphore(SDL_sem * sem)
|
||||
void SDL_DestroySemaphore(SDL_sem *sem)
|
||||
{
|
||||
SDL_sem_impl_active.Destroy(sem);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
|
||||
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
|
||||
{
|
||||
return SDL_sem_impl_active.WaitTimeout(sem, timeout);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemTryWait(SDL_sem * sem)
|
||||
int SDL_SemTryWait(SDL_sem *sem)
|
||||
{
|
||||
return SDL_sem_impl_active.TryWait(sem);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemWait(SDL_sem * sem)
|
||||
int SDL_SemWait(SDL_sem *sem)
|
||||
{
|
||||
return SDL_sem_impl_active.Wait(sem);
|
||||
}
|
||||
|
||||
Uint32
|
||||
SDL_SemValue(SDL_sem * sem)
|
||||
SDL_SemValue(SDL_sem *sem)
|
||||
{
|
||||
return SDL_sem_impl_active.Value(sem);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemPost(SDL_sem * sem)
|
||||
int SDL_SemPost(SDL_sem *sem)
|
||||
{
|
||||
return SDL_sem_impl_active.Post(sem);
|
||||
}
|
||||
|
||||
@@ -38,28 +38,26 @@
|
||||
|
||||
/* Cygwin gcc-3 ... MingW64 (even with a i386 host) does this like MSVC. */
|
||||
#if (defined(__MINGW32__) && (__GNUC__ < 4))
|
||||
typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
|
||||
unsigned (__stdcall *func)(void *), void *arg,
|
||||
unsigned, unsigned *threadID);
|
||||
typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
|
||||
typedef unsigned long(__cdecl *pfnSDL_CurrentBeginThread)(void *, unsigned,
|
||||
unsigned(__stdcall *func)(void *), void *arg,
|
||||
unsigned, unsigned *threadID);
|
||||
typedef void(__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
|
||||
|
||||
#else
|
||||
typedef uintptr_t(__cdecl * pfnSDL_CurrentBeginThread) (void *, unsigned,
|
||||
unsigned (__stdcall *
|
||||
func) (void
|
||||
*),
|
||||
void *arg, unsigned,
|
||||
unsigned *threadID);
|
||||
typedef void (__cdecl * pfnSDL_CurrentEndThread) (unsigned code);
|
||||
typedef uintptr_t(__cdecl *pfnSDL_CurrentBeginThread)(void *, unsigned,
|
||||
unsigned(__stdcall *
|
||||
func)(void
|
||||
*),
|
||||
void *arg, unsigned,
|
||||
unsigned *threadID);
|
||||
typedef void(__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
|
||||
#endif
|
||||
#endif /* !SDL_PASSED_BEGINTHREAD_ENDTHREAD */
|
||||
|
||||
|
||||
static DWORD
|
||||
RunThread(void *data)
|
||||
static DWORD RunThread(void *data)
|
||||
{
|
||||
SDL_Thread *thread = (SDL_Thread *) data;
|
||||
pfnSDL_CurrentEndThread pfnEndThread = (pfnSDL_CurrentEndThread) thread->endfunc;
|
||||
SDL_Thread *thread = (SDL_Thread *)data;
|
||||
pfnSDL_CurrentEndThread pfnEndThread = (pfnSDL_CurrentEndThread)thread->endfunc;
|
||||
SDL_RunThread(thread);
|
||||
if (pfnEndThread != NULL) {
|
||||
pfnEndThread(0);
|
||||
@@ -67,33 +65,28 @@ RunThread(void *data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static DWORD WINAPI
|
||||
RunThreadViaCreateThread(LPVOID data)
|
||||
static DWORD WINAPI RunThreadViaCreateThread(LPVOID data)
|
||||
{
|
||||
return RunThread(data);
|
||||
return RunThread(data);
|
||||
}
|
||||
|
||||
static unsigned __stdcall
|
||||
RunThreadViaBeginThreadEx(void *data)
|
||||
static unsigned __stdcall RunThreadViaBeginThreadEx(void *data)
|
||||
{
|
||||
return (unsigned)RunThread(data);
|
||||
return (unsigned)RunThread(data);
|
||||
}
|
||||
|
||||
#ifdef SDL_PASSED_BEGINTHREAD_ENDTHREAD
|
||||
int
|
||||
SDL_SYS_CreateThread(SDL_Thread * thread,
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread,
|
||||
pfnSDL_CurrentEndThread pfnEndThread)
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread,
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread,
|
||||
pfnSDL_CurrentEndThread pfnEndThread)
|
||||
{
|
||||
#elif defined(__CYGWIN__) || defined(__WINRT__)
|
||||
int
|
||||
SDL_SYS_CreateThread(SDL_Thread * thread)
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
{
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread = NULL;
|
||||
pfnSDL_CurrentEndThread pfnEndThread = NULL;
|
||||
#else
|
||||
int
|
||||
SDL_SYS_CreateThread(SDL_Thread * thread)
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
{
|
||||
pfnSDL_CurrentBeginThread pfnBeginThread = (pfnSDL_CurrentBeginThread)_beginthreadex;
|
||||
pfnSDL_CurrentEndThread pfnEndThread = (pfnSDL_CurrentEndThread)_endthreadex;
|
||||
@@ -106,10 +99,9 @@ SDL_SYS_CreateThread(SDL_Thread * thread)
|
||||
/* thread->stacksize == 0 means "system default", same as win32 expects */
|
||||
if (pfnBeginThread) {
|
||||
unsigned threadid = 0;
|
||||
thread->handle = (SYS_ThreadHandle)
|
||||
((size_t) pfnBeginThread(NULL, (unsigned int) thread->stacksize,
|
||||
RunThreadViaBeginThreadEx,
|
||||
thread, flags, &threadid));
|
||||
thread->handle = (SYS_ThreadHandle)((size_t)pfnBeginThread(NULL, (unsigned int)thread->stacksize,
|
||||
RunThreadViaBeginThreadEx,
|
||||
thread, flags, &threadid));
|
||||
} else {
|
||||
DWORD threadid = 0;
|
||||
thread->handle = CreateThread(NULL, thread->stacksize,
|
||||
@@ -122,31 +114,29 @@ SDL_SYS_CreateThread(SDL_Thread * thread)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#pragma pack(push,8)
|
||||
#pragma pack(push, 8)
|
||||
typedef struct tagTHREADNAME_INFO
|
||||
{
|
||||
DWORD dwType; /* must be 0x1000 */
|
||||
LPCSTR szName; /* pointer to name (in user addr space) */
|
||||
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 */
|
||||
DWORD dwFlags; /* reserved for future use, must be zero */
|
||||
} THREADNAME_INFO;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef HRESULT(WINAPI *pfnSetThreadDescription)(HANDLE, PCWSTR);
|
||||
|
||||
typedef HRESULT (WINAPI *pfnSetThreadDescription)(HANDLE, PCWSTR);
|
||||
|
||||
void
|
||||
SDL_SYS_SetupThread(const char *name)
|
||||
void SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
if (name != NULL) {
|
||||
#ifndef __WINRT__ /* !!! FIXME: There's no LoadLibrary() in WinRT; don't know if SetThreadDescription is available there at all at the moment. */
|
||||
#ifndef __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 = 0;
|
||||
|
||||
if (!kernel32) {
|
||||
kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
|
||||
if (kernel32) {
|
||||
pSetThreadDescription = (pfnSetThreadDescription) GetProcAddress(kernel32, "SetThreadDescription");
|
||||
pSetThreadDescription = (pfnSetThreadDescription)GetProcAddress(kernel32, "SetThreadDescription");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +147,7 @@ SDL_SYS_SetupThread(const char *name)
|
||||
SDL_free(strw);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#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
|
||||
@@ -175,11 +165,11 @@ SDL_SYS_SetupThread(const char *name)
|
||||
SDL_zero(inf);
|
||||
inf.dwType = 0x1000;
|
||||
inf.szName = name;
|
||||
inf.dwThreadID = (DWORD) -1;
|
||||
inf.dwThreadID = (DWORD)-1;
|
||||
inf.dwFlags = 0;
|
||||
|
||||
/* The debugger catches this, renames the thread, continues on. */
|
||||
RaiseException(0x406D1388, 0, sizeof(inf) / sizeof(ULONG), (const ULONG_PTR*) &inf);
|
||||
RaiseException(0x406D1388, 0, sizeof(inf) / sizeof(ULONG), (const ULONG_PTR *)&inf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,8 +180,7 @@ SDL_ThreadID(void)
|
||||
return (SDL_threadID)GetCurrentThreadId();
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
{
|
||||
int value;
|
||||
|
||||
@@ -210,15 +199,13 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_WaitThread(SDL_Thread * thread)
|
||||
void SDL_SYS_WaitThread(SDL_Thread *thread)
|
||||
{
|
||||
WaitForSingleObjectEx(thread->handle, INFINITE, FALSE);
|
||||
CloseHandle(thread->handle);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_DetachThread(SDL_Thread * thread)
|
||||
void SDL_SYS_DetachThread(SDL_Thread *thread)
|
||||
{
|
||||
CloseHandle(thread->handle);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include <fibersapi.h>
|
||||
|
||||
#ifndef TLS_OUT_OF_INDEXES
|
||||
#define TLS_OUT_OF_INDEXES FLS_OUT_OF_INDEXES
|
||||
#define TLS_OUT_OF_INDEXES FLS_OUT_OF_INDEXES
|
||||
#endif
|
||||
|
||||
#define TlsAlloc() FlsAlloc(NULL)
|
||||
@@ -66,8 +66,7 @@ SDL_SYS_GetTLSData(void)
|
||||
return (SDL_TLSData *)TlsGetValue(thread_local_storage);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_SetTLSData(SDL_TLSData *data)
|
||||
int SDL_SYS_SetTLSData(SDL_TLSData *data)
|
||||
{
|
||||
if (generic_local_storage) {
|
||||
return SDL_Generic_SetTLSData(data);
|
||||
|
||||
Reference in New Issue
Block a user