Expose GBASync{Suspend/Resume}Drawing
Jeffrey Pfau jeffrey@endrift.com
Sat, 18 Oct 2014 02:08:20 -0700
2 files changed,
21 insertions(+),
10 deletions(-)
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -76,14 +76,14 @@ _waitUntilNotState(threadContext, THREAD_PAUSING);
} } -static void _changeVideoSync(struct GBAThread* threadContext, bool frameOn) { +static void _changeVideoSync(struct GBASync* sync, bool frameOn) { // Make sure the video thread can process events while the GBA thread is paused - MutexLock(&threadContext->sync.videoFrameMutex); - if (frameOn != threadContext->sync.videoFrameOn) { - threadContext->sync.videoFrameOn = frameOn; - ConditionWake(&threadContext->sync.videoFrameAvailableCond); + MutexLock(&sync->videoFrameMutex); + if (frameOn != sync->videoFrameOn) { + sync->videoFrameOn = frameOn; + ConditionWake(&sync->videoFrameAvailableCond); } - MutexUnlock(&threadContext->sync.videoFrameMutex); + MutexUnlock(&sync->videoFrameMutex); } static THREAD_ENTRY _GBAThreadRun(void* context) {@@ -434,7 +434,7 @@ frameOn = false;
} MutexUnlock(&threadContext->stateMutex); - _changeVideoSync(threadContext, frameOn); + _changeVideoSync(&threadContext->sync, frameOn); } void GBAThreadUnpause(struct GBAThread* threadContext) {@@ -446,7 +446,7 @@ ConditionWake(&threadContext->stateCond);
} MutexUnlock(&threadContext->stateMutex); - _changeVideoSync(threadContext, true); + _changeVideoSync(&threadContext->sync, true); } bool GBAThreadIsPaused(struct GBAThread* threadContext) {@@ -471,7 +471,7 @@ frameOn = false;
} MutexUnlock(&threadContext->stateMutex); - _changeVideoSync(threadContext, frameOn); + _changeVideoSync(&threadContext->sync, frameOn); } void GBAThreadPauseFromThread(struct GBAThread* threadContext) {@@ -484,7 +484,7 @@ frameOn = false;
} MutexUnlock(&threadContext->stateMutex); - _changeVideoSync(threadContext, frameOn); + _changeVideoSync(&threadContext->sync, frameOn); } #ifdef USE_PTHREADS@@ -577,6 +577,14 @@ }
bool GBASyncDrawingFrame(struct GBASync* sync) { return sync->videoFrameSkip <= 0; +} + +void GBASyncSuspendDrawing(struct GBASync* sync) { + _changeVideoSync(sync, false); +} + +void GBASyncResumeDrawing(struct GBASync* sync) { + _changeVideoSync(sync, true); } void GBASyncProduceAudio(struct GBASync* sync, bool wait) {
M
src/gba/gba-thread.h
→
src/gba/gba-thread.h
@@ -121,6 +121,9 @@ bool GBASyncWaitFrameStart(struct GBASync* sync, int frameskip);
void GBASyncWaitFrameEnd(struct GBASync* sync); bool GBASyncDrawingFrame(struct GBASync* sync); +void GBASyncSuspendDrawing(struct GBASync* sync); +void GBASyncResumeDrawing(struct GBASync* sync); + void GBASyncProduceAudio(struct GBASync* sync, bool wait); void GBASyncLockAudio(struct GBASync* sync); void GBASyncUnlockAudio(struct GBASync* sync);