mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-02 22:30:13 +02: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
(cherry picked from commit 5750bcb174)
This commit is contained in:
@@ -35,7 +35,7 @@ struct SDL_cond
|
||||
SDL_cond *
|
||||
SDL_CreateCond(void)
|
||||
{
|
||||
SDL_cond *cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
|
||||
SDL_cond *cond = (SDL_cond *)SDL_malloc(sizeof(SDL_cond));
|
||||
if (cond) {
|
||||
CondVar_Init(&cond->cond_variable);
|
||||
} else {
|
||||
@@ -45,8 +45,7 @@ SDL_CreateCond(void)
|
||||
}
|
||||
|
||||
/* Destroy a condition variable */
|
||||
void
|
||||
SDL_DestroyCond(SDL_cond *cond)
|
||||
void SDL_DestroyCond(SDL_cond *cond)
|
||||
{
|
||||
if (cond) {
|
||||
SDL_free(cond);
|
||||
@@ -54,8 +53,7 @@ SDL_DestroyCond(SDL_cond *cond)
|
||||
}
|
||||
|
||||
/* Restart one of the threads that are waiting on the condition variable */
|
||||
int
|
||||
SDL_CondSignal(SDL_cond *cond)
|
||||
int SDL_CondSignal(SDL_cond *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
@@ -66,8 +64,7 @@ SDL_CondSignal(SDL_cond *cond)
|
||||
}
|
||||
|
||||
/* Restart all threads that are waiting on the condition variable */
|
||||
int
|
||||
SDL_CondBroadcast(SDL_cond *cond)
|
||||
int SDL_CondBroadcast(SDL_cond *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
@@ -98,8 +95,7 @@ Thread B:
|
||||
SDL_CondSignal(cond);
|
||||
SDL_UnlockMutex(lock);
|
||||
*/
|
||||
int
|
||||
SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
|
||||
int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
|
||||
{
|
||||
Result res;
|
||||
|
||||
@@ -115,15 +111,14 @@ SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
|
||||
CondVar_Wait(&cond->cond_variable, &mutex->lock.lock);
|
||||
} else {
|
||||
res = CondVar_WaitTimeout(&cond->cond_variable, &mutex->lock.lock,
|
||||
(s64) ms * 1000000LL);
|
||||
(s64)ms * 1000000LL);
|
||||
}
|
||||
|
||||
return R_SUCCEEDED(res) ? 0 : SDL_MUTEX_TIMEDOUT;
|
||||
}
|
||||
|
||||
/* Wait on the condition variable forever */
|
||||
int
|
||||
SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex)
|
||||
int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex)
|
||||
{
|
||||
return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ SDL_CreateMutex(void)
|
||||
SDL_mutex *mutex;
|
||||
|
||||
/* Allocate mutex memory */
|
||||
mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
|
||||
mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex));
|
||||
if (mutex) {
|
||||
RecursiveLock_Init(&mutex->lock);
|
||||
} else {
|
||||
@@ -43,8 +43,7 @@ SDL_CreateMutex(void)
|
||||
}
|
||||
|
||||
/* Free the mutex */
|
||||
void
|
||||
SDL_DestroyMutex(SDL_mutex *mutex)
|
||||
void SDL_DestroyMutex(SDL_mutex *mutex)
|
||||
{
|
||||
if (mutex) {
|
||||
SDL_free(mutex);
|
||||
@@ -52,8 +51,7 @@ SDL_DestroyMutex(SDL_mutex *mutex)
|
||||
}
|
||||
|
||||
/* Lock the mutex */
|
||||
int
|
||||
SDL_LockMutex(SDL_mutex *mutex)
|
||||
int SDL_LockMutex(SDL_mutex *mutex)
|
||||
{
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
@@ -65,8 +63,7 @@ SDL_LockMutex(SDL_mutex *mutex)
|
||||
}
|
||||
|
||||
/* try Lock the mutex */
|
||||
int
|
||||
SDL_TryLockMutex(SDL_mutex *mutex)
|
||||
int SDL_TryLockMutex(SDL_mutex *mutex)
|
||||
{
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
@@ -76,8 +73,7 @@ SDL_TryLockMutex(SDL_mutex *mutex)
|
||||
}
|
||||
|
||||
/* Unlock the mutex */
|
||||
int
|
||||
SDL_mutexV(SDL_mutex *mutex)
|
||||
int SDL_mutexV(SDL_mutex *mutex)
|
||||
{
|
||||
if (mutex == NULL) {
|
||||
return SDL_SetError("Passed a NULL mutex");
|
||||
|
||||
@@ -43,7 +43,7 @@ SDL_CreateSemaphore(Uint32 initial_value)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sem = (SDL_sem *) SDL_malloc(sizeof(*sem));
|
||||
sem = (SDL_sem *)SDL_malloc(sizeof(*sem));
|
||||
if (sem == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
@@ -57,16 +57,14 @@ SDL_CreateSemaphore(Uint32 initial_value)
|
||||
/* WARNING:
|
||||
You cannot call this function when another thread is using the semaphore.
|
||||
*/
|
||||
void
|
||||
SDL_DestroySemaphore(SDL_sem *sem)
|
||||
void SDL_DestroySemaphore(SDL_sem *sem)
|
||||
{
|
||||
if (sem) {
|
||||
SDL_free(sem);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemTryWait(SDL_sem *sem)
|
||||
int SDL_SemTryWait(SDL_sem *sem)
|
||||
{
|
||||
if (sem == NULL) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
@@ -75,8 +73,7 @@ SDL_SemTryWait(SDL_sem *sem)
|
||||
return SDL_SemWaitTimeout(sem, 0);
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
|
||||
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
|
||||
{
|
||||
int retval;
|
||||
|
||||
@@ -104,8 +101,7 @@ SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
|
||||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemWait(SDL_sem *sem)
|
||||
int SDL_SemWait(SDL_sem *sem)
|
||||
{
|
||||
return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
|
||||
}
|
||||
@@ -120,8 +116,7 @@ SDL_SemValue(SDL_sem *sem)
|
||||
return sem->semaphore.current_count;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SemPost(SDL_sem *sem)
|
||||
int SDL_SemPost(SDL_sem *sem)
|
||||
{
|
||||
if (sem == NULL) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
|
||||
@@ -37,10 +37,9 @@
|
||||
|
||||
static size_t GetStackSize(size_t requested_size);
|
||||
|
||||
static void
|
||||
ThreadEntry(void *arg)
|
||||
static void ThreadEntry(void *arg)
|
||||
{
|
||||
SDL_RunThread((SDL_Thread *) arg);
|
||||
SDL_RunThread((SDL_Thread *)arg);
|
||||
threadExit(0);
|
||||
}
|
||||
|
||||
@@ -48,8 +47,7 @@ ThreadEntry(void *arg)
|
||||
#error "SDL_PASSED_BEGINTHREAD_ENDTHREAD is not supported on N3DS"
|
||||
#endif
|
||||
|
||||
int
|
||||
SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
{
|
||||
s32 priority = N3DS_THREAD_PRIORITY_MEDIUM;
|
||||
size_t stack_size = GetStackSize(thread->stacksize);
|
||||
@@ -86,8 +84,7 @@ GetStackSize(size_t requested_size)
|
||||
return requested_size;
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_SetupThread(const char *name)
|
||||
void SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -97,11 +94,10 @@ SDL_ThreadID(void)
|
||||
{
|
||||
u32 thread_ID = 0;
|
||||
svcGetThreadId(&thread_ID, CUR_THREAD_HANDLE);
|
||||
return (SDL_threadID) thread_ID;
|
||||
return (SDL_threadID)thread_ID;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SYS_SetThreadPriority(SDL_ThreadPriority sdl_priority)
|
||||
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority sdl_priority)
|
||||
{
|
||||
s32 svc_priority;
|
||||
switch (sdl_priority) {
|
||||
@@ -120,11 +116,10 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority sdl_priority)
|
||||
default:
|
||||
svc_priority = N3DS_THREAD_PRIORITY_MEDIUM;
|
||||
}
|
||||
return (int) svcSetThreadPriority(CUR_THREAD_HANDLE, svc_priority);
|
||||
return (int)svcSetThreadPriority(CUR_THREAD_HANDLE, svc_priority);
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_WaitThread(SDL_Thread *thread)
|
||||
void SDL_SYS_WaitThread(SDL_Thread *thread)
|
||||
{
|
||||
Result res = threadJoin(thread->handle, U64_MAX);
|
||||
|
||||
@@ -137,8 +132,7 @@ SDL_SYS_WaitThread(SDL_Thread *thread)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SDL_SYS_DetachThread(SDL_Thread *thread)
|
||||
void SDL_SYS_DetachThread(SDL_Thread *thread)
|
||||
{
|
||||
threadDetach(thread->handle);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user