aboutsummaryrefslogtreecommitdiffstats
path: root/al
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-08-24 16:34:53 -0700
committerChris Robinson <[email protected]>2020-08-24 16:34:53 -0700
commit73ab9d46c88f034a32a6fb174e98fd23dec1ff98 (patch)
treeeb1bc6a757fc533369ee1fd74b14378d3033cf4d /al
parentf9d6aa2f480a0d647e8ad901a5680c335ba4fa0c (diff)
Use an intrusive_ptr to hold the unapplied effect state
Diffstat (limited to 'al')
-rw-r--r--al/auxeffectslot.cpp15
-rw-r--r--al/auxeffectslot.h2
2 files changed, 7 insertions, 10 deletions
diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp
index c5f9a295..bfacb290 100644
--- a/al/auxeffectslot.cpp
+++ b/al/auxeffectslot.cpp
@@ -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);
diff --git a/al/auxeffectslot.h b/al/auxeffectslot.h
index c9e54f60..71f99a11 100644
--- a/al/auxeffectslot.h
+++ b/al/auxeffectslot.h
@@ -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;