thread: code style

This commit is contained in:
pionere
2022-11-29 17:30:03 +01:00
committed by Sam Lantinga
parent 38c281fbc0
commit 461a38ff1a
12 changed files with 35 additions and 38 deletions

View File

@@ -72,7 +72,7 @@ static void WaitAll(SDL_sem *sem)
RSemaphore sema; RSemaphore sema;
sema.SetHandle(sem->handle); sema.SetHandle(sem->handle);
sema.Wait(); sema.Wait();
while(sem->count < 0) { while (sem->count < 0) {
sema.Wait(); sema.Wait();
} }
} }
@@ -94,7 +94,7 @@ SDL_CreateSemaphore(Uint32 initial_value)
void void
SDL_DestroySemaphore(SDL_sem * sem) SDL_DestroySemaphore(SDL_sem * sem)
{ {
if (sem) { if (sem != NULL) {
RSemaphore sema; RSemaphore sema;
sema.SetHandle(sem->handle); sema.SetHandle(sem->handle);
sema.Signal(sema.Count()); sema.Signal(sema.Count());

View File

@@ -52,13 +52,11 @@ CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny* aPtr1, TAny*
{ {
TBuf<16> name; TBuf<16> name;
TInt status = KErrNone; TInt status = KErrNone;
do do {
{
object_count++; object_count++;
name.Format(_L("SDL_%x"), object_count); name.Format(_L("SDL_%x"), object_count);
status = aFunc(name, aPtr1, aPtr2); status = aFunc(name, aPtr1, aPtr2);
} } while (status == KErrAlreadyExists);
while(status == KErrAlreadyExists);
return status; return status;
} }
@@ -71,8 +69,7 @@ SDL_SYS_CreateThread(SDL_Thread *thread)
if (status != KErrNone) { if (status != KErrNone) {
delete(((RThread*)(thread->handle))); delete(((RThread*)(thread->handle)));
thread->handle = NULL; thread->handle = NULL;
SDL_SetError("Not enough resources to create thread"); return SDL_SetError("Not enough resources to create thread");
return -1;
} }
rthread.Resume(); rthread.Resume();

View File

@@ -83,7 +83,7 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
int ret; int ret;
struct timer_alarm_t alarm; struct timer_alarm_t alarm;
InitializeTimerAlarm(&alarm); InitializeTimerAlarm(&alarm);
if (sem == NULL) { if (sem == NULL) {
return SDL_InvalidParamError("sem"); return SDL_InvalidParamError("sem");
} }
@@ -105,7 +105,7 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
if (ret < 0) { if (ret < 0) {
return SDL_MUTEX_TIMEDOUT; return SDL_MUTEX_TIMEDOUT;
} }
return 0; //Wait condition satisfied. return 0; // Wait condition satisfied.
} }
int SDL_SemTryWait(SDL_sem *sem) int SDL_SemTryWait(SDL_sem *sem)

View File

@@ -44,7 +44,7 @@ SDL_sem *
SDL_CreateSemaphore(Uint32 initial_value) SDL_CreateSemaphore(Uint32 initial_value)
{ {
SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem)); SDL_sem *sem = (SDL_sem *) SDL_malloc(sizeof(SDL_sem));
if (sem) { if (sem != NULL) {
if (sem_init(&sem->sem, 0, initial_value) < 0) { if (sem_init(&sem->sem, 0, initial_value) < 0) {
SDL_SetError("sem_init() failed"); SDL_SetError("sem_init() failed");
SDL_free(sem); SDL_free(sem);
@@ -59,7 +59,7 @@ SDL_CreateSemaphore(Uint32 initial_value)
void void
SDL_DestroySemaphore(SDL_sem * sem) SDL_DestroySemaphore(SDL_sem * sem)
{ {
if (sem) { if (sem != NULL) {
sem_destroy(&sem->sem); sem_destroy(&sem->sem);
SDL_free(sem); SDL_free(sem);
} }
@@ -179,7 +179,7 @@ SDL_SemValue(SDL_sem * sem)
{ {
int ret = 0; int ret = 0;
if (!sem) { if (sem == NULL) {
SDL_InvalidParamError("sem"); SDL_InvalidParamError("sem");
return 0; return 0;
} }

View File

@@ -58,7 +58,7 @@ extern "C"
void void
SDL_DestroyCond(SDL_cond * cond) SDL_DestroyCond(SDL_cond * cond)
{ {
if (cond) { if (cond != NULL) {
delete cond; delete cond;
} }
} }
@@ -114,11 +114,11 @@ extern "C"
int int
SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms) SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
{ {
if (!cond) { if (cond == NULL) {
return SDL_InvalidParamError("cond"); return SDL_InvalidParamError("cond");
} }
if (!mutex) { if (mutex == NULL) {
return SDL_InvalidParamError("mutex"); return SDL_InvalidParamError("mutex");
} }
@@ -131,7 +131,7 @@ SDL_CondWaitTimeout(SDL_cond * cond, SDL_mutex * mutex, Uint32 ms)
cpp_lock.release(); cpp_lock.release();
return 0; return 0;
} else { } else {
auto wait_result = cond->cpp_cond.wait_for ( auto wait_result = cond->cpp_cond.wait_for(
cpp_lock, cpp_lock,
std::chrono::duration<Uint32, std::milli>(ms) std::chrono::duration<Uint32, std::milli>(ms)
); );

View File

@@ -53,7 +53,7 @@ extern "C"
void void
SDL_DestroyMutex(SDL_mutex * mutex) SDL_DestroyMutex(SDL_mutex * mutex)
{ {
if (mutex) { if (mutex != NULL) {
delete mutex; delete mutex;
} }
} }

View File

@@ -45,7 +45,7 @@ SDL_CreateCond(void)
SDL_cond *cond; SDL_cond *cond;
cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond)); cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
if (cond) { if (cond != NULL) {
cond->lock = SDL_CreateMutex(); cond->lock = SDL_CreateMutex();
cond->wait_sem = SDL_CreateSemaphore(0); cond->wait_sem = SDL_CreateSemaphore(0);
cond->wait_done = SDL_CreateSemaphore(0); cond->wait_done = SDL_CreateSemaphore(0);
@@ -64,7 +64,7 @@ SDL_CreateCond(void)
void void
SDL_DestroyCond(SDL_cond * cond) SDL_DestroyCond(SDL_cond * cond)
{ {
if (cond) { if (cond != NULL) {
if (cond->wait_sem) { if (cond->wait_sem) {
SDL_DestroySemaphore(cond->wait_sem); SDL_DestroySemaphore(cond->wait_sem);
} }

View File

@@ -41,7 +41,7 @@ SDL_CreateMutex(void)
/* Allocate mutex memory */ /* Allocate mutex memory */
mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex)); mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
if (mutex) { if (mutex != NULL) {
res = sceKernelCreateLwMutex( res = sceKernelCreateLwMutex(
&mutex->lock, &mutex->lock,
@@ -64,7 +64,7 @@ SDL_CreateMutex(void)
void void
SDL_DestroyMutex(SDL_mutex * mutex) SDL_DestroyMutex(SDL_mutex * mutex)
{ {
if (mutex) { if (mutex != NULL) {
sceKernelDeleteLwMutex(&mutex->lock); sceKernelDeleteLwMutex(&mutex->lock);
SDL_free(mutex); SDL_free(mutex);
} }

View File

@@ -78,7 +78,7 @@ void SDL_DestroySemaphore(SDL_sem *sem)
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout) int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
{ {
Uint32 *pTimeout; Uint32 *pTimeout;
unsigned int res; unsigned int res;
if (sem == NULL) { if (sem == NULL) {
return SDL_InvalidParamError("sem"); return SDL_InvalidParamError("sem");
@@ -100,13 +100,13 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
} }
res = sceKernelWaitSema(sem->semid, 1, pTimeout); res = sceKernelWaitSema(sem->semid, 1, pTimeout);
switch (res) { switch (res) {
case SCE_KERNEL_OK: case SCE_KERNEL_OK:
return 0; return 0;
case SCE_KERNEL_ERROR_WAIT_TIMEOUT: case SCE_KERNEL_ERROR_WAIT_TIMEOUT:
return SDL_MUTEX_TIMEDOUT; return SDL_MUTEX_TIMEDOUT;
default: default:
return SDL_SetError("WaitForSingleObject() failed"); return SDL_SetError("WaitForSingleObject() failed");
} }
} }

View File

@@ -96,7 +96,7 @@ SDL_CreateCond_cv(void)
static void static void
SDL_DestroyCond_cv(SDL_cond * cond) SDL_DestroyCond_cv(SDL_cond * cond)
{ {
if (cond) { if (cond != NULL) {
/* There are no kernel allocated resources */ /* There are no kernel allocated resources */
SDL_free(cond); SDL_free(cond);
} }

View File

@@ -74,7 +74,7 @@ SDL_CreateMutex_srw(void)
static void static void
SDL_DestroyMutex_srw(SDL_mutex * mutex) SDL_DestroyMutex_srw(SDL_mutex * mutex)
{ {
if (mutex) { if (mutex != NULL) {
/* There are no kernel allocated resources */ /* There are no kernel allocated resources */
SDL_free(mutex); SDL_free(mutex);
} }
@@ -176,7 +176,7 @@ SDL_CreateMutex_cs(void)
/* Allocate mutex memory */ /* Allocate mutex memory */
mutex = (SDL_mutex_cs *) SDL_malloc(sizeof(*mutex)); mutex = (SDL_mutex_cs *) SDL_malloc(sizeof(*mutex));
if (mutex) { if (mutex != NULL) {
/* Initialize */ /* Initialize */
/* On SMP systems, a non-zero spin count generally helps performance */ /* On SMP systems, a non-zero spin count generally helps performance */
#if __WINRT__ #if __WINRT__
@@ -195,7 +195,7 @@ static void
SDL_DestroyMutex_cs(SDL_mutex * mutex_) SDL_DestroyMutex_cs(SDL_mutex * mutex_)
{ {
SDL_mutex_cs *mutex = (SDL_mutex_cs *)mutex_; SDL_mutex_cs *mutex = (SDL_mutex_cs *)mutex_;
if (mutex) { if (mutex != NULL) {
DeleteCriticalSection(&mutex->cs); DeleteCriticalSection(&mutex->cs);
SDL_free(mutex); SDL_free(mutex);
} }

View File

@@ -96,7 +96,7 @@ SDL_CreateSemaphore_atom(Uint32 initial_value)
SDL_sem_atom *sem; SDL_sem_atom *sem;
sem = (SDL_sem_atom *) SDL_malloc(sizeof(*sem)); sem = (SDL_sem_atom *) SDL_malloc(sizeof(*sem));
if (sem) { if (sem != NULL) {
sem->count = initial_value; sem->count = initial_value;
} else { } else {
SDL_OutOfMemory(); SDL_OutOfMemory();
@@ -107,7 +107,7 @@ SDL_CreateSemaphore_atom(Uint32 initial_value)
static void static void
SDL_DestroySemaphore_atom(SDL_sem * sem) SDL_DestroySemaphore_atom(SDL_sem * sem)
{ {
if (sem) { if (sem != NULL) {
SDL_free(sem); SDL_free(sem);
} }
} }
@@ -269,7 +269,7 @@ SDL_CreateSemaphore_kern(Uint32 initial_value)
/* Allocate sem memory */ /* Allocate sem memory */
sem = (SDL_sem_kern *) SDL_malloc(sizeof(*sem)); sem = (SDL_sem_kern *) SDL_malloc(sizeof(*sem));
if (sem) { if (sem != NULL) {
/* Create the semaphore, with max value 32K */ /* Create the semaphore, with max value 32K */
#if __WINRT__ #if __WINRT__
sem->id = CreateSemaphoreEx(NULL, initial_value, 32 * 1024, NULL, 0, SEMAPHORE_ALL_ACCESS); 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_DestroySemaphore_kern(SDL_sem * _sem)
{ {
SDL_sem_kern *sem = (SDL_sem_kern *)_sem; SDL_sem_kern *sem = (SDL_sem_kern *)_sem;
if (sem) { if (sem != NULL) {
if (sem->id) { if (sem->id) {
CloseHandle(sem->id); CloseHandle(sem->id);
sem->id = 0; sem->id = 0;