Always use RAII with EffectSlotLock
This commit is contained in:
parent
757c42c74b
commit
75213ee6f9
@ -2263,7 +2263,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
||||
}
|
||||
|
||||
almtx_lock(&context->PropLock);
|
||||
almtx_lock(&context->EffectSlotLock);
|
||||
std::unique_lock<almtx_t> slotlock{context->EffectSlotLock};
|
||||
for(auto &slot : context->EffectSlotList)
|
||||
{
|
||||
EffectState *state = slot->Effect.State;
|
||||
@ -2275,7 +2275,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
|
||||
else
|
||||
UpdateEffectSlotProps(slot.get(), context);
|
||||
}
|
||||
almtx_unlock(&context->EffectSlotLock);
|
||||
slotlock.unlock();
|
||||
|
||||
almtx_lock(&context->SourceLock);
|
||||
for(auto &sublist : context->SourceList)
|
||||
|
@ -135,11 +135,6 @@ void UpdateContextProps(ALCcontext *context);
|
||||
void ALCcontext_DeferUpdates(ALCcontext *context);
|
||||
void ALCcontext_ProcessUpdates(ALCcontext *context);
|
||||
|
||||
inline void LockEffectSlotList(ALCcontext *context)
|
||||
{ almtx_lock(&context->EffectSlotLock); }
|
||||
inline void UnlockEffectSlotList(ALCcontext *context)
|
||||
{ almtx_unlock(&context->EffectSlotLock); }
|
||||
|
||||
|
||||
/* Simple RAII context reference. Takes the reference of the provided
|
||||
* ALCcontext, and decrements it when leaving scope. Movable (transfer
|
||||
|
@ -755,6 +755,7 @@ static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
|
||||
ALfilter *filter = NULL;
|
||||
ALeffectslot *slot = NULL;
|
||||
ALbufferlistitem *oldlist;
|
||||
std::unique_lock<almtx_t> slotlock;
|
||||
ALfloat fvals[6];
|
||||
|
||||
switch(prop)
|
||||
@ -980,23 +981,23 @@ static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
|
||||
|
||||
|
||||
case AL_AUXILIARY_SEND_FILTER:
|
||||
LockEffectSlotList(Context);
|
||||
slotlock = std::unique_lock<almtx_t>{Context->EffectSlotLock};
|
||||
if(!(values[0] == 0 || (slot=LookupEffectSlot(Context, values[0])) != NULL))
|
||||
{
|
||||
UnlockEffectSlotList(Context);
|
||||
slotlock.unlock();
|
||||
SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid effect ID %u",
|
||||
values[0]);
|
||||
}
|
||||
if((ALuint)values[1] >= (ALuint)device->NumAuxSends)
|
||||
{
|
||||
UnlockEffectSlotList(Context);
|
||||
slotlock.unlock();
|
||||
SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid send %u", values[1]);
|
||||
}
|
||||
LockFilterList(device);
|
||||
if(!(values[2] == 0 || (filter=LookupFilter(device, values[2])) != NULL))
|
||||
{
|
||||
UnlockFilterList(device);
|
||||
UnlockEffectSlotList(Context);
|
||||
slotlock.unlock();
|
||||
SETERR_RETURN(Context, AL_INVALID_VALUE, AL_FALSE, "Invalid filter ID %u",
|
||||
values[2]);
|
||||
}
|
||||
@ -1045,7 +1046,6 @@ static ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp p
|
||||
Source->Send[values[1]].Slot = slot;
|
||||
DO_UPDATEPROPS();
|
||||
}
|
||||
UnlockEffectSlotList(Context);
|
||||
|
||||
return AL_TRUE;
|
||||
|
||||
|
@ -137,7 +137,7 @@ public:
|
||||
using mutex_type = almtx_t;
|
||||
|
||||
explicit lock_guard(almtx_t &mtx) : mMtx(mtx) { almtx_lock(&mMtx); }
|
||||
lock_guard(almtx_t &mtx, std::adopt_lock_t) : mMtx(mtx) { }
|
||||
lock_guard(almtx_t &mtx, std::adopt_lock_t) noexcept : mMtx(mtx) { }
|
||||
~lock_guard() { almtx_unlock(&mMtx); }
|
||||
|
||||
lock_guard(const lock_guard&) = delete;
|
||||
@ -152,8 +152,9 @@ class unique_lock<almtx_t> {
|
||||
public:
|
||||
using mutex_type = almtx_t;
|
||||
|
||||
unique_lock() noexcept = default;
|
||||
explicit unique_lock(almtx_t &mtx) : mMtx(&mtx) { almtx_lock(mMtx); mLocked = true; }
|
||||
unique_lock(unique_lock&& rhs) : mMtx(rhs.mMtx), mLocked(rhs.mLocked)
|
||||
unique_lock(unique_lock&& rhs) noexcept : mMtx(rhs.mMtx), mLocked(rhs.mLocked)
|
||||
{ rhs.mMtx = nullptr; rhs.mLocked = false; }
|
||||
~unique_lock() { if(mLocked) almtx_unlock(mMtx); }
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user