aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-01-27 17:24:18 -0800
committerChris Robinson <[email protected]>2018-01-27 19:04:32 -0800
commit6a839600b96b73104f8b93a4fa4a1a8da67cae5c (patch)
tree5b5203ce907411f32999e2e3ee3e3cd2a39dda25
parent4d1795e90b83f040aa59cf69616a4ff2b32bf71a (diff)
Use a vector to store the effect slot pointers
And make the ID a simple index into it (1-base, to avoid ID 0).
-rw-r--r--Alc/ALc.c25
-rw-r--r--OpenAL32/Include/alAuxEffectSlot.h14
-rw-r--r--OpenAL32/Include/alMain.h9
-rw-r--r--OpenAL32/alAuxEffectSlot.c143
-rw-r--r--OpenAL32/alSource.c18
5 files changed, 116 insertions, 93 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index f59c6e90..0dc93b56 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -2249,10 +2249,10 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
}
WriteLock(&context->PropLock);
- LockUIntMapRead(&context->EffectSlotMap);
- for(pos = 0;pos < context->EffectSlotMap.size;pos++)
+ almtx_lock(&context->EffectSlotLock);
+ for(pos = 0;pos < (ALsizei)VECTOR_SIZE(context->EffectSlotList);pos++)
{
- ALeffectslot *slot = context->EffectSlotMap.values[pos];
+ ALeffectslot *slot = VECTOR_ELEM(context->EffectSlotList, pos);
ALeffectState *state = slot->Effect.State;
state->OutBuffer = device->Dry.Buffer;
@@ -2262,7 +2262,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
else
UpdateEffectSlotProps(slot, context);
}
- UnlockUIntMapRead(&context->EffectSlotMap);
+ almtx_unlock(&context->EffectSlotLock);
almtx_lock(&context->SourceLock);
sublist = VECTOR_BEGIN(context->SourceList);
@@ -2534,7 +2534,8 @@ static ALvoid InitContext(ALCcontext *Context)
VECTOR_INIT(Context->SourceList);
Context->NumSources = 0;
almtx_init(&Context->SourceLock, almtx_plain);
- InitUIntMap(&Context->EffectSlotMap, Context->Device->AuxiliaryEffectSlotMax);
+ VECTOR_INIT(Context->EffectSlotList);
+ almtx_init(&Context->EffectSlotLock, almtx_plain);
if(Context->DefaultSlot)
{
@@ -2648,13 +2649,13 @@ static void FreeContext(ALCcontext *context)
++count;
}
TRACE("Freed "SZFMT" AuxiliaryEffectSlot property object%s\n", count, (count==1)?"":"s");
- if(context->EffectSlotMap.size > 0)
- {
- WARN("(%p) Deleting %d AuxiliaryEffectSlot%s\n", context, context->EffectSlotMap.size,
- (context->EffectSlotMap.size==1)?"":"s");
- ReleaseALAuxiliaryEffectSlots(context);
- }
- ResetUIntMap(&context->EffectSlotMap);
+
+ ReleaseALAuxiliaryEffectSlots(context);
+#define FREE_EFFECTSLOTPTR(x) al_free(*(x))
+ VECTOR_FOR_EACH(ALeffectslotPtr, context->EffectSlotList, FREE_EFFECTSLOTPTR);
+#undef FREE_EFFECTSLOTPTR
+ VECTOR_DEINIT(context->EffectSlotList);
+ almtx_destroy(&context->EffectSlotLock);
count = 0;
vprops = ATOMIC_LOAD(&context->FreeVoiceProps, almemory_order_relaxed);
diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h
index 74bb841c..e4e954a0 100644
--- a/OpenAL32/Include/alAuxEffectSlot.h
+++ b/OpenAL32/Include/alAuxEffectSlot.h
@@ -149,20 +149,6 @@ typedef struct ALeffectslot {
alignas(16) ALfloat WetBuffer[MAX_EFFECT_CHANNELS][BUFFERSIZE];
} ALeffectslot;
-inline void LockEffectSlotsRead(ALCcontext *context)
-{ LockUIntMapRead(&context->EffectSlotMap); }
-inline void UnlockEffectSlotsRead(ALCcontext *context)
-{ UnlockUIntMapRead(&context->EffectSlotMap); }
-inline void LockEffectSlotsWrite(ALCcontext *context)
-{ LockUIntMapWrite(&context->EffectSlotMap); }
-inline void UnlockEffectSlotsWrite(ALCcontext *context)
-{ UnlockUIntMapWrite(&context->EffectSlotMap); }
-
-inline struct ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id)
-{ return (struct ALeffectslot*)LookupUIntMapKeyNoLock(&context->EffectSlotMap, id); }
-inline struct ALeffectslot *RemoveEffectSlot(ALCcontext *context, ALuint id)
-{ return (struct ALeffectslot*)RemoveUIntMapKeyNoLock(&context->EffectSlotMap, id); }
-
ALenum InitEffectSlot(ALeffectslot *slot);
void DeinitEffectSlot(ALeffectslot *slot);
void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context);
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index f7ae2ecd..d1ae0a94 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -387,6 +387,12 @@ typedef struct SourceSubList {
} SourceSubList;
TYPEDEF_VECTOR(SourceSubList, vector_SourceSubList)
+/* Effect slots are rather large, and apps aren't likely to have more than one
+ * or two (let alone 64), so hold them individually.
+ */
+typedef struct ALeffectslot *ALeffectslotPtr;
+TYPEDEF_VECTOR(ALeffectslotPtr, vector_ALeffectslotPtr)
+
typedef struct EnumeratedHrtf {
al_string name;
@@ -600,7 +606,8 @@ struct ALCcontext_struct {
ALuint NumSources;
almtx_t SourceLock;
- UIntMap EffectSlotMap;
+ vector_ALeffectslotPtr EffectSlotList;
+ almtx_t EffectSlotLock;
ATOMIC(ALenum) LastError;
diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c
index d2039097..3fbf4b6e 100644
--- a/OpenAL32/alAuxEffectSlot.c
+++ b/OpenAL32/alAuxEffectSlot.c
@@ -36,13 +36,6 @@
#include "almalloc.h"
-extern inline void LockEffectSlotsRead(ALCcontext *context);
-extern inline void UnlockEffectSlotsRead(ALCcontext *context);
-extern inline void LockEffectSlotsWrite(ALCcontext *context);
-extern inline void UnlockEffectSlotsWrite(ALCcontext *context);
-extern inline struct ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id);
-extern inline struct ALeffectslot *RemoveEffectSlot(ALCcontext *context, ALuint id);
-
static UIntMap EffectStateFactoryMap;
static inline ALeffectStateFactory *getFactoryByType(ALenum type)
{
@@ -54,6 +47,21 @@ static inline ALeffectStateFactory *getFactoryByType(ALenum type)
static void ALeffectState_IncRef(ALeffectState *state);
+
+static inline void LockEffectSlotList(ALCcontext *context)
+{ almtx_lock(&context->EffectSlotLock); }
+static inline void UnlockEffectSlotList(ALCcontext *context)
+{ almtx_unlock(&context->EffectSlotLock); }
+
+static inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id)
+{
+ id--;
+ if(UNLIKELY(id >= VECTOR_SIZE(context->EffectSlotList)))
+ return NULL;
+ return VECTOR_ELEM(context->EffectSlotList, id);
+}
+
+
#define DO_UPDATEPROPS() do { \
if(!ATOMIC_LOAD(&context->DeferUpdates, almemory_order_acquire)) \
UpdateEffectSlotProps(slot, context); \
@@ -76,38 +84,45 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo
SETERR_GOTO(context, AL_INVALID_VALUE, done, "Generating %d effect slots", n);
tmpslots = al_malloc(DEF_ALIGN, sizeof(ALeffectslot*)*n);
- LockEffectSlotsWrite(context);
+ LockEffectSlotList(context);
for(cur = 0;cur < n;cur++)
{
- ALeffectslot *slot = al_calloc(16, sizeof(ALeffectslot));
- err = AL_OUT_OF_MEMORY;
- if(!slot || (err=InitEffectSlot(slot)) != AL_NO_ERROR)
- {
- al_free(slot);
- UnlockEffectSlotsWrite(context);
+ ALeffectslotPtr *iter = VECTOR_BEGIN(context->EffectSlotList);
+ ALeffectslotPtr *end = VECTOR_END(context->EffectSlotList);
+ ALeffectslot *slot = NULL;
- alDeleteAuxiliaryEffectSlots(cur, effectslots);
- SETERR_GOTO(context, err, done, "Effect slot object allocation failed");
+ for(;iter != end;iter++)
+ {
+ if(!*iter)
+ break;
}
+ if(iter == end)
+ {
+ if(VECTOR_SIZE(context->EffectSlotList) >= INT_MAX)
+ {
+ UnlockEffectSlotList(context);
- err = NewThunkEntry(&slot->id);
- if(err == AL_NO_ERROR)
- err = InsertUIntMapEntryNoLock(&context->EffectSlotMap, slot->id, slot);
- if(err != AL_NO_ERROR)
+ alDeleteAuxiliaryEffectSlots(cur, effectslots);
+ SETERR_GOTO(context, err, done, "Too many effect slot objects");
+ }
+ VECTOR_PUSH_BACK(context->EffectSlotList, NULL);
+ iter = &VECTOR_BACK(context->EffectSlotList);
+ }
+ slot = al_calloc(16, sizeof(ALeffectslot));
+ err = AL_OUT_OF_MEMORY;
+ if(!slot || (err=InitEffectSlot(slot)) != AL_NO_ERROR)
{
- FreeThunkEntry(slot->id);
- ALeffectState_DecRef(slot->Effect.State);
- if(slot->Params.EffectState)
- ALeffectState_DecRef(slot->Params.EffectState);
al_free(slot);
- UnlockEffectSlotsWrite(context);
+ UnlockEffectSlotList(context);
alDeleteAuxiliaryEffectSlots(cur, effectslots);
- SETERR_GOTO(context, err, done, "Failed to set effect slot ID");
+ SETERR_GOTO(context, err, done, "Effect slot object allocation failed");
}
-
aluInitEffectPanning(slot);
+ slot->id = (iter - VECTOR_BEGIN(context->EffectSlotList)) + 1;
+ *iter = slot;
+
tmpslots[cur] = slot;
effectslots[cur] = slot->id;
}
@@ -131,7 +146,7 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo
althrd_yield();
al_free(newarray);
}
- UnlockEffectSlotsWrite(context);
+ UnlockEffectSlotList(context);
done:
al_free(tmpslots);
@@ -147,7 +162,7 @@ AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint *
context = GetContextRef();
if(!context) return;
- LockEffectSlotsWrite(context);
+ LockEffectSlotList(context);
if(!(n >= 0))
SETERR_GOTO(context, AL_INVALID_VALUE, done, "Deleting %d effect slots", n);
for(i = 0;i < n;i++)
@@ -194,9 +209,9 @@ AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint *
for(i = 0;i < n;i++)
{
- if((slot=RemoveEffectSlot(context, effectslots[i])) == NULL)
+ if((slot=LookupEffectSlot(context, effectslots[i])) == NULL)
continue;
- FreeThunkEntry(slot->id);
+ VECTOR_ELEM(context->EffectSlotList, effectslots[i]-1) = NULL;
DeinitEffectSlot(slot);
@@ -205,7 +220,7 @@ AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint *
}
done:
- UnlockEffectSlotsWrite(context);
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
}
@@ -217,9 +232,9 @@ AL_API ALboolean AL_APIENTRY alIsAuxiliaryEffectSlot(ALuint effectslot)
context = GetContextRef();
if(!context) return AL_FALSE;
- LockEffectSlotsRead(context);
+ LockEffectSlotList(context);
ret = (LookupEffectSlot(context, effectslot) ? AL_TRUE : AL_FALSE);
- UnlockEffectSlotsRead(context);
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
@@ -238,7 +253,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param
if(!context) return;
WriteLock(&context->PropLock);
- LockEffectSlotsRead(context);
+ LockEffectSlotList(context);
if((slot=LookupEffectSlot(context, effectslot)) == NULL)
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
@@ -274,7 +289,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSloti(ALuint effectslot, ALenum param
DO_UPDATEPROPS();
done:
- UnlockEffectSlotsRead(context);
+ UnlockEffectSlotList(context);
WriteUnlock(&context->PropLock);
ALCcontext_DecRef(context);
}
@@ -294,7 +309,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum para
context = GetContextRef();
if(!context) return;
- LockEffectSlotsRead(context);
+ LockEffectSlotList(context);
if(LookupEffectSlot(context, effectslot) == NULL)
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
@@ -305,7 +320,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotiv(ALuint effectslot, ALenum para
}
done:
- UnlockEffectSlotsRead(context);
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
}
@@ -318,7 +333,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param
if(!context) return;
WriteLock(&context->PropLock);
- LockEffectSlotsRead(context);
+ LockEffectSlotList(context);
if((slot=LookupEffectSlot(context, effectslot)) == NULL)
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
@@ -336,7 +351,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotf(ALuint effectslot, ALenum param
DO_UPDATEPROPS();
done:
- UnlockEffectSlotsRead(context);
+ UnlockEffectSlotList(context);
WriteUnlock(&context->PropLock);
ALCcontext_DecRef(context);
}
@@ -355,7 +370,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum para
context = GetContextRef();
if(!context) return;
- LockEffectSlotsRead(context);
+ LockEffectSlotList(context);
if(LookupEffectSlot(context, effectslot) == NULL)
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
@@ -366,7 +381,7 @@ AL_API ALvoid AL_APIENTRY alAuxiliaryEffectSlotfv(ALuint effectslot, ALenum para
}
done:
- UnlockEffectSlotsRead(context);
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
}
@@ -378,7 +393,7 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum pa
context = GetContextRef();
if(!context) return;
- LockEffectSlotsRead(context);
+ LockEffectSlotList(context);
if((slot=LookupEffectSlot(context, effectslot)) == NULL)
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
@@ -392,7 +407,7 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSloti(ALuint effectslot, ALenum pa
}
done:
- UnlockEffectSlotsRead(context);
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
}
@@ -411,7 +426,7 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum p
context = GetContextRef();
if(!context) return;
- LockEffectSlotsRead(context);
+ LockEffectSlotList(context);
if(LookupEffectSlot(context, effectslot) == NULL)
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
@@ -422,7 +437,7 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotiv(ALuint effectslot, ALenum p
}
done:
- UnlockEffectSlotsRead(context);
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
}
@@ -434,7 +449,7 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum pa
context = GetContextRef();
if(!context) return;
- LockEffectSlotsRead(context);
+ LockEffectSlotList(context);
if((slot=LookupEffectSlot(context, effectslot)) == NULL)
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
@@ -448,7 +463,7 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotf(ALuint effectslot, ALenum pa
}
done:
- UnlockEffectSlotsRead(context);
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
}
@@ -466,7 +481,7 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum p
context = GetContextRef();
if(!context) return;
- LockEffectSlotsRead(context);
+ LockEffectSlotList(context);
if(LookupEffectSlot(context, effectslot) == NULL)
SETERR_GOTO(context, AL_INVALID_NAME, done, "Invalid effect slot ID %u", effectslot);
switch(param)
@@ -477,7 +492,7 @@ AL_API ALvoid AL_APIENTRY alGetAuxiliaryEffectSlotfv(ALuint effectslot, ALenum p
}
done:
- UnlockEffectSlotsRead(context);
+ UnlockEffectSlotList(context);
ALCcontext_DecRef(context);
}
@@ -697,7 +712,7 @@ void UpdateAllEffectSlotProps(ALCcontext *context)
struct ALeffectslotArray *auxslots;
ALsizei i;
- LockEffectSlotsRead(context);
+ LockEffectSlotList(context);
auxslots = ATOMIC_LOAD(&context->ActiveAuxSlots, almemory_order_acquire);
for(i = 0;i < auxslots->count;i++)
{
@@ -705,21 +720,27 @@ void UpdateAllEffectSlotProps(ALCcontext *context)
if(!ATOMIC_FLAG_TEST_AND_SET(&slot->PropsClean, almemory_order_acq_rel))
UpdateEffectSlotProps(slot, context);
}
- UnlockEffectSlotsRead(context);
+ UnlockEffectSlotList(context);
}
-ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *Context)
+ALvoid ReleaseALAuxiliaryEffectSlots(ALCcontext *context)
{
- ALsizei pos;
- for(pos = 0;pos < Context->EffectSlotMap.size;pos++)
+ ALeffectslotPtr *iter = VECTOR_BEGIN(context->EffectSlotList);
+ ALeffectslotPtr *end = VECTOR_END(context->EffectSlotList);
+ size_t leftover = 0;
+
+ for(;iter != end;iter++)
{
- ALeffectslot *temp = Context->EffectSlotMap.values[pos];
- Context->EffectSlotMap.values[pos] = NULL;
+ ALeffectslot *slot = *iter;
+ if(!slot) continue;
+ *iter = NULL;
- DeinitEffectSlot(temp);
+ DeinitEffectSlot(slot);
- FreeThunkEntry(temp->id);
- memset(temp, 0, sizeof(ALeffectslot));
- al_free(temp);
+ memset(slot, 0, sizeof(*slot));
+ al_free(slot);
+ ++leftover;
}
+ if(leftover > 0)
+ WARN("(%p) Deleted "SZFMT" AuxiliaryEffectSlot%s\n", context, leftover, (leftover==1)?"":"s");
}
diff --git a/OpenAL32/alSource.c b/OpenAL32/alSource.c
index 05d9a456..58026aeb 100644
--- a/OpenAL32/alSource.c
+++ b/OpenAL32/alSource.c
@@ -84,6 +84,14 @@ static inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id)
return sublist->Buffers + slidx;
}
+static inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id)
+{
+ id--;
+ if(UNLIKELY(id >= VECTOR_SIZE(context->EffectSlotList)))
+ return NULL;
+ return VECTOR_ELEM(context->EffectSlotList, id);
+}
+
typedef enum SourceProp {
srcPitch = AL_PITCH,
@@ -972,23 +980,23 @@ static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
case AL_AUXILIARY_SEND_FILTER:
- LockEffectSlotsRead(Context);
+ almtx_lock(&Context->EffectSlotLock);
if(!(values[0] == 0 || (slot=LookupEffectSlot(Context, values[0])) != NULL))
{
- UnlockEffectSlotsRead(Context);
+ almtx_unlock(&Context->EffectSlotLock);
SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid effect ID %u",
values[0]);
}
if(!((ALuint)values[1] < (ALuint)device->NumAuxSends))
{
- UnlockEffectSlotsRead(Context);
+ almtx_unlock(&Context->EffectSlotLock);
SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid send %u", values[1]);
}
LockFiltersRead(device);
if(!(values[2] == 0 || (filter=LookupFilter(device, values[2])) != NULL))
{
UnlockFiltersRead(device);
- UnlockEffectSlotsRead(Context);
+ almtx_unlock(&Context->EffectSlotLock);
SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid filter ID %u",
values[2]);
}
@@ -1037,7 +1045,7 @@ static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
Source->Send[values[1]].Slot = slot;
DO_UPDATEPROPS();
}
- UnlockEffectSlotsRead(Context);
+ almtx_unlock(&Context->EffectSlotLock);
return AL_TRUE;