From a1fb90635fa80182447a8c2a1d6a21345a20c45d Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Wed, 16 Oct 2013 00:52:52 -0700 Subject: [PATCH] Functions for explicitly pausing and unpausing --- src/gba/gba-thread.c | 37 ++++++++++++++++++++++++++++++++++++- src/gba/gba-thread.h | 3 +++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/gba/gba-thread.c b/src/gba/gba-thread.c index 8bb1e642a..47a6fc575 100644 --- a/src/gba/gba-thread.c +++ b/src/gba/gba-thread.c @@ -167,11 +167,47 @@ void GBAThreadJoin(struct GBAThread* threadContext) { 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 @@ void GBAThreadTogglePause(struct GBAThread* threadContext) { 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) { diff --git a/src/gba/gba-thread.h b/src/gba/gba-thread.h index 8974050ca..97c683ce4 100644 --- a/src/gba/gba-thread.h +++ b/src/gba/gba-thread.h @@ -54,6 +54,9 @@ struct GBAThread { 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);