GBA Thread: Make GBASyncWaitFrameStart time out

This commit is contained in:
Jeffrey Pfau 2015-02-21 03:44:15 -08:00
parent 37fd51df39
commit 8a90066965
3 changed files with 32 additions and 1 deletions

View File

@ -64,6 +64,7 @@ Misc:
- Qt: Optimize logo drawing
- Qt: Move frame upload back onto main thread
- All: Enable link-time optimization
- GBA Thread: Make GBASyncWaitFrameStart time out
0.1.1: (2015-01-24)
Bugfixes:

View File

@ -659,7 +659,9 @@ bool GBASyncWaitFrameStart(struct GBASync* sync, int frameskip) {
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;

View File

@ -10,6 +10,7 @@
#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);
}
@ -104,6 +120,11 @@ static inline int ConditionWait(Condition* cond, Mutex* mutex) {
return GetLastError();
}
static inline int ConditionWaitTimed(Condition* cond, Mutex* mutex, int32_t timeoutMs) {
SleepConditionVariableCS(cond, mutex, timeoutMs);
return GetLastError();
}
static inline int ConditionWake(Condition* cond) {
WakeAllConditionVariable(cond);
return GetLastError();
@ -163,6 +184,13 @@ static inline int ConditionWait(Condition* cond, Mutex* mutex) {
return 0;
}
static inline int ConditionWaitTimed(Condition* cond, Mutex* mutex, int32_t timeoutMs) {
UNUSED(cond);
UNUSED(mutex);
UNUSED(timeoutMs);
return 0;
}
static inline int ConditionWake(Condition* cond) {
UNUSED(cond);
return 0;