Properly isolate threading
Jeffrey Pfau jeffrey@endrift.com
Sat, 20 Apr 2013 16:44:03 -0700
3 files changed,
11 insertions(+),
8 deletions(-)
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -38,7 +38,7 @@
return 0; } -int GBAThreadStart(struct GBAThread* threadContext, pthread_t* thread) { +int GBAThreadStart(struct GBAThread* threadContext) { // TODO: error check { pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;@@ -51,9 +51,13 @@ pthread_cond_init(&threadContext->cond, 0);
pthread_mutex_lock(&threadContext->mutex); threadContext->started = 0; - pthread_create(thread, 0, _GBAThreadRun, threadContext); + pthread_create(&threadContext->thread, 0, _GBAThreadRun, threadContext); pthread_cond_wait(&threadContext->cond, &threadContext->mutex); pthread_mutex_unlock(&threadContext->mutex); return 0; } + +void GBAThreadJoin(struct GBAThread* threadContext) { + pthread_join(threadContext->thread, 0); +}
M
src/gba/gba-thread.h
→
src/gba/gba-thread.h
@@ -16,8 +16,10 @@
// Threading state pthread_mutex_t mutex; pthread_cond_t cond; + pthread_t thread; }; -int GBAThreadStart(struct GBAThread* threadContext, pthread_t* thread); +int GBAThreadStart(struct GBAThread* threadContext); +void GBAThreadJoin(struct GBAThread* threadContext); #endif
M
src/main.c
→
src/main.c
@@ -18,11 +18,8 @@ struct GBAThread context;
struct GBAVideoSoftwareRenderer renderer; context.fd = fd; context.renderer = 0; - pthread_t thread; - - GBAThreadStart(&context, &thread); - - pthread_join(thread, 0); + GBAThreadStart(&context); + GBAThreadJoin(&context); close(fd); return 0;