SDL: use SDL_InvalidParamError in the thread 'classes'

From 450f184f7d883476123471585e5abc670b086a67 Mon Sep 17 00:00:00 2001
From: pionere <[EMAIL REDACTED]>
Date: Sat, 19 Nov 2022 08:13:12 +0100
Subject: [PATCH] use SDL_InvalidParamError in the thread 'classes'

---
 src/thread/n3ds/SDL_syscond.c     |  8 ++++----
 src/thread/n3ds/SDL_sysmutex.c    |  6 +++---
 src/thread/n3ds/SDL_syssem.c      |  8 ++++----
 src/thread/ngage/SDL_sysmutex.cpp |  7 +++----
 src/thread/ngage/SDL_syssem.cpp   | 11 ++++++++---
 src/thread/pthread/SDL_syssem.c   | 14 +++++++++-----
 6 files changed, 31 insertions(+), 23 deletions(-)

diff --git a/src/thread/n3ds/SDL_syscond.c b/src/thread/n3ds/SDL_syscond.c
index 9c671f554e70..eb56eea0e2af 100644
--- a/src/thread/n3ds/SDL_syscond.c
+++ b/src/thread/n3ds/SDL_syscond.c
@@ -58,7 +58,7 @@ int
 SDL_CondSignal(SDL_cond *cond)
 {
     if (!cond) {
-        return SDL_SetError("Passed a NULL condition variable");
+        return SDL_InvalidParamError("cond");
     }
 
     CondVar_Signal(&cond->cond_variable);
@@ -70,7 +70,7 @@ int
 SDL_CondBroadcast(SDL_cond *cond)
 {
     if (!cond) {
-        return SDL_SetError("Passed a NULL condition variable");
+        return SDL_InvalidParamError("cond");
     }
 
     CondVar_Broadcast(&cond->cond_variable);
@@ -104,10 +104,10 @@ SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
     Result res;
 
     if (!cond) {
-        return SDL_SetError("Passed a NULL condition variable");
+        return SDL_InvalidParamError("cond");
     }
     if (!mutex) {
-        return SDL_SetError("Passed a NULL mutex");
+        return SDL_InvalidParamError("mutex");
     }
 
     res = 0;
diff --git a/src/thread/n3ds/SDL_sysmutex.c b/src/thread/n3ds/SDL_sysmutex.c
index 59fa8a801a01..4c091de02204 100644
--- a/src/thread/n3ds/SDL_sysmutex.c
+++ b/src/thread/n3ds/SDL_sysmutex.c
@@ -56,7 +56,7 @@ int
 SDL_LockMutex(SDL_mutex *mutex)
 {
     if (mutex == NULL) {
-        return SDL_SetError("Passed a NULL mutex");
+        return SDL_InvalidParamError("mutex");
     }
 
     RecursiveLock_Lock(&mutex->lock);
@@ -69,7 +69,7 @@ int
 SDL_TryLockMutex(SDL_mutex *mutex)
 {
     if (mutex == NULL) {
-        return SDL_SetError("Passed a NULL mutex");
+        return SDL_InvalidParamError("mutex");
     }
 
     return RecursiveLock_TryLock(&mutex->lock);
@@ -80,7 +80,7 @@ int
 SDL_mutexV(SDL_mutex *mutex)
 {
     if (mutex == NULL) {
-        return SDL_SetError("Passed a NULL mutex");
+        return SDL_InvalidParamError("mutex");
     }
 
     RecursiveLock_Unlock(&mutex->lock);
diff --git a/src/thread/n3ds/SDL_syssem.c b/src/thread/n3ds/SDL_syssem.c
index 08fbb6f42ef4..29d3415aa260 100644
--- a/src/thread/n3ds/SDL_syssem.c
+++ b/src/thread/n3ds/SDL_syssem.c
@@ -69,7 +69,7 @@ int
 SDL_SemTryWait(SDL_sem *sem)
 {
     if (!sem) {
-        return SDL_SetError("Passed a NULL semaphore");
+        return SDL_InvalidParamError("sem");
     }
 
     return SDL_SemWaitTimeout(sem, 0);
@@ -81,7 +81,7 @@ SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
     int retval;
 
     if (!sem) {
-        return SDL_SetError("Passed a NULL semaphore");
+        return SDL_InvalidParamError("sem");
     }
 
     if (timeout == SDL_MUTEX_MAXWAIT) {
@@ -114,7 +114,7 @@ Uint32
 SDL_SemValue(SDL_sem *sem)
 {
     if (!sem) {
-        return SDL_SetError("Passed a NULL semaphore");
+        return SDL_InvalidParamError("sem");
     }
     return sem->semaphore.current_count;
 }
@@ -123,7 +123,7 @@ int
 SDL_SemPost(SDL_sem *sem)
 {
     if (!sem) {
-        return SDL_SetError("Passed a NULL semaphore");
+        return SDL_InvalidParamError("sem");
     }
     LightSemaphore_Release(&sem->semaphore, 1);
     return 0;
diff --git a/src/thread/ngage/SDL_sysmutex.cpp b/src/thread/ngage/SDL_sysmutex.cpp
index 6893fc6283a7..f7ec1bbb114c 100644
--- a/src/thread/ngage/SDL_sysmutex.cpp
+++ b/src/thread/ngage/SDL_sysmutex.cpp
@@ -77,8 +77,7 @@ SDL_TryLockMutex(SDL_mutex * mutex)
 {
     if (mutex == NULL)
     {
-        SDL_SetError("Passed a NULL mutex.");
-        return -1;
+        return SDL_InvalidParamError("mutex");
     }
 
     // Not yet implemented.
@@ -92,7 +91,7 @@ SDL_LockMutex(SDL_mutex * mutex)
 {
     if (mutex == NULL)
     {
-        return SDL_SetError("Passed a NULL mutex.");
+        return SDL_InvalidParamError("mutex");
     }
 
     RMutex rmutex;
@@ -108,7 +107,7 @@ SDL_UnlockMutex(SDL_mutex * mutex)
 {
     if ( mutex == NULL )
     {
-        return SDL_SetError("Passed a NULL mutex.");
+        return SDL_InvalidParamError("mutex");
     }
 
     RMutex rmutex;
diff --git a/src/thread/ngage/SDL_syssem.cpp b/src/thread/ngage/SDL_syssem.cpp
index 622d6239a0d3..a999524e822c 100644
--- a/src/thread/ngage/SDL_syssem.cpp
+++ b/src/thread/ngage/SDL_syssem.cpp
@@ -119,7 +119,7 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
 {
     if (! sem)
     {
-        return SDL_SetError("Passed a NULL sem");
+        return SDL_InvalidParamError("sem");
     }
 
     if (timeout == SDL_MUTEX_MAXWAIT)
@@ -152,6 +152,11 @@ SDL_SemWaitTimeout(SDL_sem * sem, Uint32 timeout)
 int
 SDL_SemTryWait(SDL_sem *sem)
 {
+    if (! sem)
+    {
+        return SDL_InvalidParamError("sem");
+    }
+
     if(sem->count > 0)
     {
         sem->count--;
@@ -170,7 +175,7 @@ SDL_SemValue(SDL_sem * sem)
 {
     if (! sem)
     {
-        SDL_SetError("Passed a NULL sem.");
+        SDL_InvalidParamError("sem");
         return 0;
     }
     return sem->count;
@@ -181,7 +186,7 @@ SDL_SemPost(SDL_sem * sem)
 {
     if (! sem)
     {
-        return SDL_SetError("Passed a NULL sem.");
+        return SDL_InvalidParamError("sem");
     }
     sem->count++;
     RSemaphore sema;
diff --git a/src/thread/pthread/SDL_syssem.c b/src/thread/pthread/SDL_syssem.c
index 9a0c888224a0..01039e801e70 100644
--- a/src/thread/pthread/SDL_syssem.c
+++ b/src/thread/pthread/SDL_syssem.c
@@ -180,11 +180,15 @@ Uint32
 SDL_SemValue(SDL_sem * sem)
 {
     int ret = 0;
-    if (sem) {
-        sem_getvalue(&sem->sem, &ret);
-        if (ret < 0) {
-            ret = 0;
-        }
+
+    if (!sem) {
+        SDL_InvalidParamError("sem");
+        return 0;
+    }
+
+    sem_getvalue(&sem->sem, &ret);
+    if (ret < 0) {
+        ret = 0;
     }
     return (Uint32) ret;
 }