Use an intrusive_ptr for ALeffectslotProps::State

This commit is contained in:
Chris Robinson 2020-08-22 22:45:26 -07:00
parent 01f76f2b67
commit ff5c9d1c15
4 changed files with 5 additions and 15 deletions

View File

@ -640,7 +640,6 @@ ALeffectslot::~ALeffectslot()
ALeffectslotProps *props{Params.Update.load()};
if(props)
{
if(props->State) props->State->release();
TRACE("Freed unapplied AuxiliaryEffectSlot update %p\n",
decltype(std::declval<void*>()){props});
delete props;
@ -707,8 +706,6 @@ ALenum ALeffectslot::initEffect(ALeffect *effect, ALCcontext *context)
ALeffectslotProps *props{context->mFreeEffectslotProps.load()};
while(props)
{
if(props->State)
props->State->release();
props->State = nullptr;
props = props->next.load(std::memory_order_relaxed);
}
@ -741,9 +738,8 @@ void ALeffectslot::updateProps(ALCcontext *context)
/* Swap out any stale effect state object there may be in the container, to
* delete it.
*/
EffectState *oldstate{props->State};
Effect.State->add_ref();
props->State = Effect.State;
props->State.reset(Effect.State);
/* Set the new container for updating internal parameters. */
props = Params.Update.exchange(props, std::memory_order_acq_rel);
@ -752,14 +748,9 @@ void ALeffectslot::updateProps(ALCcontext *context)
/* If there was an unused update container, put it back in the
* freelist.
*/
if(props->State)
props->State->release();
props->State = nullptr;
AtomicReplaceHead(context->mFreeEffectslotProps, props);
}
if(oldstate)
oldstate->release();
}
void UpdateAllEffectSlotProps(ALCcontext *context)

View File

@ -12,6 +12,7 @@
#include "almalloc.h"
#include "atomic.h"
#include "effects/base.h"
#include "intrusive_ptr.h"
#include "vector.h"
struct ALeffect;
@ -29,7 +30,7 @@ struct ALeffectslotProps {
ALenum Type;
EffectProps Props;
EffectState *State;
al::intrusive_ptr<EffectState> State;
std::atomic<ALeffectslotProps*> next;

View File

@ -2353,7 +2353,6 @@ ALCcontext::~ALCcontext()
while(eprops)
{
ALeffectslotProps *next{eprops->next.load(std::memory_order_relaxed)};
if(eprops->State) eprops->State->release();
delete eprops;
eprops = next;
++count;

View File

@ -476,8 +476,7 @@ bool CalcEffectSlotParams(ALeffectslot *slot, ALeffectslot **sorted_slots, ALCco
slot->Params.AirAbsorptionGainHF = 1.0f;
}
EffectState *state{props->State};
props->State = nullptr;
EffectState *state{props->State.release()};
EffectState *oldstate{slot->Params.mEffectState};
slot->Params.mEffectState = state;
@ -502,7 +501,7 @@ bool CalcEffectSlotParams(ALeffectslot *slot, ALeffectslot **sorted_slots, ALCco
* cleaned up sometime later (not ideal, but better than blocking
* or leaking).
*/
props->State = oldstate;
props->State.reset(oldstate);
}
}