diff options
author | Chris Robinson <[email protected]> | 2018-12-27 10:44:02 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-12-27 10:44:02 -0800 |
commit | 4dca2f2ee5ef488fbe05397de1ab3029e559cf61 (patch) | |
tree | 930224ac816f69b0ca0a7cd0c97e647d6e04da57 /Alc | |
parent | be85ab6f826a724105cef05e740b5013a1e6149e (diff) |
Use a unique_ptr for the AsyncEvents ringbuffer
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/alc.cpp | 5 | ||||
-rw-r--r-- | Alc/alcontext.h | 2 | ||||
-rw-r--r-- | Alc/alu.cpp | 12 | ||||
-rw-r--r-- | Alc/mixvoice.cpp | 8 |
4 files changed, 12 insertions, 15 deletions
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<RingBuffer> AsyncEvents; std::atomic<ALbitfieldSOFT> 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); |