all repos — mgba @ a1fb90635fa80182447a8c2a1d6a21345a20c45d

mGBA Game Boy Advance Emulator

Functions for explicitly pausing and unpausing
Jeffrey Pfau jeffrey@endrift.com
Wed, 16 Oct 2013 00:52:52 -0700
commit

a1fb90635fa80182447a8c2a1d6a21345a20c45d

parent

a107243c7a95033961b5292bac20b406950bc77b

2 files changed, 39 insertions(+), 1 deletions(-)

jump to
M src/gba/gba-thread.csrc/gba/gba-thread.c

@@ -167,11 +167,47 @@ pthread_cond_broadcast(&threadContext->sync.audioRequiredCond);

pthread_cond_destroy(&threadContext->sync.audioRequiredCond); } +void GBAThreadPause(struct GBAThread* threadContext) { + int frameOn = 1; + pthread_mutex_lock(&threadContext->stateMutex); + if (threadContext->state == THREAD_RUNNING) { + if (threadContext->debugger && threadContext->debugger->state == DEBUGGER_RUNNING) { + threadContext->debugger->state = DEBUGGER_EXITING; + } + threadContext->state = THREAD_PAUSED; + frameOn = 0; + } + pthread_mutex_unlock(&threadContext->stateMutex); + pthread_mutex_lock(&threadContext->sync.videoFrameMutex); + if (frameOn != threadContext->sync.videoFrameOn) { + threadContext->sync.videoFrameOn = frameOn; + pthread_cond_broadcast(&threadContext->sync.videoFrameAvailableCond); + } + pthread_mutex_unlock(&threadContext->sync.videoFrameMutex); +} + +void GBAThreadUnpause(struct GBAThread* threadContext) { + int frameOn = 1; + pthread_mutex_lock(&threadContext->stateMutex); + if (threadContext->state == THREAD_PAUSED) { + threadContext->state = THREAD_RUNNING; + pthread_cond_broadcast(&threadContext->stateCond); + } + pthread_mutex_unlock(&threadContext->stateMutex); + pthread_mutex_lock(&threadContext->sync.videoFrameMutex); + if (frameOn != threadContext->sync.videoFrameOn) { + threadContext->sync.videoFrameOn = frameOn; + pthread_cond_broadcast(&threadContext->sync.videoFrameAvailableCond); + } + pthread_mutex_unlock(&threadContext->sync.videoFrameMutex); +} + void GBAThreadTogglePause(struct GBAThread* threadContext) { int frameOn = 1; pthread_mutex_lock(&threadContext->stateMutex); if (threadContext->state == THREAD_PAUSED) { threadContext->state = THREAD_RUNNING; + pthread_cond_broadcast(&threadContext->stateCond); } else if (threadContext->state == THREAD_RUNNING) { if (threadContext->debugger && threadContext->debugger->state == DEBUGGER_RUNNING) { threadContext->debugger->state = DEBUGGER_EXITING;

@@ -179,7 +215,6 @@ }

threadContext->state = THREAD_PAUSED; frameOn = 0; } - pthread_cond_broadcast(&threadContext->stateCond); pthread_mutex_unlock(&threadContext->stateMutex); pthread_mutex_lock(&threadContext->sync.videoFrameMutex); if (frameOn != threadContext->sync.videoFrameOn) {
M src/gba/gba-thread.hsrc/gba/gba-thread.h

@@ -54,6 +54,9 @@ };

int GBAThreadStart(struct GBAThread* threadContext); void GBAThreadJoin(struct GBAThread* threadContext); + +void GBAThreadPause(struct GBAThread* threadContext); +void GBAThreadUnpause(struct GBAThread* threadContext); void GBAThreadTogglePause(struct GBAThread* threadContext); struct GBAThread* GBAThreadGetContext(void);