all repos — mgba @ c20efb42ffdda29e8ba1540b493805cee5158ef4

mGBA Game Boy Advance Emulator

Clean up thread locking in the software renderer
Jeffrey Pfau jeffrey@endrift.com
Sat, 11 May 2013 21:07:10 -0700
commit

c20efb42ffdda29e8ba1540b493805cee5158ef4

parent

63b72657c138142a76e482db09ddf0c8cc35facb

2 files changed, 8 insertions(+), 15 deletions(-)

jump to
M src/gba/renderers/video-software.csrc/gba/renderers/video-software.c

@@ -108,6 +108,10 @@

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);
M src/sdl/main.csrc/sdl/main.c

@@ -110,7 +110,6 @@

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 @@ glTexCoordPointer(2, GL_INT, 0, _glTexCoords);

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 @@ GBASDLHandleEvent(context, &event);

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