Rename EventLock to make it more clear it's protecting the callback
[openal-soft.git] / OpenAL32 / event.c
blob9a3a92b4b8dc6a397901e7d9b791f99045e8cf7b
2 #include "config.h"
4 #include "AL/alc.h"
5 #include "AL/al.h"
6 #include "AL/alext.h"
7 #include "alMain.h"
8 #include "alError.h"
11 AL_API void AL_APIENTRY alEventControlSOFT(ALsizei count, const ALenum *types, ALboolean enable)
13 ALCcontext *context;
14 ALbitfieldSOFT flags = 0;
15 ALsizei i;
17 context = GetContextRef();
18 if(!context) return;
20 if(count < 0) SETERR_GOTO(context, AL_INVALID_VALUE, done, "Controlling %d events", count);
21 if(count == 0) goto done;
22 if(!types) SETERR_GOTO(context, AL_INVALID_VALUE, done, "NULL pointer");
24 for(i = 0;i < count;i++)
26 if(types[i] == AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT)
27 flags |= EventType_BufferCompleted;
28 else if(types[i] == AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT)
29 flags |= EventType_SourceStateChange;
30 else if(types[i] == AL_EVENT_TYPE_ERROR_SOFT)
31 flags |= EventType_Error;
32 else if(types[i] == AL_EVENT_TYPE_PERFORMANCE_SOFT)
33 flags |= EventType_Performance;
34 else if(types[i] == AL_EVENT_TYPE_DEPRECATED_SOFT)
35 flags |= EventType_Deprecated;
36 else
37 SETERR_GOTO(context, AL_INVALID_ENUM, done, "Invalid event type 0x%04x", types[i]);
40 if(enable)
42 ALbitfieldSOFT enabledevts = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_relaxed);
43 while(ATOMIC_COMPARE_EXCHANGE_WEAK(&context->EnabledEvts, &enabledevts, enabledevts|flags,
44 almemory_order_acq_rel, almemory_order_acquire) == 0)
46 /* enabledevts is (re-)filled with the current value on failure, so
47 * just try again.
51 else
53 ALbitfieldSOFT enabledevts = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_relaxed);
54 while(ATOMIC_COMPARE_EXCHANGE_WEAK(&context->EnabledEvts, &enabledevts, enabledevts&~flags,
55 almemory_order_acq_rel, almemory_order_acquire) == 0)
60 done:
61 ALCcontext_DecRef(context);
64 AL_API void AL_APIENTRY alEventCallbackSOFT(ALEVENTPROCSOFT callback, void *userParam)
66 ALCcontext *context;
68 context = GetContextRef();
69 if(!context) return;
71 almtx_lock(&context->EventCbLock);
72 context->EventCb = callback;
73 context->EventParam = userParam;
74 almtx_unlock(&context->EventCbLock);
76 ALCcontext_DecRef(context);