From c20efb42ffdda29e8ba1540b493805cee5158ef4 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sat, 11 May 2013 21:07:10 -0700 Subject: [PATCH] Clean up thread locking in the software renderer --- src/gba/renderers/video-software.c | 4 ++++ src/sdl/main.c | 19 ++++--------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/gba/renderers/video-software.c b/src/gba/renderers/video-software.c index 54d41c9ab..f8935f202 100644 --- a/src/gba/renderers/video-software.c +++ b/src/gba/renderers/video-software.c @@ -108,6 +108,10 @@ static void GBAVideoSoftwareRendererInit(struct GBAVideoRenderer* renderer) { static void GBAVideoSoftwareRendererDeinit(struct GBAVideoRenderer* renderer) { struct GBAVideoSoftwareRenderer* softwareRenderer = (struct GBAVideoSoftwareRenderer*) renderer; + pthread_mutex_lock(&softwareRenderer->mutex); + pthread_cond_broadcast(&softwareRenderer->upCond); + pthread_mutex_unlock(&softwareRenderer->mutex); + pthread_mutex_destroy(&softwareRenderer->mutex); pthread_cond_destroy(&softwareRenderer->upCond); pthread_cond_destroy(&softwareRenderer->downCond); diff --git a/src/sdl/main.c b/src/sdl/main.c index 4cad51df6..3826e1ef9 100644 --- a/src/sdl/main.c +++ b/src/sdl/main.c @@ -110,7 +110,6 @@ static int _GBASDLInit(struct GLSoftwareRenderer* renderer) { static void _GBASDLRunloop(struct GBAThread* context, struct GLSoftwareRenderer* renderer) { SDL_Event event; - int err; glEnable(GL_TEXTURE_2D); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); @@ -119,7 +118,7 @@ static void _GBASDLRunloop(struct GBAThread* context, struct GLSoftwareRenderer* glMatrixMode (GL_PROJECTION); glLoadIdentity(); glOrtho(0, 240, 160, 0, 0, 1); - while (context->started) { + while (context->started && context->debugger->state != DEBUGGER_EXITING) { pthread_mutex_lock(&renderer->d.mutex); if (renderer->d.d.framesPending) { renderer->d.d.framesPending = 0; @@ -135,21 +134,11 @@ static void _GBASDLRunloop(struct GBAThread* context, struct GLSoftwareRenderer* } pthread_mutex_lock(&renderer->d.mutex); pthread_cond_broadcast(&renderer->d.downCond); - pthread_mutex_unlock(&renderer->d.mutex); } else { - while (!renderer->d.d.framesPending) { - struct timeval tv; - struct timespec ts; - gettimeofday(&tv, 0); - ts.tv_sec = tv.tv_sec; - ts.tv_nsec = tv.tv_usec * 1000 + 800000; - err = pthread_cond_timedwait(&renderer->d.upCond, &renderer->d.mutex, &ts); - if (err == ETIMEDOUT) { - break; - } - } - pthread_mutex_unlock(&renderer->d.mutex); + pthread_cond_broadcast(&renderer->d.downCond); + pthread_cond_wait(&renderer->d.upCond, &renderer->d.mutex); } + pthread_mutex_unlock(&renderer->d.mutex); } }