mirror of
https://github.com/yawut/SDL.git
synced 2026-09-07 00:25:37 -05:00
File style cleanup for the SDL 2.0 release
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
#include "SDL_systhread.h"
|
||||
#include "../SDL_error_c.h"
|
||||
|
||||
#define ARRAY_CHUNKSIZE 32
|
||||
#define ARRAY_CHUNKSIZE 32
|
||||
/* The array of threads currently active in the application
|
||||
(except the main thread)
|
||||
The manipulation of an array here is safer than using a linked list.
|
||||
|
||||
@@ -31,42 +31,42 @@
|
||||
#include <pspkerror.h>
|
||||
|
||||
struct SDL_semaphore {
|
||||
SceUID semid;
|
||||
SceUID semid;
|
||||
};
|
||||
|
||||
|
||||
/* Create a semaphore */
|
||||
SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
|
||||
{
|
||||
SDL_sem *sem;
|
||||
SDL_sem *sem;
|
||||
|
||||
sem = (SDL_sem *) malloc(sizeof(*sem));
|
||||
if (sem != NULL) {
|
||||
/* TODO: Figure out the limit on the maximum value. */
|
||||
sem->semid = sceKernelCreateSema("SDL sema", 0, initial_value, 255, NULL);
|
||||
if (sem->semid < 0) {
|
||||
SDL_SetError("Couldn't create semaphore");
|
||||
free(sem);
|
||||
sem = NULL;
|
||||
}
|
||||
} else {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
sem = (SDL_sem *) malloc(sizeof(*sem));
|
||||
if (sem != NULL) {
|
||||
/* TODO: Figure out the limit on the maximum value. */
|
||||
sem->semid = sceKernelCreateSema("SDL sema", 0, initial_value, 255, NULL);
|
||||
if (sem->semid < 0) {
|
||||
SDL_SetError("Couldn't create semaphore");
|
||||
free(sem);
|
||||
sem = NULL;
|
||||
}
|
||||
} else {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
return sem;
|
||||
return sem;
|
||||
}
|
||||
|
||||
/* Free the semaphore */
|
||||
void SDL_DestroySemaphore(SDL_sem *sem)
|
||||
{
|
||||
if (sem != NULL) {
|
||||
if (sem->semid > 0) {
|
||||
sceKernelDeleteSema(sem->semid);
|
||||
sem->semid = 0;
|
||||
}
|
||||
if (sem != NULL) {
|
||||
if (sem->semid > 0) {
|
||||
sceKernelDeleteSema(sem->semid);
|
||||
sem->semid = 0;
|
||||
}
|
||||
|
||||
free(sem);
|
||||
}
|
||||
free(sem);
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO: This routine is a bit overloaded.
|
||||
@@ -75,30 +75,30 @@ void SDL_DestroySemaphore(SDL_sem *sem)
|
||||
* is specified, convert it to microseconds. */
|
||||
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
|
||||
{
|
||||
Uint32 *pTimeout;
|
||||
Uint32 *pTimeout;
|
||||
unsigned int res;
|
||||
|
||||
if (sem == NULL) {
|
||||
SDL_SetError("Passed a NULL sem");
|
||||
return 0;
|
||||
}
|
||||
if (sem == NULL) {
|
||||
SDL_SetError("Passed a NULL sem");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (timeout == 0) {
|
||||
res = sceKernelPollSema(sem->semid, 1);
|
||||
if (res < 0) {
|
||||
return SDL_MUTEX_TIMEDOUT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (timeout == 0) {
|
||||
res = sceKernelPollSema(sem->semid, 1);
|
||||
if (res < 0) {
|
||||
return SDL_MUTEX_TIMEDOUT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (timeout == SDL_MUTEX_MAXWAIT) {
|
||||
pTimeout = NULL;
|
||||
} else {
|
||||
timeout *= 1000; /* Convert to microseconds. */
|
||||
pTimeout = &timeout;
|
||||
}
|
||||
if (timeout == SDL_MUTEX_MAXWAIT) {
|
||||
pTimeout = NULL;
|
||||
} else {
|
||||
timeout *= 1000; /* Convert to microseconds. */
|
||||
pTimeout = &timeout;
|
||||
}
|
||||
|
||||
res = sceKernelWaitSema(sem->semid, 1, pTimeout);
|
||||
res = sceKernelWaitSema(sem->semid, 1, pTimeout);
|
||||
switch (res) {
|
||||
case SCE_KERNEL_ERROR_OK:
|
||||
return 0;
|
||||
@@ -106,50 +106,50 @@ int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
|
||||
return SDL_MUTEX_TIMEDOUT;
|
||||
default:
|
||||
return SDL_SetError("WaitForSingleObject() failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int SDL_SemTryWait(SDL_sem *sem)
|
||||
{
|
||||
return SDL_SemWaitTimeout(sem, 0);
|
||||
return SDL_SemWaitTimeout(sem, 0);
|
||||
}
|
||||
|
||||
int SDL_SemWait(SDL_sem *sem)
|
||||
{
|
||||
return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
|
||||
return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
|
||||
}
|
||||
|
||||
/* Returns the current count of the semaphore */
|
||||
Uint32 SDL_SemValue(SDL_sem *sem)
|
||||
{
|
||||
SceKernelSemaInfo info;
|
||||
SceKernelSemaInfo info;
|
||||
|
||||
if (sem == NULL) {
|
||||
SDL_SetError("Passed a NULL sem");
|
||||
return 0;
|
||||
}
|
||||
if (sem == NULL) {
|
||||
SDL_SetError("Passed a NULL sem");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sceKernelReferSemaStatus(sem->semid, &info) >= 0) {
|
||||
return info.currentCount;
|
||||
}
|
||||
if (sceKernelReferSemaStatus(sem->semid, &info) >= 0) {
|
||||
return info.currentCount;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDL_SemPost(SDL_sem *sem)
|
||||
{
|
||||
int res;
|
||||
int res;
|
||||
|
||||
if (sem == NULL) {
|
||||
return SDL_SetError("Passed a NULL sem");
|
||||
}
|
||||
if (sem == NULL) {
|
||||
return SDL_SetError("Passed a NULL sem");
|
||||
}
|
||||
|
||||
res = sceKernelSignalSema(sem->semid, 1);
|
||||
if (res < 0) {
|
||||
return SDL_SetError("sceKernelSignalSema() failed");
|
||||
}
|
||||
res = sceKernelSignalSema(sem->semid, 1);
|
||||
if (res < 0) {
|
||||
return SDL_SetError("sceKernelSignalSema() failed");
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vim: ts=4 sw=4
|
||||
|
||||
@@ -35,57 +35,57 @@
|
||||
|
||||
static int ThreadEntry(SceSize args, void *argp)
|
||||
{
|
||||
SDL_RunThread(*(void **) argp);
|
||||
return 0;
|
||||
SDL_RunThread(*(void **) argp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
|
||||
{
|
||||
SceKernelThreadInfo status;
|
||||
int priority = 32;
|
||||
SceKernelThreadInfo status;
|
||||
int priority = 32;
|
||||
|
||||
/* Set priority of new thread to the same as the current thread */
|
||||
status.size = sizeof(SceKernelThreadInfo);
|
||||
if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) {
|
||||
priority = status.currentPriority;
|
||||
}
|
||||
/* Set priority of new thread to the same as the current thread */
|
||||
status.size = sizeof(SceKernelThreadInfo);
|
||||
if (sceKernelReferThreadStatus(sceKernelGetThreadId(), &status) == 0) {
|
||||
priority = status.currentPriority;
|
||||
}
|
||||
|
||||
thread->handle = sceKernelCreateThread("SDL thread", ThreadEntry,
|
||||
priority, 0x8000,
|
||||
PSP_THREAD_ATTR_VFPU, NULL);
|
||||
if (thread->handle < 0) {
|
||||
return SDL_SetError("sceKernelCreateThread() failed");
|
||||
}
|
||||
thread->handle = sceKernelCreateThread("SDL thread", ThreadEntry,
|
||||
priority, 0x8000,
|
||||
PSP_THREAD_ATTR_VFPU, NULL);
|
||||
if (thread->handle < 0) {
|
||||
return SDL_SetError("sceKernelCreateThread() failed");
|
||||
}
|
||||
|
||||
sceKernelStartThread(thread->handle, 4, &args);
|
||||
return 0;
|
||||
sceKernelStartThread(thread->handle, 4, &args);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SDL_SYS_SetupThread(const char *name)
|
||||
{
|
||||
/* Do nothing. */
|
||||
/* Do nothing. */
|
||||
}
|
||||
|
||||
SDL_threadID SDL_ThreadID(void)
|
||||
{
|
||||
return (SDL_threadID) sceKernelGetThreadId();
|
||||
return (SDL_threadID) sceKernelGetThreadId();
|
||||
}
|
||||
|
||||
void SDL_SYS_WaitThread(SDL_Thread *thread)
|
||||
{
|
||||
sceKernelWaitThreadEnd(thread->handle, NULL);
|
||||
sceKernelDeleteThread(thread->handle);
|
||||
sceKernelWaitThreadEnd(thread->handle, NULL);
|
||||
sceKernelDeleteThread(thread->handle);
|
||||
}
|
||||
|
||||
void SDL_SYS_KillThread(SDL_Thread *thread)
|
||||
{
|
||||
sceKernelTerminateDeleteThread(thread->handle);
|
||||
{
|
||||
sceKernelTerminateDeleteThread(thread->handle);
|
||||
}
|
||||
|
||||
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
{
|
||||
{
|
||||
int value;
|
||||
|
||||
|
||||
if (priority == SDL_THREAD_PRIORITY_LOW) {
|
||||
value = 19;
|
||||
} else if (priority == SDL_THREAD_PRIORITY_HIGH) {
|
||||
@@ -93,7 +93,7 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
|
||||
} else {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
|
||||
return sceKernelChangeThreadPriority(sceKernelGetThreadId(),value);
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#include <sys/resource.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
#endif // __LINUX__
|
||||
#endif /* __LINUX__ */
|
||||
|
||||
#if defined(__LINUX__) || defined(__MACOSX__) || defined(__IPHONEOS__)
|
||||
#include <dlfcn.h>
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
/* Cygwin gcc-3 ... MingW64 (even with a i386 host) does this like MSVC. */
|
||||
#if (defined(__MINGW32__) && (__GNUC__ < 4))
|
||||
typedef unsigned long (__cdecl *pfnSDL_CurrentBeginThread) (void *, unsigned,
|
||||
unsigned (__stdcall *func)(void *), void *arg,
|
||||
unsigned (__stdcall *func)(void *), void *arg,
|
||||
unsigned, unsigned *threadID);
|
||||
typedef void (__cdecl *pfnSDL_CurrentEndThread)(unsigned code);
|
||||
|
||||
@@ -118,9 +118,9 @@ SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
|
||||
if (!pThreadParms) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
// Save the function which we will have to call to clear the RTL of calling app!
|
||||
/* Save the function which we will have to call to clear the RTL of calling app! */
|
||||
pThreadParms->pfnCurrentEndThread = pfnEndThread;
|
||||
// Also save the real parameters we have to pass to thread function
|
||||
/* Also save the real parameters we have to pass to thread function */
|
||||
pThreadParms->args = args;
|
||||
|
||||
if (pfnBeginThread) {
|
||||
|
||||
Reference in New Issue
Block a user