Use a unique_ptr for the AsyncEvents ringbuffer
This commit is contained in:
+1
-4
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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{};
|
||||
|
||||
+6
-6
@@ -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)
|
||||
{
|
||||
|
||||
+4
-4
@@ -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);
|
||||
|
||||
@@ -697,7 +697,7 @@ void SendStateChangeEvent(ALCcontext *context, ALuint id, ALenum state)
|
||||
* and we don't want state change messages to occur out of order, so send
|
||||
* it through the async queue to ensure proper ordering.
|
||||
*/
|
||||
RingBuffer *ring{context->AsyncEvents};
|
||||
RingBuffer *ring{context->AsyncEvents.get()};
|
||||
auto evt_vec = ring->getWriteVector();
|
||||
if(evt_vec.first.len < 1) return;
|
||||
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@
|
||||
|
||||
static int EventThread(ALCcontext *context)
|
||||
{
|
||||
RingBuffer *ring{context->AsyncEvents};
|
||||
RingBuffer *ring{context->AsyncEvents.get()};
|
||||
bool quitnow{false};
|
||||
while(LIKELY(!quitnow))
|
||||
{
|
||||
@@ -44,7 +44,7 @@ static int EventThread(ALCcontext *context)
|
||||
evt.~AsyncEvent();
|
||||
ring->readAdvance(1);
|
||||
}
|
||||
} _{evt, context->AsyncEvents};
|
||||
} _{evt, context->AsyncEvents.get()};
|
||||
|
||||
quitnow = evt.EnumType == EventType_KillThread;
|
||||
if(UNLIKELY(quitnow)) break;
|
||||
@@ -111,7 +111,7 @@ void StartEventThrd(ALCcontext *ctx)
|
||||
void StopEventThrd(ALCcontext *ctx)
|
||||
{
|
||||
static constexpr AsyncEvent kill_evt{EventType_KillThread};
|
||||
RingBuffer *ring{ctx->AsyncEvents};
|
||||
RingBuffer *ring{ctx->AsyncEvents.get()};
|
||||
auto evt_data = ring->getWriteVector().first;
|
||||
if(evt_data.len == 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user