Use an intrusive_ptr for ALeffectslotProps::State
This commit is contained in:
parent
01f76f2b67
commit
ff5c9d1c15
@ -640,7 +640,6 @@ ALeffectslot::~ALeffectslot()
|
|||||||
ALeffectslotProps *props{Params.Update.load()};
|
ALeffectslotProps *props{Params.Update.load()};
|
||||||
if(props)
|
if(props)
|
||||||
{
|
{
|
||||||
if(props->State) props->State->release();
|
|
||||||
TRACE("Freed unapplied AuxiliaryEffectSlot update %p\n",
|
TRACE("Freed unapplied AuxiliaryEffectSlot update %p\n",
|
||||||
decltype(std::declval<void*>()){props});
|
decltype(std::declval<void*>()){props});
|
||||||
delete props;
|
delete props;
|
||||||
@ -707,8 +706,6 @@ ALenum ALeffectslot::initEffect(ALeffect *effect, ALCcontext *context)
|
|||||||
ALeffectslotProps *props{context->mFreeEffectslotProps.load()};
|
ALeffectslotProps *props{context->mFreeEffectslotProps.load()};
|
||||||
while(props)
|
while(props)
|
||||||
{
|
{
|
||||||
if(props->State)
|
|
||||||
props->State->release();
|
|
||||||
props->State = nullptr;
|
props->State = nullptr;
|
||||||
props = props->next.load(std::memory_order_relaxed);
|
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
|
/* Swap out any stale effect state object there may be in the container, to
|
||||||
* delete it.
|
* delete it.
|
||||||
*/
|
*/
|
||||||
EffectState *oldstate{props->State};
|
|
||||||
Effect.State->add_ref();
|
Effect.State->add_ref();
|
||||||
props->State = Effect.State;
|
props->State.reset(Effect.State);
|
||||||
|
|
||||||
/* Set the new container for updating internal parameters. */
|
/* Set the new container for updating internal parameters. */
|
||||||
props = Params.Update.exchange(props, std::memory_order_acq_rel);
|
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
|
/* If there was an unused update container, put it back in the
|
||||||
* freelist.
|
* freelist.
|
||||||
*/
|
*/
|
||||||
if(props->State)
|
|
||||||
props->State->release();
|
|
||||||
props->State = nullptr;
|
props->State = nullptr;
|
||||||
AtomicReplaceHead(context->mFreeEffectslotProps, props);
|
AtomicReplaceHead(context->mFreeEffectslotProps, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(oldstate)
|
|
||||||
oldstate->release();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateAllEffectSlotProps(ALCcontext *context)
|
void UpdateAllEffectSlotProps(ALCcontext *context)
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "almalloc.h"
|
#include "almalloc.h"
|
||||||
#include "atomic.h"
|
#include "atomic.h"
|
||||||
#include "effects/base.h"
|
#include "effects/base.h"
|
||||||
|
#include "intrusive_ptr.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
|
|
||||||
struct ALeffect;
|
struct ALeffect;
|
||||||
@ -29,7 +30,7 @@ struct ALeffectslotProps {
|
|||||||
ALenum Type;
|
ALenum Type;
|
||||||
EffectProps Props;
|
EffectProps Props;
|
||||||
|
|
||||||
EffectState *State;
|
al::intrusive_ptr<EffectState> State;
|
||||||
|
|
||||||
std::atomic<ALeffectslotProps*> next;
|
std::atomic<ALeffectslotProps*> next;
|
||||||
|
|
||||||
|
@ -2353,7 +2353,6 @@ ALCcontext::~ALCcontext()
|
|||||||
while(eprops)
|
while(eprops)
|
||||||
{
|
{
|
||||||
ALeffectslotProps *next{eprops->next.load(std::memory_order_relaxed)};
|
ALeffectslotProps *next{eprops->next.load(std::memory_order_relaxed)};
|
||||||
if(eprops->State) eprops->State->release();
|
|
||||||
delete eprops;
|
delete eprops;
|
||||||
eprops = next;
|
eprops = next;
|
||||||
++count;
|
++count;
|
||||||
|
@ -476,8 +476,7 @@ bool CalcEffectSlotParams(ALeffectslot *slot, ALeffectslot **sorted_slots, ALCco
|
|||||||
slot->Params.AirAbsorptionGainHF = 1.0f;
|
slot->Params.AirAbsorptionGainHF = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
EffectState *state{props->State};
|
EffectState *state{props->State.release()};
|
||||||
props->State = nullptr;
|
|
||||||
EffectState *oldstate{slot->Params.mEffectState};
|
EffectState *oldstate{slot->Params.mEffectState};
|
||||||
slot->Params.mEffectState = state;
|
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
|
* cleaned up sometime later (not ideal, but better than blocking
|
||||||
* or leaking).
|
* or leaking).
|
||||||
*/
|
*/
|
||||||
props->State = oldstate;
|
props->State.reset(oldstate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user