diff --git a/libretro.h b/libretro.h index 57d12a4..3eef758 100755 --- a/libretro.h +++ b/libretro.h @@ -3,6 +3,7 @@ #include #include +#include // Hack applied for MSVC when compiling in C89 mode as it isn't C99 compliant. #ifdef __cplusplus @@ -380,7 +381,10 @@ enum retro_pixel_format // RGB565, native endian. This pixel format is the recommended format to use if a 15/16-bit format is desired // as it is the pixel format that is typically available on a wide range of low-power devices. // It is also natively supported in APIs like OpenGL ES. - RETRO_PIXEL_FORMAT_RGB565 = 2 + RETRO_PIXEL_FORMAT_RGB565 = 2, + + // Ensure sizeof() == sizeof(int). + RETRO_PIXEL_FORMAT_UNKNOWN = INT_MAX }; struct retro_message diff --git a/thread.cpp b/thread.cpp index af9d068..85c5a65 100644 --- a/thread.cpp +++ b/thread.cpp @@ -21,11 +21,18 @@ #include #elif defined(_XBOX) #include +#elif defined(GEKKO) +#include "thread/gx_pthread.h" #else #include #include #endif +#ifdef __MACH__ +#include +#include +#endif + struct thread_data { void (*func)(void*); @@ -143,6 +150,17 @@ void scond_wait(scond_t *cond, slock_t *lock) slock_lock(lock); } +int scond_wait_timeout(scond_t *cond, slock_t *lock, unsigned timeout_ms) +{ + WaitForSingleObject(cond->event, 0); + slock_unlock(lock); + + DWORD res = WaitForSingleObject(cond->event, timeout_ms); + + slock_lock(lock); + return res == WAIT_OBJECT_0; +} + void scond_signal(scond_t *cond) { SetEvent(cond->event); diff --git a/thread/gx_pthread.h b/thread/gx_pthread.h new file mode 100644 index 0000000..c014b62 --- /dev/null +++ b/thread/gx_pthread.h @@ -0,0 +1,96 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef _GX_PTHREAD_WRAP_GX_ +#define _GX_PTHREAD_WRAP_GX_ + +#include +#include +#include + +#define STACKSIZE (8 * 1024) + +typedef lwp_t pthread_t; +typedef mutex_t pthread_mutex_t; +typedef void* pthread_mutexattr_t; +typedef int pthread_attr_t; +typedef cond_t pthread_cond_t; +typedef cond_t pthread_condattr_t; + +static inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg) +{ + *thread = 0; + return LWP_CreateThread(thread, start_routine, arg, 0, STACKSIZE, 64); +} + +static inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) +{ + return LWP_MutexInit(mutex, 0); +} + +static inline int pthread_mutex_destroy(pthread_mutex_t *mutex) +{ + return LWP_MutexDestroy(*mutex); +} + +static inline int pthread_mutex_lock(pthread_mutex_t *mutex) +{ + return LWP_MutexLock(*mutex); +} + +static inline int pthread_mutex_unlock(pthread_mutex_t *mutex) +{ + return LWP_MutexUnlock(*mutex); +} + +static inline int pthread_join(pthread_t thread, void **retval) +{ + // FIXME: Shouldn't the second arg to LWP_JoinThread take retval? + (void)retval; + return LWP_JoinThread(thread, NULL); +} + +static inline int pthread_mutex_trylock(pthread_mutex_t *mutex) +{ + return LWP_MutexTryLock(*mutex); +} + +static inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) +{ + return LWP_CondWait(*cond, *mutex); +} + +static inline int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime) +{ + return LWP_CondWait(*cond, *mutex); +} + +static inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) +{ + return LWP_CondInit(cond); +} + +static inline int pthread_cond_signal(pthread_cond_t *cond) +{ + return LWP_CondSignal(*cond); +} + +static inline int pthread_cond_destroy(pthread_cond_t *cond) +{ + return LWP_CondDestroy(*cond); +} + +#endif