mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-02 16:08:30 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user