mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-18 07:41:45 +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:
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user