From 7b1548af3cdda7f0023510a9ec12813a137a1668 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 30 Nov 2018 21:39:59 -0800 Subject: Handle source state changed events uniquely in the event loop To avoid the need of constructing the string in the mixer thread, which is commonly formatted anyway. --- Alc/alu.cpp | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) (limited to 'Alc') diff --git a/Alc/alu.cpp b/Alc/alu.cpp index b9fe95f0..197d554d 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -287,31 +287,12 @@ aluVector aluMatrixfVector(const aluMatrixf *mtx, const aluVector *vec) void SendSourceStoppedEvent(ALCcontext *context, ALuint id) { - AsyncEvent evt = ASYNC_EVENT(EventType_SourceStateChange); - ALbitfieldSOFT enabledevt; - size_t strpos; - ALuint scale; - - enabledevt = context->EnabledEvts.load(std::memory_order_acquire); + ALbitfieldSOFT enabledevt{context->EnabledEvts.load(std::memory_order_acquire)}; if(!(enabledevt&EventType_SourceStateChange)) return; - evt.u.user.type = AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT; - evt.u.user.id = id; - evt.u.user.param = AL_STOPPED; - - /* Normally snprintf would be used, but this is called from the mixer and - * that function's not real-time safe, so we have to construct it manually. - */ - strcpy(evt.u.user.msg, "Source ID "); strpos = 10; - scale = 1000000000; - while(scale > 0 && scale > id) - scale /= 10; - while(scale > 0) - { - evt.u.user.msg[strpos++] = '0' + ((id/scale)%10); - scale /= 10; - } - strcpy(evt.u.user.msg+strpos, " state changed to AL_STOPPED"); + AsyncEvent evt{ASYNC_EVENT(EventType_SourceStateChange)}; + evt.u.srcstate.id = id; + evt.u.srcstate.state = AL_STOPPED; if(ll_ringbuffer_write(context->AsyncEvents, &evt, 1) == 1) context->EventSem.post(); -- cgit v1.2.3