mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-10-16 06:45:59 +00:00
Pointer as bool (libsdl-org#7214)
This commit is contained in:
@@ -37,7 +37,7 @@ void *SDL_GetTLS(SDL_TLSID id)
|
||||
SDL_TLSData *storage;
|
||||
|
||||
storage = SDL_SYS_GetTLSData();
|
||||
if (storage == NULL || id == 0 || id > storage->limit) {
|
||||
if (!storage || id == 0 || id > storage->limit) {
|
||||
return NULL;
|
||||
}
|
||||
return storage->array[id - 1].data;
|
||||
@@ -52,13 +52,13 @@ int SDL_SetTLS(SDL_TLSID id, const void *value, void(SDLCALL *destructor)(void *
|
||||
}
|
||||
|
||||
storage = SDL_SYS_GetTLSData();
|
||||
if (storage == NULL || (id > storage->limit)) {
|
||||
if (!storage || (id > storage->limit)) {
|
||||
unsigned int i, oldlimit, newlimit;
|
||||
|
||||
oldlimit = storage ? storage->limit : 0;
|
||||
newlimit = (id + TLS_ALLOC_CHUNKSIZE);
|
||||
storage = (SDL_TLSData *)SDL_realloc(storage, sizeof(*storage) + (newlimit - 1) * sizeof(storage->array[0]));
|
||||
if (storage == NULL) {
|
||||
if (!storage) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
storage->limit = newlimit;
|
||||
@@ -118,14 +118,14 @@ SDL_TLSData *SDL_Generic_GetTLSData(void)
|
||||
SDL_TLSData *storage = NULL;
|
||||
|
||||
#ifndef SDL_THREADS_DISABLED
|
||||
if (SDL_generic_TLS_mutex == NULL) {
|
||||
if (!SDL_generic_TLS_mutex) {
|
||||
static SDL_SpinLock tls_lock;
|
||||
SDL_AtomicLock(&tls_lock);
|
||||
if (SDL_generic_TLS_mutex == NULL) {
|
||||
if (!SDL_generic_TLS_mutex) {
|
||||
SDL_Mutex *mutex = SDL_CreateMutex();
|
||||
SDL_MemoryBarrierRelease();
|
||||
SDL_generic_TLS_mutex = mutex;
|
||||
if (SDL_generic_TLS_mutex == NULL) {
|
||||
if (!SDL_generic_TLS_mutex) {
|
||||
SDL_AtomicUnlock(&tls_lock);
|
||||
return NULL;
|
||||
}
|
||||
@@ -159,10 +159,10 @@ int SDL_Generic_SetTLSData(SDL_TLSData *data)
|
||||
prev = NULL;
|
||||
for (entry = SDL_generic_TLS; entry; entry = entry->next) {
|
||||
if (entry->thread == thread) {
|
||||
if (data != NULL) {
|
||||
if (data) {
|
||||
entry->storage = data;
|
||||
} else {
|
||||
if (prev != NULL) {
|
||||
if (prev) {
|
||||
prev->next = entry->next;
|
||||
} else {
|
||||
SDL_generic_TLS = entry->next;
|
||||
@@ -173,7 +173,7 @@ int SDL_Generic_SetTLSData(SDL_TLSData *data)
|
||||
}
|
||||
prev = entry;
|
||||
}
|
||||
if (entry == NULL) {
|
||||
if (!entry) {
|
||||
entry = (SDL_TLSEntry *)SDL_malloc(sizeof(*entry));
|
||||
if (entry) {
|
||||
entry->thread = thread;
|
||||
@@ -184,7 +184,7 @@ int SDL_Generic_SetTLSData(SDL_TLSData *data)
|
||||
}
|
||||
SDL_UnlockMutex(SDL_generic_TLS_mutex);
|
||||
|
||||
if (entry == NULL) {
|
||||
if (!entry) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
return 0;
|
||||
@@ -249,7 +249,7 @@ SDL_error *SDL_GetErrBuf(void)
|
||||
if (errbuf == ALLOCATION_IN_PROGRESS) {
|
||||
return SDL_GetStaticErrBuf();
|
||||
}
|
||||
if (errbuf == NULL) {
|
||||
if (!errbuf) {
|
||||
/* Get the original memory functions for this allocation because the lifetime
|
||||
* of the error buffer may span calls to SDL_SetMemoryFunctions() by the app
|
||||
*/
|
||||
@@ -260,7 +260,7 @@ SDL_error *SDL_GetErrBuf(void)
|
||||
/* Mark that we're in the middle of allocating our buffer */
|
||||
SDL_SetTLS(tls_errbuf, ALLOCATION_IN_PROGRESS, NULL);
|
||||
errbuf = (SDL_error *)realloc_func(NULL, sizeof(*errbuf));
|
||||
if (errbuf == NULL) {
|
||||
if (!errbuf) {
|
||||
SDL_SetTLS(tls_errbuf, NULL, NULL);
|
||||
return SDL_GetStaticErrBuf();
|
||||
}
|
||||
@@ -328,7 +328,7 @@ SDL_Thread *SDL_CreateThreadWithStackSize(int(SDLCALL *fn)(void *),
|
||||
|
||||
/* Allocate memory for the thread info structure */
|
||||
thread = (SDL_Thread *)SDL_calloc(1, sizeof(*thread));
|
||||
if (thread == NULL) {
|
||||
if (!thread) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -336,9 +336,9 @@ SDL_Thread *SDL_CreateThreadWithStackSize(int(SDLCALL *fn)(void *),
|
||||
SDL_AtomicSet(&thread->state, SDL_THREAD_STATE_ALIVE);
|
||||
|
||||
/* Set up the arguments for the thread */
|
||||
if (name != NULL) {
|
||||
if (name) {
|
||||
thread->name = SDL_strdup(name);
|
||||
if (thread->name == NULL) {
|
||||
if (!thread->name) {
|
||||
SDL_OutOfMemory();
|
||||
SDL_free(thread);
|
||||
return NULL;
|
||||
@@ -381,7 +381,7 @@ DECLSPEC SDL_Thread *SDLCALL SDL_CreateThread(int(SDLCALL *fn)(void *),
|
||||
size_t stacksize = 0;
|
||||
|
||||
/* If the SDL_HINT_THREAD_STACK_SIZE exists, use it */
|
||||
if (stackhint != NULL) {
|
||||
if (stackhint) {
|
||||
char *endp = NULL;
|
||||
const Sint64 hintval = SDL_strtoll(stackhint, &endp, 10);
|
||||
if ((*stackhint != '\0') && (*endp == '\0')) { /* a valid number? */
|
||||
@@ -450,7 +450,7 @@ void SDL_WaitThread(SDL_Thread *thread, int *status)
|
||||
|
||||
void SDL_DetachThread(SDL_Thread *thread)
|
||||
{
|
||||
if (thread == NULL) {
|
||||
if (!thread) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -92,7 +92,7 @@ void SDL_DestroyCondition_generic(SDL_Condition *_cond)
|
||||
int SDL_SignalCondition_generic(SDL_Condition *_cond)
|
||||
{
|
||||
SDL_cond_generic *cond = (SDL_cond_generic *)_cond;
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ int SDL_SignalCondition_generic(SDL_Condition *_cond)
|
||||
int SDL_BroadcastCondition_generic(SDL_Condition *_cond)
|
||||
{
|
||||
SDL_cond_generic *cond = (SDL_cond_generic *)_cond;
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ int SDL_WaitConditionTimeoutNS_generic(SDL_Condition *_cond, SDL_Mutex *mutex, S
|
||||
SDL_cond_generic *cond = (SDL_cond_generic *)_cond;
|
||||
int retval;
|
||||
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
|
@@ -87,7 +87,7 @@ int SDL_TryLockMutex(SDL_Mutex *mutex)
|
||||
{
|
||||
int retval = 0;
|
||||
#ifndef SDL_THREADS_DISABLED
|
||||
if (mutex != NULL) {
|
||||
if (mutex) {
|
||||
SDL_threadID this_thread = SDL_ThreadID();
|
||||
if (mutex->owner == this_thread) {
|
||||
++mutex->recursive;
|
||||
|
@@ -66,7 +66,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
SDL_Semaphore *sem;
|
||||
|
||||
sem = (SDL_Semaphore *)SDL_malloc(sizeof(*sem));
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
{
|
||||
int retval;
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem)
|
||||
|
||||
int SDL_PostSemaphore(SDL_Semaphore *sem)
|
||||
{
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
|
@@ -54,7 +54,7 @@ void SDL_DestroyCondition(SDL_Condition *cond)
|
||||
/* Restart one of the threads that are waiting on the condition variable */
|
||||
int SDL_SignalCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ int SDL_SignalCondition(SDL_Condition *cond)
|
||||
/* Restart all threads that are waiting on the condition variable */
|
||||
int SDL_BroadcastCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
@@ -98,10 +98,10 @@ int SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 tim
|
||||
{
|
||||
Result res;
|
||||
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
if (mutex == NULL) {
|
||||
if (!mutex) {
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
|
@@ -53,7 +53,7 @@ void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doe
|
||||
|
||||
int SDL_TryLockMutex(SDL_Mutex *mutex)
|
||||
{
|
||||
return (mutex == NULL) ? 0 : RecursiveLock_TryLock(&mutex->lock);
|
||||
return (!mutex) ? 0 : RecursiveLock_TryLock(&mutex->lock);
|
||||
}
|
||||
|
||||
void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes
|
||||
|
@@ -43,7 +43,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
}
|
||||
|
||||
sem = (SDL_Semaphore *)SDL_malloc(sizeof(*sem));
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
@@ -63,7 +63,7 @@ void SDL_DestroySemaphore(SDL_Semaphore *sem)
|
||||
|
||||
int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
{
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ int WaitOnSemaphoreFor(SDL_Semaphore *sem, Sint64 timeout)
|
||||
|
||||
Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem)
|
||||
{
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
@@ -108,7 +108,7 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem)
|
||||
|
||||
int SDL_PostSemaphore(SDL_Semaphore *sem)
|
||||
{
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
LightSemaphore_Release(&sem->semaphore, 1);
|
||||
|
@@ -66,7 +66,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
cpu,
|
||||
false);
|
||||
|
||||
if (thread->handle == NULL) {
|
||||
if (!thread->handle) {
|
||||
return SDL_SetError("Couldn't create thread");
|
||||
}
|
||||
|
||||
|
@@ -90,7 +90,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
|
||||
void SDL_DestroySemaphore(SDL_Semaphore *sem)
|
||||
{
|
||||
if (sem != NULL) {
|
||||
if (sem) {
|
||||
RSemaphore sema;
|
||||
sema.SetHandle(sem->handle);
|
||||
sema.Signal(sema.Count());
|
||||
@@ -102,7 +102,7 @@ void SDL_DestroySemaphore(SDL_Semaphore *sem)
|
||||
|
||||
int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
{
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
|
||||
Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem)
|
||||
{
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
@@ -149,7 +149,7 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem)
|
||||
|
||||
int SDL_PostSemaphore(SDL_Semaphore *sem)
|
||||
{
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
sem->count++;
|
||||
|
@@ -47,7 +47,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
ee_sema_t sema;
|
||||
|
||||
sem = (SDL_Semaphore *)SDL_malloc(sizeof(*sem));
|
||||
if (sem != NULL) {
|
||||
if (sem) {
|
||||
/* TODO: Figure out the limit on the maximum value. */
|
||||
sema.init_count = initial_value;
|
||||
sema.max_count = 255;
|
||||
@@ -69,7 +69,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
/* Free the semaphore */
|
||||
void SDL_DestroySemaphore(SDL_Semaphore *sem)
|
||||
{
|
||||
if (sem != NULL) {
|
||||
if (sem) {
|
||||
if (sem->semid > 0) {
|
||||
DeleteSema(sem->semid);
|
||||
sem->semid = 0;
|
||||
@@ -85,7 +85,7 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
struct timer_alarm_t alarm;
|
||||
InitializeTimerAlarm(&alarm);
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem)
|
||||
{
|
||||
ee_sema_t info;
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ int SDL_PostSemaphore(SDL_Semaphore *sem)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
|
@@ -78,7 +78,7 @@ void SDL_DestroyCondition(SDL_Condition *cond)
|
||||
/* Restart one of the threads that are waiting on the condition variable */
|
||||
int SDL_SignalCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ int SDL_SignalCondition(SDL_Condition *cond)
|
||||
/* Restart all threads that are waiting on the condition variable */
|
||||
int SDL_BroadcastCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ int SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 tim
|
||||
{
|
||||
int retval;
|
||||
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
|
@@ -80,7 +80,7 @@ int SDL_TryLockMutex(SDL_Mutex *mutex)
|
||||
{
|
||||
int retval = 0;
|
||||
#ifndef SDL_THREADS_DISABLED
|
||||
if (mutex != NULL) {
|
||||
if (mutex) {
|
||||
const SceInt32 res = sceKernelTryLockLwMutex(&mutex->lock, 1);
|
||||
if (res == SCE_KERNEL_ERROR_OK) {
|
||||
retval = 0;
|
||||
|
@@ -41,7 +41,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
SDL_Semaphore *sem;
|
||||
|
||||
sem = (SDL_Semaphore *)SDL_malloc(sizeof(*sem));
|
||||
if (sem != NULL) {
|
||||
if (sem) {
|
||||
/* TODO: Figure out the limit on the maximum value. */
|
||||
sem->semid = sceKernelCreateSema("SDL sema", 0, initial_value, 255, NULL);
|
||||
if (sem->semid < 0) {
|
||||
@@ -59,7 +59,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
/* Free the semaphore */
|
||||
void SDL_DestroySemaphore(SDL_Semaphore *sem)
|
||||
{
|
||||
if (sem != NULL) {
|
||||
if (sem) {
|
||||
if (sem->semid > 0) {
|
||||
sceKernelDeleteSema(sem->semid);
|
||||
sem->semid = 0;
|
||||
@@ -79,7 +79,7 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
SceUInt *pTimeout;
|
||||
int res;
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem)
|
||||
{
|
||||
SceKernelSemaInfo info;
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ int SDL_PostSemaphore(SDL_Semaphore *sem)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
|
@@ -63,7 +63,7 @@ int SDL_SignalCondition(SDL_Condition *cond)
|
||||
{
|
||||
int retval;
|
||||
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ int SDL_BroadcastCondition(SDL_Condition *cond)
|
||||
{
|
||||
int retval;
|
||||
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ int SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 tim
|
||||
#endif
|
||||
struct timespec abstime;
|
||||
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
|
@@ -88,7 +88,7 @@ int SDL_TryLockMutex(SDL_Mutex *mutex)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (mutex != NULL) {
|
||||
if (mutex) {
|
||||
#ifdef FAKE_RECURSIVE_MUTEX
|
||||
pthread_t this_thread = pthread_self();
|
||||
if (mutex->owner == this_thread) {
|
||||
|
@@ -42,7 +42,7 @@ struct SDL_Semaphore
|
||||
SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
{
|
||||
SDL_Semaphore *sem = (SDL_Semaphore *)SDL_malloc(sizeof(SDL_Semaphore));
|
||||
if (sem != NULL) {
|
||||
if (sem) {
|
||||
if (sem_init(&sem->sem, 0, initial_value) < 0) {
|
||||
SDL_SetError("sem_init() failed");
|
||||
SDL_free(sem);
|
||||
@@ -56,7 +56,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
|
||||
void SDL_DestroySemaphore(SDL_Semaphore *sem)
|
||||
{
|
||||
if (sem != NULL) {
|
||||
if (sem) {
|
||||
sem_destroy(&sem->sem);
|
||||
SDL_free(sem);
|
||||
}
|
||||
@@ -74,7 +74,7 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
Uint64 end;
|
||||
#endif
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
@@ -168,7 +168,7 @@ int SDL_PostSemaphore(SDL_Semaphore *sem)
|
||||
{
|
||||
int retval;
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
|
@@ -118,10 +118,10 @@ void SDL_SYS_SetupThread(const char *name)
|
||||
int i;
|
||||
sigset_t mask;
|
||||
|
||||
if (name != NULL) {
|
||||
if (name) {
|
||||
#if (defined(__MACOS__) || defined(__IOS__) || defined(__LINUX__)) && defined(HAVE_DLOPEN)
|
||||
SDL_assert(checked_setname);
|
||||
if (ppthread_setname_np != NULL) {
|
||||
if (ppthread_setname_np) {
|
||||
#if defined(__MACOS__) || defined(__IOS__)
|
||||
ppthread_setname_np(name);
|
||||
#elif defined(__LINUX__)
|
||||
|
@@ -56,7 +56,7 @@ SDL_CreateCondition(void)
|
||||
extern "C" void
|
||||
SDL_DestroyCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (cond != NULL) {
|
||||
if (cond) {
|
||||
delete cond;
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ SDL_DestroyCondition(SDL_Condition *cond)
|
||||
extern "C" int
|
||||
SDL_SignalCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ SDL_SignalCondition(SDL_Condition *cond)
|
||||
extern "C" int
|
||||
SDL_BroadcastCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
|
@@ -45,7 +45,7 @@ extern "C" SDL_Mutex * SDL_CreateMutex(void)
|
||||
|
||||
extern "C" void SDL_DestroyMutex(SDL_Mutex *mutex)
|
||||
{
|
||||
if (mutex != NULL) {
|
||||
if (mutex) {
|
||||
delete mutex;
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ extern "C" void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS /
|
||||
|
||||
extern "C" int SDL_TryLockMutex(SDL_Mutex *mutex)
|
||||
{
|
||||
return ((mutex == NULL) || mutex->cpp_mutex.try_lock()) ? 0 : SDL_MUTEX_TIMEDOUT;
|
||||
return ((!mutex) || mutex->cpp_mutex.try_lock()) ? 0 : SDL_MUTEX_TIMEDOUT;
|
||||
}
|
||||
|
||||
/* Unlock the mutex */
|
||||
|
@@ -46,7 +46,7 @@ extern "C" SDL_RWLock *SDL_CreateRWLock(void)
|
||||
|
||||
extern "C" void SDL_DestroyRWLock(SDL_RWLock *rwlock)
|
||||
{
|
||||
if (rwlock != NULL) {
|
||||
if (rwlock) {
|
||||
delete rwlock;
|
||||
}
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ SDL_Condition *SDL_CreateCondition(void)
|
||||
SDL_Condition *cond;
|
||||
|
||||
cond = (SDL_Condition *)SDL_malloc(sizeof(SDL_Condition));
|
||||
if (cond != NULL) {
|
||||
if (cond) {
|
||||
cond->lock = SDL_CreateMutex();
|
||||
cond->wait_sem = SDL_CreateSemaphore(0);
|
||||
cond->wait_done = SDL_CreateSemaphore(0);
|
||||
@@ -61,7 +61,7 @@ SDL_Condition *SDL_CreateCondition(void)
|
||||
/* Destroy a condition variable */
|
||||
void SDL_DestroyCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (cond != NULL) {
|
||||
if (cond) {
|
||||
if (cond->wait_sem) {
|
||||
SDL_DestroySemaphore(cond->wait_sem);
|
||||
}
|
||||
@@ -78,7 +78,7 @@ void SDL_DestroyCondition(SDL_Condition *cond)
|
||||
/* Restart one of the threads that are waiting on the condition variable */
|
||||
int SDL_SignalCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ int SDL_SignalCondition(SDL_Condition *cond)
|
||||
/* Restart all threads that are waiting on the condition variable */
|
||||
int SDL_BroadcastCondition(SDL_Condition *cond)
|
||||
{
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ int SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 tim
|
||||
{
|
||||
int retval;
|
||||
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
|
@@ -35,7 +35,7 @@ struct SDL_Mutex
|
||||
SDL_Mutex *SDL_CreateMutex(void)
|
||||
{
|
||||
SDL_Mutex *mutex = (SDL_Mutex *)SDL_malloc(sizeof(*mutex));
|
||||
if (mutex != NULL) {
|
||||
if (mutex) {
|
||||
const SceInt32 res = sceKernelCreateLwMutex(
|
||||
&mutex->lock,
|
||||
"SDL mutex",
|
||||
@@ -56,7 +56,7 @@ SDL_Mutex *SDL_CreateMutex(void)
|
||||
|
||||
void SDL_DestroyMutex(SDL_Mutex *mutex)
|
||||
{
|
||||
if (mutex != NULL) {
|
||||
if (mutex) {
|
||||
sceKernelDeleteLwMutex(&mutex->lock);
|
||||
SDL_free(mutex);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ int SDL_TryLockMutex(SDL_Mutex *mutex)
|
||||
#else
|
||||
SceInt32 res = 0;
|
||||
|
||||
if (mutex == NULL) {
|
||||
if (!mutex) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -42,7 +42,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
SDL_Semaphore *sem;
|
||||
|
||||
sem = (SDL_Semaphore *)SDL_malloc(sizeof(*sem));
|
||||
if (sem != NULL) {
|
||||
if (sem) {
|
||||
/* TODO: Figure out the limit on the maximum value. */
|
||||
sem->semid = sceKernelCreateSema("SDL sema", 0, initial_value, 255, NULL);
|
||||
if (sem->semid < 0) {
|
||||
@@ -60,7 +60,7 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
/* Free the semaphore */
|
||||
void SDL_DestroySemaphore(SDL_Semaphore *sem)
|
||||
{
|
||||
if (sem != NULL) {
|
||||
if (sem) {
|
||||
if (sem->semid > 0) {
|
||||
sceKernelDeleteSema(sem->semid);
|
||||
sem->semid = 0;
|
||||
@@ -80,7 +80,7 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS)
|
||||
SceUInt *pTimeout;
|
||||
int res;
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem)
|
||||
SceKernelSemaInfo info;
|
||||
info.size = sizeof(info);
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
@@ -132,7 +132,7 @@ int SDL_PostSemaphore(SDL_Semaphore *sem)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
|
@@ -84,7 +84,7 @@ static SDL_Condition *SDL_CreateCondition_cv(void)
|
||||
|
||||
/* Relies on CONDITION_VARIABLE_INIT == 0. */
|
||||
cond = (SDL_cond_cv *)SDL_calloc(1, sizeof(*cond));
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ static SDL_Condition *SDL_CreateCondition_cv(void)
|
||||
|
||||
static void SDL_DestroyCondition_cv(SDL_Condition *cond)
|
||||
{
|
||||
if (cond != NULL) {
|
||||
if (cond) {
|
||||
/* There are no kernel allocated resources */
|
||||
SDL_free(cond);
|
||||
}
|
||||
@@ -102,7 +102,7 @@ static void SDL_DestroyCondition_cv(SDL_Condition *cond)
|
||||
static int SDL_SignalCondition_cv(SDL_Condition *_cond)
|
||||
{
|
||||
SDL_cond_cv *cond = (SDL_cond_cv *)_cond;
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ static int SDL_SignalCondition_cv(SDL_Condition *_cond)
|
||||
static int SDL_BroadcastCondition_cv(SDL_Condition *_cond)
|
||||
{
|
||||
SDL_cond_cv *cond = (SDL_cond_cv *)_cond;
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
|
||||
@@ -129,10 +129,10 @@ static int SDL_WaitConditionTimeoutNS_cv(SDL_Condition *_cond, SDL_Mutex *_mutex
|
||||
DWORD timeout;
|
||||
int ret;
|
||||
|
||||
if (cond == NULL) {
|
||||
if (!cond) {
|
||||
return SDL_InvalidParamError("cond");
|
||||
}
|
||||
if (_mutex == NULL) {
|
||||
if (!_mutex) {
|
||||
return SDL_InvalidParamError("mutex");
|
||||
}
|
||||
|
||||
@@ -208,13 +208,13 @@ static const SDL_cond_impl_t SDL_cond_impl_generic = {
|
||||
|
||||
SDL_Condition *SDL_CreateCondition(void)
|
||||
{
|
||||
if (SDL_cond_impl_active.Create == NULL) {
|
||||
if (!SDL_cond_impl_active.Create) {
|
||||
const SDL_cond_impl_t *impl = NULL;
|
||||
|
||||
if (SDL_mutex_impl_active.Type == SDL_MUTEX_INVALID) {
|
||||
/* The mutex implementation isn't decided yet, trigger it */
|
||||
SDL_Mutex *mutex = SDL_CreateMutex();
|
||||
if (mutex == NULL) {
|
||||
if (!mutex) {
|
||||
return NULL;
|
||||
}
|
||||
SDL_DestroyMutex(mutex);
|
||||
|
@@ -61,7 +61,7 @@ static SDL_Mutex *SDL_CreateMutex_srw(void)
|
||||
SDL_mutex_srw *mutex;
|
||||
|
||||
mutex = (SDL_mutex_srw *)SDL_calloc(1, sizeof(*mutex));
|
||||
if (mutex == NULL) {
|
||||
if (!mutex) {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ static const SDL_mutex_impl_t SDL_mutex_impl_srw = {
|
||||
static SDL_Mutex *SDL_CreateMutex_cs(void)
|
||||
{
|
||||
SDL_mutex_cs *mutex = (SDL_mutex_cs *)SDL_malloc(sizeof(*mutex));
|
||||
if (mutex != NULL) {
|
||||
if (mutex) {
|
||||
// Initialize
|
||||
// On SMP systems, a non-zero spin count generally helps performance
|
||||
#ifdef __WINRT__
|
||||
@@ -199,7 +199,7 @@ static const SDL_mutex_impl_t SDL_mutex_impl_cs = {
|
||||
|
||||
SDL_Mutex *SDL_CreateMutex(void)
|
||||
{
|
||||
if (SDL_mutex_impl_active.Create == NULL) {
|
||||
if (!SDL_mutex_impl_active.Create) {
|
||||
// Default to fallback implementation
|
||||
const SDL_mutex_impl_t *impl = &SDL_mutex_impl_cs;
|
||||
|
||||
@@ -239,7 +239,7 @@ void SDL_DestroyMutex(SDL_Mutex *mutex)
|
||||
|
||||
void SDL_LockMutex(SDL_Mutex *mutex)
|
||||
{
|
||||
if (mutex != NULL) {
|
||||
if (mutex) {
|
||||
SDL_mutex_impl_active.Lock(mutex);
|
||||
}
|
||||
}
|
||||
@@ -251,7 +251,7 @@ int SDL_TryLockMutex(SDL_Mutex *mutex)
|
||||
|
||||
void SDL_UnlockMutex(SDL_Mutex *mutex)
|
||||
{
|
||||
if (mutex != NULL) {
|
||||
if (mutex) {
|
||||
SDL_mutex_impl_active.Unlock(mutex);
|
||||
}
|
||||
}
|
||||
|
@@ -88,7 +88,7 @@ typedef struct SDL_rwlock_srw
|
||||
static SDL_RWLock *SDL_CreateRWLock_srw(void)
|
||||
{
|
||||
SDL_rwlock_srw *rwlock = (SDL_rwlock_srw *)SDL_calloc(1, sizeof(*rwlock));
|
||||
if (rwlock == NULL) {
|
||||
if (!rwlock) {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
pInitializeSRWLock(&rwlock->srw);
|
||||
@@ -125,7 +125,7 @@ static int SDL_TryLockRWLockForReading_srw(SDL_RWLock *_rwlock)
|
||||
{
|
||||
SDL_rwlock_srw *rwlock = (SDL_rwlock_srw *) _rwlock;
|
||||
int retval = 0;
|
||||
if (rwlock != NULL) {
|
||||
if (rwlock) {
|
||||
retval = pTryAcquireSRWLockShared(&rwlock->srw) ? 0 : SDL_RWLOCK_TIMEDOUT;
|
||||
}
|
||||
return retval;
|
||||
@@ -135,7 +135,7 @@ static int SDL_TryLockRWLockForWriting_srw(SDL_RWLock *_rwlock)
|
||||
{
|
||||
SDL_rwlock_srw *rwlock = (SDL_rwlock_srw *) _rwlock;
|
||||
int retval = 0;
|
||||
if (rwlock != NULL) {
|
||||
if (rwlock) {
|
||||
retval = pTryAcquireSRWLockExclusive(&rwlock->srw) ? 0 : SDL_RWLOCK_TIMEDOUT;
|
||||
}
|
||||
return retval;
|
||||
@@ -182,7 +182,7 @@ static const SDL_rwlock_impl_t SDL_rwlock_impl_generic = {
|
||||
|
||||
SDL_RWLock *SDL_CreateRWLock(void)
|
||||
{
|
||||
if (SDL_rwlock_impl_active.Create == NULL) {
|
||||
if (!SDL_rwlock_impl_active.Create) {
|
||||
const SDL_rwlock_impl_t *impl;
|
||||
|
||||
#ifdef __WINRT__
|
||||
|
@@ -83,7 +83,7 @@ static SDL_Semaphore *SDL_CreateSemaphore_atom(Uint32 initial_value)
|
||||
SDL_sem_atom *sem;
|
||||
|
||||
sem = (SDL_sem_atom *)SDL_malloc(sizeof(*sem));
|
||||
if (sem != NULL) {
|
||||
if (sem) {
|
||||
sem->count = initial_value;
|
||||
} else {
|
||||
SDL_OutOfMemory();
|
||||
@@ -93,7 +93,7 @@ static SDL_Semaphore *SDL_CreateSemaphore_atom(Uint32 initial_value)
|
||||
|
||||
static void SDL_DestroySemaphore_atom(SDL_Semaphore *sem)
|
||||
{
|
||||
if (sem != NULL) {
|
||||
if (sem) {
|
||||
SDL_free(sem);
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ static int SDL_WaitSemaphoreTimeoutNS_atom(SDL_Semaphore *_sem, Sint64 timeoutNS
|
||||
Uint64 deadline;
|
||||
DWORD timeout_eff;
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ static Uint32 SDL_GetSemaphoreValue_atom(SDL_Semaphore *_sem)
|
||||
{
|
||||
SDL_sem_atom *sem = (SDL_sem_atom *)_sem;
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
@@ -188,7 +188,7 @@ static int SDL_PostSemaphore_atom(SDL_Semaphore *_sem)
|
||||
{
|
||||
SDL_sem_atom *sem = (SDL_sem_atom *)_sem;
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ static SDL_Semaphore *SDL_CreateSemaphore_kern(Uint32 initial_value)
|
||||
|
||||
/* Allocate sem memory */
|
||||
sem = (SDL_sem_kern *)SDL_malloc(sizeof(*sem));
|
||||
if (sem != NULL) {
|
||||
if (sem) {
|
||||
/* Create the semaphore, with max value 32K */
|
||||
#ifdef __WINRT__
|
||||
sem->id = CreateSemaphoreEx(NULL, initial_value, 32 * 1024, NULL, 0, SEMAPHORE_ALL_ACCESS);
|
||||
@@ -247,7 +247,7 @@ static SDL_Semaphore *SDL_CreateSemaphore_kern(Uint32 initial_value)
|
||||
static void SDL_DestroySemaphore_kern(SDL_Semaphore *_sem)
|
||||
{
|
||||
SDL_sem_kern *sem = (SDL_sem_kern *)_sem;
|
||||
if (sem != NULL) {
|
||||
if (sem) {
|
||||
if (sem->id) {
|
||||
CloseHandle(sem->id);
|
||||
sem->id = 0;
|
||||
@@ -262,7 +262,7 @@ static int SDL_WaitSemaphoreTimeoutNS_kern(SDL_Semaphore *_sem, Sint64 timeoutNS
|
||||
int retval;
|
||||
DWORD dwMilliseconds;
|
||||
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ static int SDL_WaitSemaphoreTimeoutNS_kern(SDL_Semaphore *_sem, Sint64 timeoutNS
|
||||
static Uint32 SDL_GetSemaphoreValue_kern(SDL_Semaphore *_sem)
|
||||
{
|
||||
SDL_sem_kern *sem = (SDL_sem_kern *)_sem;
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
SDL_InvalidParamError("sem");
|
||||
return 0;
|
||||
}
|
||||
@@ -300,7 +300,7 @@ static Uint32 SDL_GetSemaphoreValue_kern(SDL_Semaphore *_sem)
|
||||
static int SDL_PostSemaphore_kern(SDL_Semaphore *_sem)
|
||||
{
|
||||
SDL_sem_kern *sem = (SDL_sem_kern *)_sem;
|
||||
if (sem == NULL) {
|
||||
if (!sem) {
|
||||
return SDL_InvalidParamError("sem");
|
||||
}
|
||||
/* Increase the counter in the first place, because
|
||||
@@ -330,7 +330,7 @@ static const SDL_sem_impl_t SDL_sem_impl_kern = {
|
||||
|
||||
SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
{
|
||||
if (SDL_sem_impl_active.Create == NULL) {
|
||||
if (!SDL_sem_impl_active.Create) {
|
||||
/* Default to fallback implementation */
|
||||
const SDL_sem_impl_t *impl = &SDL_sem_impl_kern;
|
||||
|
||||
|
@@ -47,7 +47,7 @@ static DWORD RunThread(void *data)
|
||||
SDL_Thread *thread = (SDL_Thread *)data;
|
||||
pfnSDL_CurrentEndThread pfnEndThread = (pfnSDL_CurrentEndThread)thread->endfunc;
|
||||
SDL_RunThread(thread);
|
||||
if (pfnEndThread != NULL) {
|
||||
if (pfnEndThread) {
|
||||
pfnEndThread(0);
|
||||
}
|
||||
return 0;
|
||||
@@ -96,7 +96,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread)
|
||||
RunThreadViaCreateThread,
|
||||
thread, flags, &threadid);
|
||||
}
|
||||
if (thread->handle == NULL) {
|
||||
if (!thread->handle) {
|
||||
return SDL_SetError("Not enough resources to create thread");
|
||||
}
|
||||
return 0;
|
||||
@@ -116,7 +116,7 @@ typedef HRESULT(WINAPI *pfnSetThreadDescription)(HANDLE, PCWSTR);
|
||||
|
||||
void SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
if (name != NULL) {
|
||||
if (name) {
|
||||
#ifndef __WINRT__ /* !!! FIXME: There's no LoadLibrary() in WinRT; don't know if SetThreadDescription is available there at all at the moment. */
|
||||
static pfnSetThreadDescription pSetThreadDescription = NULL;
|
||||
static HMODULE kernel32 = NULL;
|
||||
@@ -128,7 +128,7 @@ void SDL_SYS_SetupThread(const char *name)
|
||||
}
|
||||
}
|
||||
|
||||
if (pSetThreadDescription != NULL) {
|
||||
if (pSetThreadDescription) {
|
||||
WCHAR *strw = WIN_UTF8ToStringW(name);
|
||||
if (strw) {
|
||||
pSetThreadDescription(GetCurrentThread(), strw);
|
||||
|
Reference in New Issue
Block a user