GBA Thread: Make GBASyncWaitFrameStart time out
Jeffrey Pfau jeffrey@endrift.com
Sat, 21 Feb 2015 03:44:15 -0800
3 files changed,
32 insertions(+),
1 deletions(-)
M
src/gba/supervisor/thread.c
→
src/gba/supervisor/thread.c
@@ -659,7 +659,9 @@ if (!sync->videoFrameOn && !sync->videoFramePending) {
return false; } if (sync->videoFrameOn) { - ConditionWait(&sync->videoFrameAvailableCond, &sync->videoFrameMutex); + if (ConditionWaitTimed(&sync->videoFrameAvailableCond, &sync->videoFrameMutex, 20)) { + return false; + } } sync->videoFramePending = 0; sync->videoFrameSkip = frameskip;
M
src/util/threading.h
→
src/util/threading.h
@@ -10,6 +10,7 @@ #include "util/common.h"
#ifdef USE_PTHREADS #include <pthread.h> +#include <sys/time.h> #define THREAD_ENTRY void* typedef THREAD_ENTRY (*ThreadEntry)(void*);@@ -46,6 +47,21 @@ static inline int ConditionWait(Condition* cond, Mutex* mutex) {
return pthread_cond_wait(cond, mutex); } +static inline int ConditionWaitTimed(Condition* cond, Mutex* mutex, int32_t timeoutMs) { + struct timespec ts; + struct timeval tv; + + gettimeofday(&tv, 0); + ts.tv_sec = tv.tv_sec; + ts.tv_nsec = (tv.tv_usec + timeoutMs * 1000L) * 1000L; + if (ts.tv_nsec >= 1000000000L) { + ts.tv_nsec -= 1000000000L; + ++ts.tv_sec; + } + + return pthread_cond_timedwait(cond, mutex, &ts); +} + static inline int ConditionWake(Condition* cond) { return pthread_cond_broadcast(cond); }@@ -101,6 +117,11 @@ }
static inline int ConditionWait(Condition* cond, Mutex* mutex) { SleepConditionVariableCS(cond, mutex, INFINITE); + return GetLastError(); +} + +static inline int ConditionWaitTimed(Condition* cond, Mutex* mutex, int32_t timeoutMs) { + SleepConditionVariableCS(cond, mutex, timeoutMs); return GetLastError(); }@@ -160,6 +181,13 @@
static inline int ConditionWait(Condition* cond, Mutex* mutex) { UNUSED(cond); UNUSED(mutex); + return 0; +} + +static inline int ConditionWaitTimed(Condition* cond, Mutex* mutex, int32_t timeoutMs) { + UNUSED(cond); + UNUSED(mutex); + UNUSED(timeoutMs); return 0; }