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;
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());

View file

@ -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();

View file

@ -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)

View file

@ -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;
}

View file

@ -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)
);

View file

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

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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");
}
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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;