2018-01-23 18:25:59 -08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "AL/alc.h"
|
|
|
|
#include "AL/al.h"
|
|
|
|
#include "AL/alext.h"
|
|
|
|
#include "alMain.h"
|
|
|
|
#include "alError.h"
|
2018-09-21 02:37:37 -07:00
|
|
|
#include "alAuxEffectSlot.h"
|
2018-01-31 20:21:54 -08:00
|
|
|
#include "ringbuffer.h"
|
2018-01-23 18:25:59 -08:00
|
|
|
|
|
|
|
|
2018-09-20 19:58:01 -07:00
|
|
|
int EventThread(void *arg)
|
2018-01-31 20:21:54 -08:00
|
|
|
{
|
|
|
|
ALCcontext *context = arg;
|
2018-09-20 19:58:01 -07:00
|
|
|
bool quitnow = false;
|
2018-01-31 20:21:54 -08:00
|
|
|
|
2018-09-20 19:58:01 -07:00
|
|
|
while(!quitnow)
|
2018-01-31 20:21:54 -08:00
|
|
|
{
|
|
|
|
ALbitfieldSOFT enabledevts;
|
2018-03-03 14:04:10 -08:00
|
|
|
AsyncEvent evt;
|
2018-01-31 20:21:54 -08:00
|
|
|
|
2018-03-03 14:04:10 -08:00
|
|
|
if(ll_ringbuffer_read(context->AsyncEvents, (char*)&evt, 1) == 0)
|
2018-01-31 20:21:54 -08:00
|
|
|
{
|
2018-02-01 18:09:16 -08:00
|
|
|
alsem_wait(&context->EventSem);
|
2018-01-31 20:21:54 -08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-02-01 18:09:16 -08:00
|
|
|
almtx_lock(&context->EventCbLock);
|
2018-09-20 19:58:01 -07:00
|
|
|
do {
|
2018-09-20 21:59:38 -07:00
|
|
|
quitnow = evt.EnumType == EventType_KillThread;
|
2018-09-20 19:58:01 -07:00
|
|
|
if(quitnow) break;
|
|
|
|
|
2018-09-21 02:37:37 -07:00
|
|
|
if(evt.EnumType == EventType_ReleaseEffectState)
|
|
|
|
{
|
|
|
|
ALeffectState_DecRef(evt.u.EffectState);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-09-20 19:58:01 -07:00
|
|
|
enabledevts = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_acquire);
|
|
|
|
if(context->EventCb && (enabledevts&evt.EnumType) == evt.EnumType)
|
2018-09-20 21:59:38 -07:00
|
|
|
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
|
|
|
|
);
|
2018-09-20 19:58:01 -07:00
|
|
|
} while(ll_ringbuffer_read(context->AsyncEvents, (char*)&evt, 1) != 0);
|
2018-02-01 18:09:16 -08:00
|
|
|
almtx_unlock(&context->EventCbLock);
|
2018-01-31 20:21:54 -08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-23 18:25:59 -08:00
|
|
|
AL_API void AL_APIENTRY alEventControlSOFT(ALsizei count, const ALenum *types, ALboolean enable)
|
|
|
|
{
|
|
|
|
ALCcontext *context;
|
2018-03-03 14:04:10 -08:00
|
|
|
ALbitfieldSOFT enabledevts;
|
2018-01-23 18:25:59 -08:00
|
|
|
ALbitfieldSOFT flags = 0;
|
|
|
|
ALsizei i;
|
|
|
|
|
|
|
|
context = GetContextRef();
|
|
|
|
if(!context) return;
|
|
|
|
|
2018-01-25 15:59:59 -08:00
|
|
|
if(count < 0) SETERR_GOTO(context, AL_INVALID_VALUE, done, "Controlling %d events", count);
|
2018-01-23 18:25:59 -08:00
|
|
|
if(count == 0) goto done;
|
2018-01-25 15:59:59 -08:00
|
|
|
if(!types) SETERR_GOTO(context, AL_INVALID_VALUE, done, "NULL pointer");
|
2018-01-23 18:25:59 -08:00
|
|
|
|
|
|
|
for(i = 0;i < count;i++)
|
|
|
|
{
|
|
|
|
if(types[i] == AL_EVENT_TYPE_BUFFER_COMPLETED_SOFT)
|
|
|
|
flags |= EventType_BufferCompleted;
|
|
|
|
else if(types[i] == AL_EVENT_TYPE_SOURCE_STATE_CHANGED_SOFT)
|
|
|
|
flags |= EventType_SourceStateChange;
|
|
|
|
else if(types[i] == AL_EVENT_TYPE_ERROR_SOFT)
|
|
|
|
flags |= EventType_Error;
|
|
|
|
else if(types[i] == AL_EVENT_TYPE_PERFORMANCE_SOFT)
|
|
|
|
flags |= EventType_Performance;
|
2018-01-24 18:42:00 -08:00
|
|
|
else if(types[i] == AL_EVENT_TYPE_DEPRECATED_SOFT)
|
|
|
|
flags |= EventType_Deprecated;
|
2018-02-03 01:07:06 -08:00
|
|
|
else if(types[i] == AL_EVENT_TYPE_DISCONNECTED_SOFT)
|
|
|
|
flags |= EventType_Disconnected;
|
2018-01-23 18:25:59 -08:00
|
|
|
else
|
2018-01-25 15:59:59 -08:00
|
|
|
SETERR_GOTO(context, AL_INVALID_ENUM, done, "Invalid event type 0x%04x", types[i]);
|
2018-01-23 18:25:59 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if(enable)
|
2018-01-28 16:58:41 -08:00
|
|
|
{
|
2018-01-31 20:21:54 -08:00
|
|
|
enabledevts = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_relaxed);
|
2018-01-28 16:58:41 -08:00
|
|
|
while(ATOMIC_COMPARE_EXCHANGE_WEAK(&context->EnabledEvts, &enabledevts, enabledevts|flags,
|
|
|
|
almemory_order_acq_rel, almemory_order_acquire) == 0)
|
|
|
|
{
|
|
|
|
/* enabledevts is (re-)filled with the current value on failure, so
|
|
|
|
* just try again.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
2018-01-23 18:25:59 -08:00
|
|
|
else
|
2018-01-28 16:58:41 -08:00
|
|
|
{
|
2018-01-31 20:21:54 -08:00
|
|
|
enabledevts = ATOMIC_LOAD(&context->EnabledEvts, almemory_order_relaxed);
|
2018-01-28 16:58:41 -08:00
|
|
|
while(ATOMIC_COMPARE_EXCHANGE_WEAK(&context->EnabledEvts, &enabledevts, enabledevts&~flags,
|
|
|
|
almemory_order_acq_rel, almemory_order_acquire) == 0)
|
|
|
|
{
|
|
|
|
}
|
2018-09-20 19:58:01 -07:00
|
|
|
/* Wait to ensure the event handler sees the changed flags before
|
|
|
|
* returning.
|
|
|
|
*/
|
|
|
|
almtx_lock(&context->EventCbLock);
|
|
|
|
almtx_unlock(&context->EventCbLock);
|
2018-01-28 16:58:41 -08:00
|
|
|
}
|
2018-01-24 17:07:01 -08:00
|
|
|
|
2018-01-23 18:25:59 -08:00
|
|
|
done:
|
|
|
|
ALCcontext_DecRef(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
AL_API void AL_APIENTRY alEventCallbackSOFT(ALEVENTPROCSOFT callback, void *userParam)
|
|
|
|
{
|
|
|
|
ALCcontext *context;
|
|
|
|
|
|
|
|
context = GetContextRef();
|
|
|
|
if(!context) return;
|
|
|
|
|
2018-03-03 13:53:41 -08:00
|
|
|
almtx_lock(&context->PropLock);
|
2018-01-30 12:34:25 -08:00
|
|
|
almtx_lock(&context->EventCbLock);
|
2018-01-23 18:25:59 -08:00
|
|
|
context->EventCb = callback;
|
|
|
|
context->EventParam = userParam;
|
2018-01-30 12:34:25 -08:00
|
|
|
almtx_unlock(&context->EventCbLock);
|
2018-03-03 13:53:41 -08:00
|
|
|
almtx_unlock(&context->PropLock);
|
2018-01-23 18:25:59 -08:00
|
|
|
|
|
|
|
ALCcontext_DecRef(context);
|
|
|
|
}
|