SDL: thread: code style

From 461a38ff1af1d749426c8e2c6f2a56e2b31c1a45 Mon Sep 17 00:00:00 2001
From: pionere <[EMAIL REDACTED]>
Date: Tue, 29 Nov 2022 17:30:03 +0100
Subject: [PATCH] thread: code style

---
 src/thread/ngage/SDL_syssem.cpp     |  4 ++--
 src/thread/ngage/SDL_systhread.cpp  |  9 +++------
 src/thread/ps2/SDL_syssem.c         |  4 ++--
 src/thread/pthread/SDL_syssem.c     |  6 +++---
 src/thread/stdcpp/SDL_syscond.cpp   |  8 ++++----
 src/thread/stdcpp/SDL_sysmutex.cpp  |  2 +-
 src/thread/vita/SDL_syscond.c       |  4 ++--
 src/thread/vita/SDL_sysmutex.c      |  4 ++--
 src/thread/vita/SDL_syssem.c        | 16 ++++++++--------
 src/thread/windows/SDL_syscond_cv.c |  2 +-
 src/thread/windows/SDL_sysmutex.c   |  6 +++---
 src/thread/windows/SDL_syssem.c     |  8 ++++----
 12 files changed, 35 insertions(+), 38 deletions(-)

diff --git a/src/thread/ngage/SDL_syssem.cpp b/src/thread/ngage/SDL_syssem.cpp
index 01fe8bd90a82..5e6cdaf17b60 100644
--- a/src/thread/ngage/SDL_syssem.cpp
+++ b/src/thread/ngage/SDL_syssem.cpp
@@ -72,7 +72,7 @@ static void WaitAll(SDL_sem *sem)
     RSemaphore sema;
     sema.SetHandle(sem->handle);
     sema.Wait();
-    while(sem->count < 0) {
+    while (sem->count < 0) {
         sema.Wait();
     }
 }
@@ -94,7 +94,7 @@ SDL_CreateSemaphore(Uint32 initial_value)
 void
 SDL_DestroySemaphore(SDL_sem * sem)
 {
-    if (sem) {
+    if (sem != NULL) {
         RSemaphore sema;
         sema.SetHandle(sem->handle);
         sema.Signal(sema.Count());
diff --git a/src/thread/ngage/SDL_systhread.cpp b/src/thread/ngage/SDL_systhread.cpp
index e711cb6661bb..00c603da8332 100644
--- a/src/thread/ngage/SDL_systhread.cpp
+++ b/src/thread/ngage/SDL_systhread.cpp
@@ -52,13 +52,11 @@ CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny* aPtr1, TAny*
 {
     TBuf<16> name;
     TInt     status = KErrNone;
-    do
-    {
+    do {
         object_count++;
         name.Format(_L("SDL_%x"), object_count);
         status = aFunc(name, aPtr1, aPtr2);
-    }
-    while(status == KErrAlreadyExists);
+    } while (status == KErrAlreadyExists);
     return status;
 }
 
@@ -71,8 +69,7 @@ SDL_SYS_CreateThread(SDL_Thread *thread)
     if (status != KErrNone) {
         delete(((RThread*)(thread->handle)));
         thread->handle = NULL;
-        SDL_SetError("Not enough resources to create thread");
-        return -1;
+        return SDL_SetError("Not enough resources to create thread");
     }
 
     rthread.Resume();
diff --git a/src/thread/ps2/SDL_syssem.c b/src/thread/ps2/SDL_syssem.c
index fab72c14f850..638947ea50aa 100644
--- a/src/thread/ps2/SDL_syssem.c
+++ b/src/thread/ps2/SDL_syssem.c
@@ -83,7 +83,7 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
     int ret;
     struct timer_alarm_t alarm;
     InitializeTimerAlarm(&alarm);
-    
+
     if (sem == NULL) {
         return SDL_InvalidParamError("sem");
     }
@@ -105,7 +105,7 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
     if (ret < 0) {
         return SDL_MUTEX_TIMEDOUT;
     }
-    return 0; //Wait condition satisfied.
+    return 0; // Wait condition satisfied.
 }
 
 int SDL_SemTryWait(SDL_sem *sem)
diff --git a/src/thread/pthread/SDL_syssem.c b/src/thread/pthread/SDL_syssem.c
index c7f78ab0df33..865e1e0662d7 100644
--- a/src/thread/pthread/SDL_syssem.c
+++ b/src/thread/pthread/SDL_syssem.c
@@ -44,7 +44,7 @@ SDL_sem *
 SDL_CreateSemaphore(Uint32 initial_value)
 {
     SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem));
-    if (sem) {
+    if (sem != NULL) {
         if (sem_init(&sem->sem, 0, initial_value) < 0) {
             SDL_SetError("sem_init() failed");
             SDL_free(sem);
@@ -59,7 +59,7 @@ SDL_CreateSemaphore(Uint32 initial_value)
 void
 SDL_DestroySemaphore(SDL_sem * sem)
 {
-    if (sem) {
+    if (sem != NULL) {
         sem_destroy(&sem->sem);
         SDL_free(sem);
     }
@@ -179,7 +179,7 @@ SDL_SemValue(SDL_sem * sem)
 {
     int ret = 0;
 
-    if (!sem) {
+    if (sem == NULL) {
         SDL_InvalidParamError("sem");
         return 0;
     }
diff --git a/src/thread/stdcpp/SDL_syscond.cpp b/src/thread/stdcpp/SDL_syscond.cpp
index d49198a64668..f49051c62d3e 100644
--- a/src/thread/stdcpp/SDL_syscond.cpp
+++ b/src/thread/stdcpp/SDL_syscond.cpp
@@ -58,7 +58,7 @@ extern "C"
 void
 SDL_DestroyCond(SDL_cond * cond)
 {
-    if (cond) {
+    if (cond != NULL) {
         delete cond;
     }
 }
@@ -114,11 +114,11 @@ extern "C"
 int
 SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
 {
-    if (!cond) {
+    if (cond == NULL) {
         return SDL_InvalidParamError("cond");
     }
 
-    if (!mutex) {
+    if (mutex == NULL) {
         return SDL_InvalidParamError("mutex");
     }
 
@@ -131,7 +131,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
             cpp_lock.release();
             return 0;
         } else {
-            auto wait_result = cond->cpp_cond.wait_for (
+            auto wait_result = cond->cpp_cond.wait_for(
                 cpp_lock,
                 std::chrono::duration<Uint32, std::milli>(ms)
                 );
diff --git a/src/thread/stdcpp/SDL_sysmutex.cpp b/src/thread/stdcpp/SDL_sysmutex.cpp
index c10aa9242e63..2a59c34b544a 100644
--- a/src/thread/stdcpp/SDL_sysmutex.cpp
+++ b/src/thread/stdcpp/SDL_sysmutex.cpp
@@ -53,7 +53,7 @@ extern "C"
 void
 SDL_DestroyMutex(SDL_mutex * mutex)
 {
-    if (mutex) {
+    if (mutex != NULL) {
         delete mutex;
     }
 }
diff --git a/src/thread/vita/SDL_syscond.c b/src/thread/vita/SDL_syscond.c
index b37195477a12..39df9a5366c2 100644
--- a/src/thread/vita/SDL_syscond.c
+++ b/src/thread/vita/SDL_syscond.c
@@ -45,7 +45,7 @@ SDL_CreateCond(void)
     SDL_cond *cond;
 
     cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
-    if (cond) {
+    if (cond != NULL) {
         cond->lock = SDL_CreateMutex();
         cond->wait_sem = SDL_CreateSemaphore(0);
         cond->wait_done = SDL_CreateSemaphore(0);
@@ -64,7 +64,7 @@ SDL_CreateCond(void)
 void
 SDL_DestroyCond(SDL_cond * cond)
 {
-    if (cond) {
+    if (cond != NULL) {
         if (cond->wait_sem) {
             SDL_DestroySemaphore(cond->wait_sem);
         }
diff --git a/src/thread/vita/SDL_sysmutex.c b/src/thread/vita/SDL_sysmutex.c
index 24af14446484..c8bbaa8466b5 100644
--- a/src/thread/vita/SDL_sysmutex.c
+++ b/src/thread/vita/SDL_sysmutex.c
@@ -41,7 +41,7 @@ SDL_CreateMutex(void)
 
     /* Allocate mutex memory */
     mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
-    if (mutex) {
+    if (mutex != NULL) {
 
         res = sceKernelCreateLwMutex(
             &mutex->lock,
@@ -64,7 +64,7 @@ SDL_CreateMutex(void)
 void
 SDL_DestroyMutex(SDL_mutex * mutex)
 {
-    if (mutex) {
+    if (mutex != NULL) {
         sceKernelDeleteLwMutex(&mutex->lock);
         SDL_free(mutex);
     }
diff --git a/src/thread/vita/SDL_syssem.c b/src/thread/vita/SDL_syssem.c
index f8464c940872..f0f3f8765588 100644
--- a/src/thread/vita/SDL_syssem.c
+++ b/src/thread/vita/SDL_syssem.c
@@ -78,7 +78,7 @@ void SDL_DestroySemaphore(SDL_sem *sem)
 int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
 {
     Uint32 *pTimeout;
-       unsigned int res;
+    unsigned int res;
 
     if (sem == NULL) {
         return SDL_InvalidParamError("sem");
@@ -100,13 +100,13 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
     }
 
     res = sceKernelWaitSema(sem->semid, 1, pTimeout);
-       switch (res) {
-               case SCE_KERNEL_OK:
-                       return 0;
-               case SCE_KERNEL_ERROR_WAIT_TIMEOUT:
-                       return SDL_MUTEX_TIMEDOUT;
-               default:
-                       return SDL_SetError("WaitForSingleObject() failed");
+    switch (res) {
+    case SCE_KERNEL_OK:
+        return 0;
+    case SCE_KERNEL_ERROR_WAIT_TIMEOUT:
+        return SDL_MUTEX_TIMEDOUT;
+    default:
+        return SDL_SetError("WaitForSingleObject() failed");
     }
 }
 
diff --git a/src/thread/windows/SDL_syscond_cv.c b/src/thread/windows/SDL_syscond_cv.c
index 0bac17d55176..0ef24b8bba29 100644
--- a/src/thread/windows/SDL_syscond_cv.c
+++ b/src/thread/windows/SDL_syscond_cv.c
@@ -96,7 +96,7 @@ SDL_CreateCond_cv(void)
 static void
 SDL_DestroyCond_cv(SDL_cond * cond)
 {
-    if (cond) {
+    if (cond != NULL) {
         /* There are no kernel allocated resources */
         SDL_free(cond);
     }
diff --git a/src/thread/windows/SDL_sysmutex.c b/src/thread/windows/SDL_sysmutex.c
index 27c5a47bff40..dcf4e9676fcc 100644
--- a/src/thread/windows/SDL_sysmutex.c
+++ b/src/thread/windows/SDL_sysmutex.c
@@ -74,7 +74,7 @@ SDL_CreateMutex_srw(void)
 static void
 SDL_DestroyMutex_srw(SDL_mutex * mutex)
 {
-    if (mutex) {
+    if (mutex != NULL) {
         /* There are no kernel allocated resources */
         SDL_free(mutex);
     }
@@ -176,7 +176,7 @@ SDL_CreateMutex_cs(void)
 
     /* Allocate mutex memory */
     mutex = (SDL_mutex_cs *) SDL_malloc(sizeof(*mutex));
-    if (mutex) {
+    if (mutex != NULL) {
         /* Initialize */
         /* On SMP systems, a non-zero spin count generally helps performance */
 #if __WINRT__
@@ -195,7 +195,7 @@ static void
 SDL_DestroyMutex_cs(SDL_mutex * mutex_)
 {
     SDL_mutex_cs *mutex = (SDL_mutex_cs *)mutex_;
-    if (mutex) {
+    if (mutex != NULL) {
         DeleteCriticalSection(&mutex->cs);
         SDL_free(mutex);
     }
diff --git a/src/thread/windows/SDL_syssem.c b/src/thread/windows/SDL_syssem.c
index 590c394b0ddd..882bf347cba8 100644
--- a/src/thread/windows/SDL_syssem.c
+++ b/src/thread/windows/SDL_syssem.c
@@ -96,7 +96,7 @@ SDL_CreateSemaphore_atom(Uint32 initial_value)
     SDL_sem_atom *sem;
 
     sem = (SDL_sem_atom *) SDL_malloc(sizeof(*sem));
-    if (sem) {
+    if (sem != NULL) {
         sem->count = initial_value;
     } else {
         SDL_OutOfMemory();
@@ -107,7 +107,7 @@ SDL_CreateSemaphore_atom(Uint32 initial_value)
 static void
 SDL_DestroySemaphore_atom(SDL_sem * sem)
 {
-    if (sem) {
+    if (sem != NULL) {
         SDL_free(sem);
     }
 }
@@ -269,7 +269,7 @@ SDL_CreateSemaphore_kern(Uint32 initial_value)
 
     /* Allocate sem memory */
     sem = (SDL_sem_kern *) SDL_malloc(sizeof(*sem));
-    if (sem) {
+    if (sem != NULL) {
         /* Create the semaphore, with max value 32K */
 #if __WINRT__
         sem->id = CreateSemaphoreEx(NULL, initial_value, 32 * 1024, NULL, 0, SEMAPHORE_ALL_ACCESS);
@@ -293,7 +293,7 @@ static void
 SDL_DestroySemaphore_kern(SDL_sem * _sem)
 {
     SDL_sem_kern *sem = (SDL_sem_kern *)_sem;
-    if (sem) {
+    if (sem != NULL) {
         if (sem->id) {
             CloseHandle(sem->id);
             sem->id = 0;