From 4dca2f2ee5ef488fbe05397de1ab3029e559cf61 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Thu, 27 Dec 2018 10:44:02 -0800 Subject: Use a unique_ptr for the AsyncEvents ringbuffer --- Alc/alc.cpp | 5 +---- Alc/alcontext.h | 2 +- Alc/alu.cpp | 12 ++++++------ Alc/mixvoice.cpp | 8 ++++---- 4 files changed, 12 insertions(+), 15 deletions(-) (limited to 'Alc') diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 27475652..9a93fbdc 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -2369,7 +2369,7 @@ static ALvoid InitContext(ALCcontext *Context) listener.Params.mDistanceModel = Context->mDistanceModel; - Context->AsyncEvents = ll_ringbuffer_create(511, sizeof(AsyncEvent), false); + Context->AsyncEvents.reset(ll_ringbuffer_create(511, sizeof(AsyncEvent), false)); StartEventThrd(Context); } @@ -2484,9 +2484,6 @@ ALCcontext_struct::~ALCcontext_struct() if(count > 0) TRACE("Destructed " SZFMT " orphaned event%s\n", count, (count==1)?"":"s"); - delete AsyncEvents; - AsyncEvents = nullptr; - ALCdevice_DecRef(Device); } diff --git a/Alc/alcontext.h b/Alc/alcontext.h index dadb4f8f..f843809b 100644 --- a/Alc/alcontext.h +++ b/Alc/alcontext.h @@ -112,7 +112,7 @@ struct ALCcontext_struct { std::thread EventThread; al::semaphore EventSem; - RingBuffer *AsyncEvents{nullptr}; + std::unique_ptr AsyncEvents; std::atomic EnabledEvts{0u}; std::mutex EventCbLock; ALEVENTPROCSOFT EventCb{}; diff --git a/Alc/alu.cpp b/Alc/alu.cpp index dfbd15a9..672b571b 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -292,11 +292,11 @@ void SendSourceStoppedEvent(ALCcontext *context, ALuint id) ALbitfieldSOFT enabledevt{context->EnabledEvts.load(std::memory_order_acquire)}; if(!(enabledevt&EventType_SourceStateChange)) return; - RingBuffer *ring{context->AsyncEvents}; - auto evt_data = ring->getWriteVector().first; - if(evt_data.len < 1) return; + RingBuffer *ring{context->AsyncEvents.get()}; + auto evt_vec = ring->getWriteVector(); + if(evt_vec.first.len < 1) return; - AsyncEvent *evt{new (evt_data.buf) AsyncEvent{EventType_SourceStateChange}}; + AsyncEvent *evt{new (evt_vec.first.buf) AsyncEvent{EventType_SourceStateChange}}; evt->u.srcstate.id = id; evt->u.srcstate.state = AL_STOPPED; @@ -419,7 +419,7 @@ bool CalcEffectSlotParams(ALeffectslot *slot, ALCcontext *context, bool force) /* Otherwise, if it would be deleted, send it off with a release * event. */ - RingBuffer *ring{context->AsyncEvents}; + RingBuffer *ring{context->AsyncEvents.get()}; auto evt_vec = ring->getWriteVector(); if(LIKELY(evt_vec.first.len > 0)) { @@ -1839,7 +1839,7 @@ void aluHandleDisconnect(ALCdevice *device, const char *msg, ...) const ALbitfieldSOFT enabledevt{ctx->EnabledEvts.load(std::memory_order_acquire)}; if((enabledevt&EventType_Disconnected)) { - RingBuffer *ring{ctx->AsyncEvents}; + RingBuffer *ring{ctx->AsyncEvents.get()}; auto evt_data = ring->getWriteVector().first; if(evt_data.len > 0) { diff --git a/Alc/mixvoice.cpp b/Alc/mixvoice.cpp index 48844219..53721201 100644 --- a/Alc/mixvoice.cpp +++ b/Alc/mixvoice.cpp @@ -736,11 +736,11 @@ ALboolean MixSource(ALvoice *voice, const ALuint SourceID, ALCcontext *Context, ALbitfieldSOFT enabledevt{Context->EnabledEvts.load(std::memory_order_acquire)}; if(buffers_done > 0 && (enabledevt&EventType_BufferCompleted)) { - RingBuffer *ring{Context->AsyncEvents}; - auto evt_data = ring->getWriteVector().first; - if(evt_data.len > 0) + RingBuffer *ring{Context->AsyncEvents.get()}; + auto evt_vec = ring->getWriteVector(); + if(evt_vec.first.len > 0) { - AsyncEvent *evt{new (evt_data.buf) AsyncEvent{EventType_BufferCompleted}}; + AsyncEvent *evt{new (evt_vec.first.buf) AsyncEvent{EventType_BufferCompleted}}; evt->u.bufcomp.id = SourceID; evt->u.bufcomp.count = buffers_done; ring->writeAdvance(1); -- cgit v1.2.3