mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-03 16:36:25 +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:
@@ -20,13 +20,12 @@
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1500)
|
||||
#include <intrin.h>
|
||||
#define HAVE_MSC_ATOMICS 1
|
||||
#endif
|
||||
|
||||
#if defined(__MACOS__) /* !!! FIXME: should we favor gcc atomics? */
|
||||
#if defined(__MACOS__) /* !!! FIXME: should we favor gcc atomics? */
|
||||
#include <libkern/OSAtomic.h>
|
||||
#endif
|
||||
|
||||
@@ -36,19 +35,20 @@
|
||||
|
||||
/* The __atomic_load_n() intrinsic showed up in different times for different compilers. */
|
||||
#if defined(__clang__)
|
||||
# if __has_builtin(__atomic_load_n) || defined(HAVE_GCC_ATOMICS)
|
||||
/* !!! FIXME: this advertises as available in the NDK but uses an external symbol we don't have.
|
||||
It might be in a later NDK or we might need an extra library? --ryan. */
|
||||
# if !defined(__ANDROID__)
|
||||
# define HAVE_ATOMIC_LOAD_N 1
|
||||
# endif
|
||||
# endif
|
||||
#if __has_builtin(__atomic_load_n) || defined(HAVE_GCC_ATOMICS)
|
||||
/* !!! FIXME: this advertises as available in the NDK but uses an external symbol we don't have.
|
||||
It might be in a later NDK or we might need an extra library? --ryan. */
|
||||
#if !defined(__ANDROID__)
|
||||
#define HAVE_ATOMIC_LOAD_N 1
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(__GNUC__)
|
||||
# if (__GNUC__ >= 5)
|
||||
# define HAVE_ATOMIC_LOAD_N 1
|
||||
# endif
|
||||
#if (__GNUC__ >= 5)
|
||||
#define HAVE_ATOMIC_LOAD_N 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* *INDENT-OFF* */ /* clang-format off */
|
||||
#if defined(__WATCOMC__) && defined(__386__)
|
||||
SDL_COMPILE_TIME_ASSERT(intsize, 4==sizeof(int));
|
||||
#define HAVE_WATCOM_ATOMICS
|
||||
@@ -73,7 +73,9 @@ extern __inline int _SDL_xadd_watcom(volatile int *a, int v);
|
||||
parm [ecx] [eax] \
|
||||
value [eax] \
|
||||
modify exact [eax];
|
||||
|
||||
#endif /* __WATCOMC__ && __386__ */
|
||||
/* *INDENT-ON* */ /* clang-format on */
|
||||
|
||||
/*
|
||||
If any of the operations are not provided then we must emulate some
|
||||
@@ -105,16 +107,14 @@ extern __inline int _SDL_xadd_watcom(volatile int *a, int v);
|
||||
#if EMULATE_CAS
|
||||
static SDL_SpinLock locks[32];
|
||||
|
||||
static SDL_INLINE void
|
||||
enterLock(void *a)
|
||||
static SDL_INLINE void enterLock(void *a)
|
||||
{
|
||||
uintptr_t index = ((((uintptr_t)a) >> 3) & 0x1f);
|
||||
|
||||
SDL_AtomicLock(&locks[index]);
|
||||
}
|
||||
|
||||
static SDL_INLINE void
|
||||
leaveLock(void *a)
|
||||
static SDL_INLINE void leaveLock(void *a)
|
||||
{
|
||||
uintptr_t index = ((((uintptr_t)a) >> 3) & 0x1f);
|
||||
|
||||
@@ -122,7 +122,6 @@ leaveLock(void *a)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
SDL_bool
|
||||
SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval)
|
||||
{
|
||||
@@ -132,9 +131,9 @@ SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval)
|
||||
#elif defined(HAVE_WATCOM_ATOMICS)
|
||||
return (SDL_bool)_SDL_cmpxchg_watcom(&a->value, newval, oldval);
|
||||
#elif defined(HAVE_GCC_ATOMICS)
|
||||
return (SDL_bool) __sync_bool_compare_and_swap(&a->value, oldval, newval);
|
||||
return (SDL_bool)__sync_bool_compare_and_swap(&a->value, oldval, newval);
|
||||
#elif defined(__MACOS__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
|
||||
return (SDL_bool) OSAtomicCompareAndSwap32Barrier(oldval, newval, &a->value);
|
||||
return (SDL_bool)OSAtomicCompareAndSwap32Barrier(oldval, newval, &a->value);
|
||||
#elif defined(__SOLARIS__)
|
||||
return (SDL_bool)((int)atomic_cas_uint((volatile uint_t *)&a->value, (uint_t)oldval, (uint_t)newval) == oldval);
|
||||
#elif EMULATE_CAS
|
||||
@@ -149,7 +148,7 @@ SDL_AtomicCAS(SDL_atomic_t *a, int oldval, int newval)
|
||||
|
||||
return retval;
|
||||
#else
|
||||
#error Please define your platform.
|
||||
#error Please define your platform.
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -162,10 +161,10 @@ SDL_AtomicCASPtr(void **a, void *oldval, void *newval)
|
||||
return (SDL_bool)_SDL_cmpxchg_watcom((int *)a, (long)newval, (long)oldval);
|
||||
#elif defined(HAVE_GCC_ATOMICS)
|
||||
return __sync_bool_compare_and_swap(a, oldval, newval);
|
||||
#elif defined(__MACOS__) && defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
|
||||
return (SDL_bool) OSAtomicCompareAndSwap64Barrier((int64_t)oldval, (int64_t)newval, (int64_t*) a);
|
||||
#elif defined(__MACOS__) && defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
|
||||
return (SDL_bool)OSAtomicCompareAndSwap64Barrier((int64_t)oldval, (int64_t)newval, (int64_t *)a);
|
||||
#elif defined(__MACOS__) && !defined(__LP64__) /* this is deprecated in 10.12 sdk; favor gcc atomics. */
|
||||
return (SDL_bool) OSAtomicCompareAndSwap32Barrier((int32_t)oldval, (int32_t)newval, (int32_t*) a);
|
||||
return (SDL_bool)OSAtomicCompareAndSwap32Barrier((int32_t)oldval, (int32_t)newval, (int32_t *)a);
|
||||
#elif defined(__SOLARIS__)
|
||||
return (SDL_bool)(atomic_cas_ptr(a, oldval, newval) == oldval);
|
||||
#elif EMULATE_CAS
|
||||
@@ -180,12 +179,11 @@ SDL_AtomicCASPtr(void **a, void *oldval, void *newval)
|
||||
|
||||
return retval;
|
||||
#else
|
||||
#error Please define your platform.
|
||||
#error Please define your platform.
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
SDL_AtomicSet(SDL_atomic_t *a, int v)
|
||||
int SDL_AtomicSet(SDL_atomic_t *a, int v)
|
||||
{
|
||||
#ifdef HAVE_MSC_ATOMICS
|
||||
SDL_COMPILE_TIME_ASSERT(atomic_set, sizeof(long) == sizeof(a->value));
|
||||
@@ -205,7 +203,7 @@ SDL_AtomicSet(SDL_atomic_t *a, int v)
|
||||
#endif
|
||||
}
|
||||
|
||||
void*
|
||||
void *
|
||||
SDL_AtomicSetPtr(void **a, void *v)
|
||||
{
|
||||
#if defined(HAVE_MSC_ATOMICS)
|
||||
@@ -225,8 +223,7 @@ SDL_AtomicSetPtr(void **a, void *v)
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
SDL_AtomicAdd(SDL_atomic_t *a, int v)
|
||||
int SDL_AtomicAdd(SDL_atomic_t *a, int v)
|
||||
{
|
||||
#ifdef HAVE_MSC_ATOMICS
|
||||
SDL_COMPILE_TIME_ASSERT(atomic_add, sizeof(long) == sizeof(a->value));
|
||||
@@ -236,9 +233,9 @@ SDL_AtomicAdd(SDL_atomic_t *a, int v)
|
||||
#elif defined(HAVE_GCC_ATOMICS)
|
||||
return __sync_fetch_and_add(&a->value, v);
|
||||
#elif defined(__SOLARIS__)
|
||||
int pv = a->value;
|
||||
membar_consumer();
|
||||
atomic_add_int((volatile uint_t*)&a->value, v);
|
||||
int pv = a->value;
|
||||
membar_consumer();
|
||||
atomic_add_int((volatile uint_t *)&a->value, v);
|
||||
return pv;
|
||||
#else
|
||||
int value;
|
||||
@@ -249,8 +246,7 @@ SDL_AtomicAdd(SDL_atomic_t *a, int v)
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
SDL_AtomicGet(SDL_atomic_t *a)
|
||||
int SDL_AtomicGet(SDL_atomic_t *a)
|
||||
{
|
||||
#ifdef HAVE_ATOMIC_LOAD_N
|
||||
return __atomic_load_n(&a->value, __ATOMIC_SEQ_CST);
|
||||
@@ -298,14 +294,12 @@ SDL_AtomicGetPtr(void **a)
|
||||
#error This file should be built in arm mode so the mcr instruction is available for memory barriers
|
||||
#endif
|
||||
|
||||
void
|
||||
SDL_MemoryBarrierReleaseFunction(void)
|
||||
void SDL_MemoryBarrierReleaseFunction(void)
|
||||
{
|
||||
SDL_MemoryBarrierRelease();
|
||||
}
|
||||
|
||||
void
|
||||
SDL_MemoryBarrierAcquireFunction(void)
|
||||
void SDL_MemoryBarrierAcquireFunction(void)
|
||||
{
|
||||
SDL_MemoryBarrierAcquire();
|
||||
}
|
||||
|
@@ -24,7 +24,6 @@
|
||||
#include "../core/windows/SDL_windows.h"
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(HAVE_GCC_ATOMICS) && defined(__SOLARIS__)
|
||||
#include <atomic.h>
|
||||
#endif
|
||||
@@ -45,6 +44,7 @@
|
||||
#include <libkern/OSAtomic.h>
|
||||
#endif
|
||||
|
||||
/* *INDENT-OFF* */ /* clang-format off */
|
||||
#if defined(__WATCOMC__) && defined(__386__)
|
||||
SDL_COMPILE_TIME_ASSERT(locksize, 4==sizeof(SDL_SpinLock));
|
||||
extern __inline int _SDL_xchg_watcom(volatile int *a, int v);
|
||||
@@ -54,6 +54,7 @@ extern __inline int _SDL_xchg_watcom(volatile int *a, int v);
|
||||
value [eax] \
|
||||
modify exact [eax];
|
||||
#endif /* __WATCOMC__ && __386__ */
|
||||
/* *INDENT-ON* */ /* clang-format on */
|
||||
|
||||
/* This function is where all the magic happens... */
|
||||
SDL_bool
|
||||
@@ -90,39 +91,47 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
|
||||
#elif defined(__WATCOMC__) && defined(__386__)
|
||||
return _SDL_xchg_watcom(lock, 1) == 0;
|
||||
|
||||
#elif defined(__GNUC__) && defined(__arm__) && \
|
||||
(defined(__ARM_ARCH_3__) || defined(__ARM_ARCH_3M__) || \
|
||||
defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || \
|
||||
defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5TE__) || \
|
||||
defined(__ARM_ARCH_5TEJ__))
|
||||
#elif defined(__GNUC__) && defined(__arm__) && \
|
||||
(defined(__ARM_ARCH_3__) || defined(__ARM_ARCH_3M__) || \
|
||||
defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__) || \
|
||||
defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5TE__) || \
|
||||
defined(__ARM_ARCH_5TEJ__))
|
||||
int result;
|
||||
|
||||
#if defined(__RISCOS__)
|
||||
if (__cpucap_have_rex()) {
|
||||
__asm__ __volatile__ (
|
||||
__asm__ __volatile__(
|
||||
"ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
|
||||
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
|
||||
: "=&r"(result)
|
||||
: "r"(1), "r"(lock)
|
||||
: "cc", "memory");
|
||||
return result == 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
__asm__ __volatile__ (
|
||||
__asm__ __volatile__(
|
||||
"swp %0, %1, [%2]\n"
|
||||
: "=&r,&r" (result) : "r,0" (1), "r,r" (lock) : "memory");
|
||||
: "=&r,&r"(result)
|
||||
: "r,0"(1), "r,r"(lock)
|
||||
: "memory");
|
||||
return result == 0;
|
||||
|
||||
#elif defined(__GNUC__) && defined(__arm__)
|
||||
int result;
|
||||
__asm__ __volatile__ (
|
||||
__asm__ __volatile__(
|
||||
"ldrex %0, [%2]\nteq %0, #0\nstrexeq %0, %1, [%2]"
|
||||
: "=&r" (result) : "r" (1), "r" (lock) : "cc", "memory");
|
||||
: "=&r"(result)
|
||||
: "r"(1), "r"(lock)
|
||||
: "cc", "memory");
|
||||
return result == 0;
|
||||
|
||||
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
||||
int result;
|
||||
__asm__ __volatile__(
|
||||
"lock ; xchgl %0, (%1)\n"
|
||||
: "=r" (result) : "r" (lock), "0" (1) : "cc", "memory");
|
||||
: "=r"(result)
|
||||
: "r"(lock), "0"(1)
|
||||
: "cc", "memory");
|
||||
return result == 0;
|
||||
|
||||
#elif defined(__MACOS__) || defined(__IOS__) || defined(__TVOS__)
|
||||
@@ -147,7 +156,9 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
|
||||
res = SDL_TRUE;
|
||||
}
|
||||
// enable interuption
|
||||
if (oldintr) { EIntr(); }
|
||||
if (oldintr) {
|
||||
EIntr();
|
||||
}
|
||||
return res;
|
||||
#else
|
||||
#error Please implement for your platform.
|
||||
@@ -155,8 +166,7 @@ SDL_AtomicTryLock(SDL_SpinLock *lock)
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicLock(SDL_SpinLock *lock)
|
||||
void SDL_AtomicLock(SDL_SpinLock *lock)
|
||||
{
|
||||
int iterations = 0;
|
||||
/* FIXME: Should we have an eventual timeout? */
|
||||
@@ -171,8 +181,7 @@ SDL_AtomicLock(SDL_SpinLock *lock)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_AtomicUnlock(SDL_SpinLock *lock)
|
||||
void SDL_AtomicUnlock(SDL_SpinLock *lock)
|
||||
{
|
||||
#if HAVE_GCC_ATOMICS || HAVE_GCC_SYNC_LOCK_TEST_AND_SET
|
||||
__sync_lock_release(lock);
|
||||
@@ -185,7 +194,7 @@ SDL_AtomicUnlock(SDL_SpinLock *lock)
|
||||
*lock = 0;
|
||||
|
||||
#elif defined(__WATCOMC__) && defined(__386__)
|
||||
SDL_CompilerBarrier ();
|
||||
SDL_CompilerBarrier();
|
||||
*lock = 0;
|
||||
|
||||
#elif defined(__SOLARIS__)
|
||||
|
Reference in New Issue
Block a user