From cb8545346d227ba85a4a98c3897b5cdb1ea86d26 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 20 Sep 2018 19:58:01 -0700 Subject: Always start the event thread with the context --- Alc/ALc.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'Alc/ALc.c') diff --git a/Alc/ALc.c b/Alc/ALc.c index 27c36477..89c0fc63 100644 --- a/Alc/ALc.c +++ b/Alc/ALc.c @@ -2665,6 +2665,11 @@ static ALvoid InitContext(ALCcontext *Context) listener->Params.MetersPerUnit; listener->Params.SourceDistanceModel = Context->SourceDistanceModel; listener->Params.DistanceModel = Context->DistanceModel; + + + Context->AsyncEvents = ll_ringbuffer_create(63, sizeof(AsyncEvent), false); + if(althrd_create(&Context->EventThread, EventThread, Context) != althrd_success) + ERR("Failed to start event thread! Expect problems.\n"); } @@ -2675,6 +2680,7 @@ static ALvoid InitContext(ALCcontext *Context) */ static void FreeContext(ALCcontext *context) { + static const AsyncEvent kill_evt = { 0 }; ALlistener *listener = context->Listener; struct ALeffectslotArray *auxslots; struct ALeffectslotProps *eprops; @@ -2686,6 +2692,11 @@ static void FreeContext(ALCcontext *context) TRACE("%p\n", context); + while(ll_ringbuffer_write(context->AsyncEvents, (const char*)&kill_evt, 1) == 0) + althrd_yield(); + alsem_post(&context->EventSem); + althrd_join(context->EventThread, NULL); + if((cprops=ATOMIC_LOAD(&context->Update, almemory_order_acquire)) != NULL) { TRACE("Freed unapplied context update %p\n", cprops); @@ -2773,15 +2784,6 @@ static void FreeContext(ALCcontext *context) } TRACE("Freed "SZFMT" listener property object%s\n", count, (count==1)?"":"s"); - if(ATOMIC_EXCHANGE(&context->EnabledEvts, 0, almemory_order_acq_rel)) - { - static const AsyncEvent kill_evt = { 0 }; - while(ll_ringbuffer_write(context->AsyncEvents, (const char*)&kill_evt, 1) == 0) - althrd_yield(); - alsem_post(&context->EventSem); - althrd_join(context->EventThread, NULL); - } - almtx_destroy(&context->EventCbLock); almtx_destroy(&context->EventThrdLock); alsem_destroy(&context->EventSem); -- cgit v1.2.3