diff options
author | Chris Robinson <[email protected]> | 2018-09-20 21:59:38 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-09-20 21:59:38 -0700 |
commit | ebbbeb0d660e442324c2b563c7b59e9f74ad15e9 (patch) | |
tree | fcddcd84260e58b2ba6c79762d92e286978b8dfc | |
parent | cb8545346d227ba85a4a98c3897b5cdb1ea86d26 (diff) |
Put user events in a union structure
-rw-r--r-- | Alc/ALc.c | 2 | ||||
-rw-r--r-- | Alc/ALu.c | 30 | ||||
-rw-r--r-- | Alc/mixvoice.c | 11 | ||||
-rw-r--r-- | OpenAL32/Include/alMain.h | 18 | ||||
-rw-r--r-- | OpenAL32/alSource.c | 11 | ||||
-rw-r--r-- | OpenAL32/event.c | 7 |
6 files changed, 43 insertions, 36 deletions
@@ -2680,7 +2680,7 @@ static ALvoid InitContext(ALCcontext *Context) */ static void FreeContext(ALCcontext *context) { - static const AsyncEvent kill_evt = { 0 }; + static const AsyncEvent kill_evt = ASYNC_EVENT(EventType_KillThread); ALlistener *listener = context->Listener; struct ALeffectslotArray *auxslots; struct ALeffectslotProps *eprops; @@ -211,32 +211,31 @@ void aluInit(void) static void SendSourceStoppedEvent(ALCcontext *context, ALuint id) { + AsyncEvent evt = ASYNC_EVENT(EventType_SourceStateChange); ALbitfieldSOFT enabledevt; - AsyncEvent evt; size_t strpos; ALuint scale; enabledevt = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_acquire); if(!(enabledevt&EventType_SourceStateChange)) return; - evt.EnumType = EventType_SourceStateChange; - evt.Type = AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT; - evt.ObjectId = id; - evt.Param = AL_STOPPED; + 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.Message, "Source ID "); strpos = 10; + strcpy(evt.u.user.msg, "Source ID "); strpos = 10; scale = 1000000000; while(scale > 0 && scale > id) scale /= 10; while(scale > 0) { - evt.Message[strpos++] = '0' + ((id/scale)%10); + evt.u.user.msg[strpos++] = '0' + ((id/scale)%10); scale /= 10; } - strcpy(evt.Message+strpos, " state changed to AL_STOPPED"); + strcpy(evt.u.user.msg+strpos, " state changed to AL_STOPPED"); if(ll_ringbuffer_write(context->AsyncEvents, (const char*)&evt, 1) == 1) alsem_post(&context->EventSem); @@ -1846,25 +1845,24 @@ void aluMixData(ALCdevice *device, ALvoid *OutBuffer, ALsizei NumSamples) void aluHandleDisconnect(ALCdevice *device, const char *msg, ...) { + AsyncEvent evt = ASYNC_EVENT(EventType_Disconnected); ALCcontext *ctx; - AsyncEvent evt; va_list args; int msglen; if(!ATOMIC_EXCHANGE(&device->Connected, AL_FALSE, almemory_order_acq_rel)) return; - evt.EnumType = EventType_Disconnected; - evt.Type = AL_EVENT_TYPE_DISCONNECTED_SOFT; - evt.ObjectId = 0; - evt.Param = 0; + evt.u.user.type = AL_EVENT_TYPE_DISCONNECTED_SOFT; + evt.u.user.id = 0; + evt.u.user.param = 0; va_start(args, msg); - msglen = vsnprintf(evt.Message, sizeof(evt.Message), msg, args); + msglen = vsnprintf(evt.u.user.msg, sizeof(evt.u.user.msg), msg, args); va_end(args); - if(msglen < 0 || (size_t)msglen >= sizeof(evt.Message)) - evt.Message[sizeof(evt.Message)-1] = 0; + if(msglen < 0 || (size_t)msglen >= sizeof(evt.u.user.msg)) + evt.u.user.msg[sizeof(evt.u.user.msg)-1] = 0; ctx = ATOMIC_LOAD_SEQ(&device->ContextList); while(ctx) diff --git a/Alc/mixvoice.c b/Alc/mixvoice.c index a2365886..d019b898 100644 --- a/Alc/mixvoice.c +++ b/Alc/mixvoice.c @@ -197,12 +197,11 @@ void aluInitMixer(void) static void SendAsyncEvent(ALCcontext *context, ALuint enumtype, ALenum type, ALuint objid, ALuint param, const char *msg) { - AsyncEvent evt; - evt.EnumType = enumtype; - evt.Type = type; - evt.ObjectId = objid; - evt.Param = param; - strcpy(evt.Message, msg); + AsyncEvent evt = ASYNC_EVENT(enumtype); + evt.u.user.type = type; + evt.u.user.id = objid; + evt.u.user.param = param; + strcpy(evt.u.user.msg, msg); if(ll_ringbuffer_write(context->AsyncEvents, (const char*)&evt, 1) == 1) alsem_post(&context->EventSem); } diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h index f1bc4469..86ac49dc 100644 --- a/OpenAL32/Include/alMain.h +++ b/OpenAL32/Include/alMain.h @@ -750,6 +750,10 @@ struct ALCdevice_struct { enum { + /* End event thread processing. */ + EventType_KillThread = 0, + + /* User event types. */ EventType_SourceStateChange = 1<<0, EventType_BufferCompleted = 1<<1, EventType_Error = 1<<2, @@ -760,11 +764,17 @@ enum { typedef struct AsyncEvent { unsigned int EnumType; - ALenum Type; - ALuint ObjectId; - ALuint Param; - ALchar Message[1008]; + union { + char dummy; + struct { + ALenum type; + ALuint id; + ALuint param; + ALchar msg[1008]; + } user; + } u; } AsyncEvent; +#define ASYNC_EVENT(t) { t, { 0 } } struct ALCcontext_struct { RefCount ref; diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c index 5ce439c7..81d8c262 100644 --- a/OpenAL32/alSource.c +++ b/OpenAL32/alSource.c @@ -229,17 +229,16 @@ static inline bool SourceShouldUpdate(ALsource *source, ALCcontext *context) /** Can only be called while the mixer is locked! */ static void SendStateChangeEvent(ALCcontext *context, ALuint id, ALenum state) { + AsyncEvent evt = ASYNC_EVENT(EventType_SourceStateChange); ALbitfieldSOFT enabledevt; - AsyncEvent evt; enabledevt = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_acquire); if(!(enabledevt&EventType_SourceStateChange)) return; - evt.EnumType = EventType_SourceStateChange; - evt.Type = AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT; - evt.ObjectId = id; - evt.Param = state; - snprintf(evt.Message, sizeof(evt.Message), "Source ID %u state changed to %s", id, + evt.u.user.type = AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT; + evt.u.user.id = id; + evt.u.user.param = state; + snprintf(evt.u.user.msg, sizeof(evt.u.user.msg), "Source ID %u state changed to %s", id, (state==AL_INITIAL) ? "AL_INITIAL" : (state==AL_PLAYING) ? "AL_PLAYING" : (state==AL_PAUSED) ? "AL_PAUSED" : diff --git a/OpenAL32/event.c b/OpenAL32/event.c index b719c371..a76746bd 100644 --- a/OpenAL32/event.c +++ b/OpenAL32/event.c @@ -27,13 +27,14 @@ int EventThread(void *arg) almtx_lock(&context->EventCbLock); do { - quitnow = !evt.EnumType; + quitnow = evt.EnumType == EventType_KillThread; if(quitnow) break; enabledevts = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_acquire); if(context->EventCb && (enabledevts&evt.EnumType) == evt.EnumType) - context->EventCb(evt.Type, evt.ObjectId, evt.Param, (ALsizei)strlen(evt.Message), - evt.Message, context->EventParam); + context->EventCb(evt.u.user.type, evt.u.user.id, evt.u.user.param, + (ALsizei)strlen(evt.u.user.msg), evt.u.user.msg, context->EventParam + ); } while(ll_ringbuffer_read(context->AsyncEvents, (char*)&evt, 1) != 0); almtx_unlock(&context->EventCbLock); } |