aboutsummaryrefslogtreecommitdiffstats
path: root/OpenAL32
diff options
context:
space:
mode:
Diffstat (limited to 'OpenAL32')
-rw-r--r--OpenAL32/Include/alAuxEffectSlot.h8
-rw-r--r--OpenAL32/Include/alMain.h2
-rw-r--r--OpenAL32/alAuxEffectSlot.c113
3 files changed, 77 insertions, 46 deletions
diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h
index c6e40a55..7f95dc91 100644
--- a/OpenAL32/Include/alAuxEffectSlot.h
+++ b/OpenAL32/Include/alAuxEffectSlot.h
@@ -75,6 +75,12 @@ static const struct ALeffectStateFactoryVtable T##_ALeffectStateFactory_vtable =
#define MAX_EFFECT_CHANNELS (4)
+struct ALeffectslotArray {
+ ALsizei count;
+ struct ALeffectslot *slot[];
+};
+
+
struct ALeffectslotProps {
ALfloat Gain;
ALboolean AuxSendAuto;
@@ -134,8 +140,6 @@ typedef struct ALeffectslot {
* first-order device output (FOAOut).
*/
alignas(16) ALfloat WetBuffer[MAX_EFFECT_CHANNELS][BUFFERSIZE];
-
- ATOMIC(struct ALeffectslot*) next;
} ALeffectslot;
inline void LockEffectSlotsRead(ALCcontext *context)
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 2182d3f0..9c1ef099 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -855,7 +855,7 @@ struct ALCcontext_struct {
ALsizei VoiceCount;
ALsizei MaxVoices;
- ATOMIC(struct ALeffectslot*) ActiveAuxSlotList;
+ ATOMIC(struct ALeffectslotArray*) ActiveAuxSlots;
ALCdevice *Device;
const ALCchar *ExtensionList;
diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c
index 65107287..743fac14 100644
--- a/OpenAL32/alAuxEffectSlot.c
+++ b/OpenAL32/alAuxEffectSlot.c
@@ -42,8 +42,6 @@ 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 void RemoveEffectSlotList(ALCcontext *Context, ALeffectslot *slot);
-
static UIntMap EffectStateFactoryMap;
static inline ALeffectStateFactory *getFactoryByType(ALenum type)
{
@@ -67,7 +65,7 @@ static void ALeffectState_DecRef(ALeffectState *state);
AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslots)
{
ALCcontext *context;
- ALeffectslot *first, *last;
+ ALeffectslot **tmpslots = NULL;
ALsizei cur;
ALenum err;
@@ -76,8 +74,9 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo
if(!(n >= 0))
SET_ERROR_AND_GOTO(context, AL_INVALID_VALUE, done);
+ tmpslots = al_malloc(DEF_ALIGN, sizeof(ALeffectslot*)*n);
- first = last = NULL;
+ LockEffectSlotsWrite(context);
for(cur = 0;cur < n;cur++)
{
ALeffectslot *slot = al_calloc(16, sizeof(ALeffectslot));
@@ -85,13 +84,15 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo
if(!slot || (err=InitEffectSlot(slot)) != AL_NO_ERROR)
{
al_free(slot);
+ UnlockEffectSlotsWrite(context);
+
alDeleteAuxiliaryEffectSlots(cur, effectslots);
SET_ERROR_AND_GOTO(context, err, done);
}
err = NewThunkEntry(&slot->id);
if(err == AL_NO_ERROR)
- err = InsertUIntMapEntry(&context->EffectSlotMap, slot->id, slot);
+ err = InsertUIntMapEntryNoLock(&context->EffectSlotMap, slot->id, slot);
if(err != AL_NO_ERROR)
{
FreeThunkEntry(slot->id);
@@ -99,6 +100,7 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo
if(slot->Params.EffectState)
ALeffectState_DecRef(slot->Params.EffectState);
al_free(slot);
+ UnlockEffectSlotsWrite(context);
alDeleteAuxiliaryEffectSlots(cur, effectslots);
SET_ERROR_AND_GOTO(context, err, done);
@@ -106,22 +108,36 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo
aluInitEffectPanning(slot);
- if(!first) first = slot;
- if(last) ATOMIC_STORE(&last->next, slot, almemory_order_relaxed);
- last = slot;
-
+ tmpslots[cur] = slot;
effectslots[cur] = slot->id;
}
- if(last != NULL)
+ if(n > 0)
{
- ALeffectslot *root = ATOMIC_LOAD_SEQ(&context->ActiveAuxSlotList);
- do {
- ATOMIC_STORE(&last->next, root, almemory_order_relaxed);
- } while(!ATOMIC_COMPARE_EXCHANGE_WEAK_SEQ(ALeffectslot*, &context->ActiveAuxSlotList,
- &root, first));
+ struct ALeffectslotArray *curarray = ATOMIC_LOAD(&context->ActiveAuxSlots, almemory_order_acquire);
+ struct ALeffectslotArray *newarray = NULL;
+ ALsizei newcount = curarray->count + n;
+ ALCdevice *device;
+
+ newarray = al_calloc(DEF_ALIGN,
+ offsetof(struct ALeffectslotArray, slot[newcount])
+ );
+ newarray->count = newcount;
+ memcpy(newarray->slot, tmpslots, sizeof(ALeffectslot*)*n);
+ if(curarray)
+ memcpy(newarray->slot+n, curarray->slot, sizeof(ALeffectslot*)*curarray->count);
+
+ newarray = ATOMIC_EXCHANGE(struct ALeffectslotArray*,
+ &context->ActiveAuxSlots, newarray, almemory_order_acq_rel
+ );
+ device = context->Device;
+ while((ATOMIC_LOAD(&device->MixCount, almemory_order_acquire)&1))
+ althrd_yield();
+ al_free(newarray);
}
+ UnlockEffectSlotsWrite(context);
done:
+ al_free(tmpslots);
ALCcontext_DecRef(context);
}
@@ -146,13 +162,46 @@ AL_API ALvoid AL_APIENTRY alDeleteAuxiliaryEffectSlots(ALsizei n, const ALuint *
}
// All effectslots are valid
+ if(n > 0)
+ {
+ struct ALeffectslotArray *curarray = ATOMIC_LOAD(&context->ActiveAuxSlots, almemory_order_acquire);
+ struct ALeffectslotArray *newarray = NULL;
+ ALsizei newcount = curarray->count - n;
+ ALCdevice *device;
+ ALsizei j, k;
+
+ assert(newcount >= 0);
+ newarray = al_calloc(DEF_ALIGN,
+ offsetof(struct ALeffectslotArray, slot[newcount])
+ );
+ newarray->count = newcount;
+ for(i = j = 0;i < newarray->count;)
+ {
+ slot = curarray->slot[j++];
+ for(k = 0;k < n;k++)
+ {
+ if(slot->id == effectslots[k])
+ break;
+ }
+ if(k == n)
+ newarray->slot[i++] = slot;
+ }
+
+ newarray = ATOMIC_EXCHANGE(struct ALeffectslotArray*,
+ &context->ActiveAuxSlots, newarray, almemory_order_acq_rel
+ );
+ device = context->Device;
+ while((ATOMIC_LOAD(&device->MixCount, almemory_order_acquire)&1))
+ althrd_yield();
+ al_free(newarray);
+ }
+
for(i = 0;i < n;i++)
{
if((slot=RemoveEffectSlot(context, effectslots[i])) == NULL)
continue;
FreeThunkEntry(slot->id);
- RemoveEffectSlotList(context, slot);
DeinitEffectSlot(slot);
memset(slot, 0, sizeof(*slot));
@@ -430,27 +479,6 @@ done:
}
-static void RemoveEffectSlotList(ALCcontext *context, ALeffectslot *slot)
-{
- ALCdevice *device = context->Device;
- ALeffectslot *root, *next;
-
- root = slot;
- next = ATOMIC_LOAD_SEQ(&slot->next);
- if(!ATOMIC_COMPARE_EXCHANGE_STRONG_SEQ(ALeffectslot*, &context->ActiveAuxSlotList, &root, next))
- {
- ALeffectslot *cur;
- do {
- cur = root;
- root = slot;
- } while(!ATOMIC_COMPARE_EXCHANGE_STRONG_SEQ(ALeffectslot*, &cur->next, &root, next));
- }
- /* Wait for any mix that may be using these effect slots to finish. */
- while((ReadRef(&device->MixCount)&1) != 0)
- althrd_yield();
-}
-
-
void InitEffectFactoryMap(void)
{
InitUIntMap(&EffectStateFactoryMap, ~0);
@@ -595,8 +623,6 @@ ALenum InitEffectSlot(ALeffectslot *slot)
slot->Params.DecayTime = 0.0f;
slot->Params.AirAbsorptionGainHF = 1.0f;
- ATOMIC_INIT(&slot->next, NULL);
-
return AL_NO_ERROR;
}
@@ -677,15 +703,16 @@ void UpdateEffectSlotProps(ALeffectslot *slot)
void UpdateAllEffectSlotProps(ALCcontext *context)
{
- ALeffectslot *slot;
+ struct ALeffectslotArray *auxslots;
+ ALsizei i;
LockEffectSlotsRead(context);
- slot = ATOMIC_LOAD_SEQ(&context->ActiveAuxSlotList);
- while(slot)
+ auxslots = ATOMIC_LOAD(&context->ActiveAuxSlots, almemory_order_acquire);
+ for(i = 0;i < auxslots->count;i++)
{
+ ALeffectslot *slot = auxslots->slot[i];
if(!ATOMIC_FLAG_TEST_AND_SET(&slot->PropsClean, almemory_order_acq_rel))
UpdateEffectSlotProps(slot);
- slot = ATOMIC_LOAD(&slot->next, almemory_order_relaxed);
}
UnlockEffectSlotsRead(context);
}