Functions for explicitly pausing and unpausing
Jeffrey Pfau jeffrey@endrift.com
Wed, 16 Oct 2013 00:52:52 -0700
2 files changed,
39 insertions(+),
1 deletions(-)
M
src/gba/gba-thread.c
→
src/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.h
→
src/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);