Use an intrusive_ptr to hold the unapplied effect state

This commit is contained in:
Chris Robinson 2020-08-24 16:34:53 -07:00
parent f9d6aa2f48
commit 73ab9d46c8
3 changed files with 9 additions and 12 deletions

View File

@ -693,8 +693,6 @@ ALeffectslot::~ALeffectslot()
delete props;
}
if(Effect.State)
Effect.State->release();
if(Params.mEffectState)
Params.mEffectState->release();
}
@ -703,11 +701,12 @@ ALenum ALeffectslot::init()
{
EffectStateFactory *factory{getFactoryByType(Effect.Type)};
if(!factory) return AL_INVALID_VALUE;
Effect.State = factory->create();
Effect.State.reset(factory->create());
if(!Effect.State) return AL_OUT_OF_MEMORY;
Effect.State->add_ref();
Params.mEffectState = Effect.State;
Params.mEffectState = Effect.State.get();
return AL_NO_ERROR;
}
@ -722,7 +721,7 @@ ALenum ALeffectslot::initEffect(ALeffect *effect, ALCcontext *context)
ERR("Failed to find factory for effect type 0x%04x\n", newtype);
return AL_INVALID_ENUM;
}
EffectState *State{factory->create()};
al::intrusive_ptr<EffectState> State{factory->create()};
if(!State) return AL_OUT_OF_MEMORY;
ALCdevice *Device{context->mDevice.get()};
@ -744,8 +743,7 @@ ALenum ALeffectslot::initEffect(ALeffect *effect, ALCcontext *context)
Effect.Props = effect->Props;
}
Effect.State->release();
Effect.State = State;
Effect.State = std::move(State);
}
else if(effect)
Effect.Props = effect->Props;
@ -786,8 +784,7 @@ void ALeffectslot::updateProps(ALCcontext *context)
/* Swap out any stale effect state object there may be in the container, to
* delete it.
*/
Effect.State->add_ref();
props->State.reset(Effect.State);
props->State = Effect.State;
/* Set the new container for updating internal parameters. */
props = Params.Update.exchange(props, std::memory_order_acq_rel);

View File

@ -49,7 +49,7 @@ struct ALeffectslot {
ALenum Type{AL_EFFECT_NULL};
EffectProps Props{};
EffectState *State{nullptr};
al::intrusive_ptr<EffectState> State;
} Effect;
std::atomic_flag PropsClean;

View File

@ -2095,7 +2095,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
{
aluInitEffectPanning(slot, device);
EffectState *state{slot->Effect.State};
EffectState *state{slot->Effect.State.get()};
state->mOutTarget = device->Dry.Buffer;
state->deviceUpdate(device);
slot->updateProps(context);
@ -2116,7 +2116,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const int *attrList)
aluInitEffectPanning(slot, device);
EffectState *state{slot->Effect.State};
EffectState *state{slot->Effect.State.get()};
state->mOutTarget = device->Dry.Buffer;
state->deviceUpdate(device);
slot->updateProps(context);