Functions for explicitly pausing and unpausing

This commit is contained in:
Jeffrey Pfau 2013-10-16 00:52:52 -07:00
parent a107243c7a
commit a1fb90635f
2 changed files with 39 additions and 1 deletions

View File

@ -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) {

View File

@ -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);