aboutsummaryrefslogtreecommitdiffstats
path: root/al
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-08-01 13:28:53 -0700
committerChris Robinson <[email protected]>2019-08-01 13:43:32 -0700
commit65f7fc610e6a6101509906c0c9bbbd794c9a3737 (patch)
tree48e03a76d121d2927623c8982c149acb0a8d616e /al
parent380f3dc11de1b3d8e6a00b2920cb809cfb953c0d (diff)
Add a common base for auto-deleting ref-counted objects
Which will also work as the basis for a future intrusive_ptr
Diffstat (limited to 'al')
-rw-r--r--al/auxeffectslot.cpp44
-rw-r--r--al/buffer.cpp8
-rw-r--r--al/event.cpp2
-rw-r--r--al/source.cpp26
4 files changed, 33 insertions, 47 deletions
diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp
index 2d10efde..b4e93858 100644
--- a/al/auxeffectslot.cpp
+++ b/al/auxeffectslot.cpp
@@ -320,7 +320,7 @@ START_API_FUNC
context->setError(AL_INVALID_NAME, "Invalid effect slot ID %u", id);
return true;
}
- if(ReadRef(&slot->ref) != 0)
+ if(ReadRef(slot->ref) != 0)
{
context->setError(AL_INVALID_NAME, "Deleting in-use effect slot %u", id);
return true;
@@ -418,14 +418,14 @@ START_API_FUNC
/* We must force an update if there was an existing effect slot
* target, in case it's about to be deleted.
*/
- if(target) IncrementRef(&target->ref);
- DecrementRef(&oldtarget->ref);
+ if(target) IncrementRef(target->ref);
+ DecrementRef(oldtarget->ref);
slot->Target = target;
UpdateEffectSlotProps(slot, context.get());
return;
}
- if(target) IncrementRef(&target->ref);
+ if(target) IncrementRef(target->ref);
slot->Target = target;
break;
@@ -651,7 +651,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect
{
statelock.unlock();
mixer_mode.leave();
- State->DecRef();
+ State->release();
return AL_OUT_OF_MEMORY;
}
mixer_mode.leave();
@@ -667,7 +667,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect
EffectSlot->Effect.Props = effect->Props;
}
- EffectSlot->Effect.State->DecRef();
+ EffectSlot->Effect.State->release();
EffectSlot->Effect.State = State;
}
else if(effect)
@@ -678,7 +678,7 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect
while(props)
{
if(props->State)
- props->State->DecRef();
+ props->State->release();
props->State = nullptr;
props = props->next.load(std::memory_order_relaxed);
}
@@ -687,20 +687,6 @@ ALenum InitializeEffect(ALCcontext *Context, ALeffectslot *EffectSlot, ALeffect
}
-void EffectState::IncRef() noexcept
-{
- auto ref = IncrementRef(&mRef);
- TRACEREF("EffectState %p increasing refcount to %u\n", this, ref);
-}
-
-void EffectState::DecRef() noexcept
-{
- auto ref = DecrementRef(&mRef);
- TRACEREF("EffectState %p decreasing refcount to %u\n", this, ref);
- if(ref == 0) delete this;
-}
-
-
ALenum InitEffectSlot(ALeffectslot *slot)
{
EffectStateFactory *factory{getFactoryByType(slot->Effect.Type)};
@@ -708,7 +694,7 @@ ALenum InitEffectSlot(ALeffectslot *slot)
slot->Effect.State = factory->create();
if(!slot->Effect.State) return AL_OUT_OF_MEMORY;
- slot->Effect.State->IncRef();
+ slot->Effect.State->add_ref();
slot->Params.mEffectState = slot->Effect.State;
return AL_NO_ERROR;
}
@@ -716,21 +702,21 @@ ALenum InitEffectSlot(ALeffectslot *slot)
ALeffectslot::~ALeffectslot()
{
if(Target)
- DecrementRef(&Target->ref);
+ DecrementRef(Target->ref);
Target = nullptr;
ALeffectslotProps *props{Update.load()};
if(props)
{
- if(props->State) props->State->DecRef();
+ if(props->State) props->State->release();
TRACE("Freed unapplied AuxiliaryEffectSlot update %p\n", props);
al_free(props);
}
if(Effect.State)
- Effect.State->DecRef();
+ Effect.State->release();
if(Params.mEffectState)
- Params.mEffectState->DecRef();
+ Params.mEffectState->release();
}
void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context)
@@ -759,7 +745,7 @@ void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context)
* delete it.
*/
EffectState *oldstate{props->State};
- slot->Effect.State->IncRef();
+ slot->Effect.State->add_ref();
props->State = slot->Effect.State;
/* Set the new container for updating internal parameters. */
@@ -770,13 +756,13 @@ void UpdateEffectSlotProps(ALeffectslot *slot, ALCcontext *context)
* freelist.
*/
if(props->State)
- props->State->DecRef();
+ props->State->release();
props->State = nullptr;
AtomicReplaceHead(context->mFreeEffectslotProps, props);
}
if(oldstate)
- oldstate->DecRef();
+ oldstate->release();
}
void UpdateAllEffectSlotProps(ALCcontext *context)
diff --git a/al/buffer.cpp b/al/buffer.cpp
index 4e843e03..173c76bd 100644
--- a/al/buffer.cpp
+++ b/al/buffer.cpp
@@ -380,7 +380,7 @@ const ALchar *NameFromUserFmtType(UserFmtType type)
*/
void LoadData(ALCcontext *context, ALbuffer *ALBuf, ALuint freq, ALsizei size, UserFmtChannels SrcChannels, UserFmtType SrcType, const al::byte *SrcData, ALbitfieldSOFT access)
{
- if(UNLIKELY(ReadRef(&ALBuf->ref) != 0 || ALBuf->MappedAccess != 0))
+ if(UNLIKELY(ReadRef(ALBuf->ref) != 0 || ALBuf->MappedAccess != 0))
SETERR_RETURN(context, AL_INVALID_OPERATION,, "Modifying storage for in-use buffer %u",
ALBuf->id);
@@ -671,7 +671,7 @@ START_API_FUNC
context->setError(AL_INVALID_NAME, "Invalid buffer ID %u", bid);
return true;
}
- if(UNLIKELY(ReadRef(&ALBuf->ref) != 0))
+ if(UNLIKELY(ReadRef(ALBuf->ref) != 0))
{
context->setError(AL_INVALID_OPERATION, "Deleting in-use buffer %u", bid);
return true;
@@ -768,7 +768,7 @@ START_API_FUNC
else
{
ALbitfieldSOFT unavailable = (albuf->Access^access) & access;
- if(UNLIKELY(ReadRef(&albuf->ref) != 0 && !(access&AL_MAP_PERSISTENT_BIT_SOFT)))
+ if(UNLIKELY(ReadRef(albuf->ref) != 0 && !(access&AL_MAP_PERSISTENT_BIT_SOFT)))
context->setError(AL_INVALID_OPERATION,
"Mapping in-use buffer %u without persistent mapping", buffer);
else if(UNLIKELY(albuf->MappedAccess != 0))
@@ -1126,7 +1126,7 @@ START_API_FUNC
else switch(param)
{
case AL_LOOP_POINTS_SOFT:
- if(UNLIKELY(ReadRef(&albuf->ref) != 0))
+ if(UNLIKELY(ReadRef(albuf->ref) != 0))
context->setError(AL_INVALID_OPERATION, "Modifying in-use buffer %u's loop points",
buffer);
else if(UNLIKELY(values[0] < 0 || values[0] >= values[1] ||
diff --git a/al/event.cpp b/al/event.cpp
index 0d41e713..75827b59 100644
--- a/al/event.cpp
+++ b/al/event.cpp
@@ -64,7 +64,7 @@ static int EventThread(ALCcontext *context)
if(evt.EnumType == EventType_ReleaseEffectState)
{
- evt.u.mEffectState->DecRef();
+ evt.u.mEffectState->release();
continue;
}
diff --git a/al/source.cpp b/al/source.cpp
index 6708c970..1e0940de 100644
--- a/al/source.cpp
+++ b/al/source.cpp
@@ -1309,7 +1309,7 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co
newlist->mMaxSamples = buffer->SampleLen;
newlist->mNumBuffers = 1;
newlist->mBuffers[0] = buffer;
- IncrementRef(&buffer->ref);
+ IncrementRef(buffer->ref);
/* Source is now Static */
Source->SourceType = AL_STATIC;
@@ -1331,7 +1331,7 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co
std::for_each(temp->begin(), temp->end(),
[](ALbuffer *buffer) -> void
- { if(buffer) DecrementRef(&buffer->ref); });
+ { if(buffer) DecrementRef(buffer->ref); });
al_free(temp);
}
return AL_TRUE;
@@ -1475,9 +1475,9 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co
if(slot != Source->Send[values[1]].Slot && IsPlayingOrPaused(Source))
{
/* Add refcount on the new slot, and release the previous slot */
- if(slot) IncrementRef(&slot->ref);
+ if(slot) IncrementRef(slot->ref);
if(Source->Send[values[1]].Slot)
- DecrementRef(&Source->Send[values[1]].Slot->ref);
+ DecrementRef(Source->Send[values[1]].Slot->ref);
Source->Send[values[1]].Slot = slot;
/* We must force an update if the auxiliary slot changed on an
@@ -1489,9 +1489,9 @@ ALboolean SetSourceiv(ALsource *Source, ALCcontext *Context, SourceProp prop, co
}
else
{
- if(slot) IncrementRef(&slot->ref);
+ if(slot) IncrementRef(slot->ref);
if(Source->Send[values[1]].Slot)
- DecrementRef(&Source->Send[values[1]].Slot->ref);
+ DecrementRef(Source->Send[values[1]].Slot->ref);
Source->Send[values[1]].Slot = slot;
UpdateSourceProps(Source, Context);
}
@@ -3249,7 +3249,7 @@ START_API_FUNC
BufferList->mBuffers[0] = buffer;
if(!buffer) continue;
- IncrementRef(&buffer->ref);
+ IncrementRef(buffer->ref);
if(buffer->MappedAccess != 0 && !(buffer->MappedAccess&AL_MAP_PERSISTENT_BIT_SOFT))
{
@@ -3274,7 +3274,7 @@ START_API_FUNC
ALbufferlistitem *next = BufferListStart->mNext.load(std::memory_order_relaxed);
std::for_each(BufferListStart->begin(), BufferListStart->end(),
[](ALbuffer *buffer) -> void
- { if(buffer) DecrementRef(&buffer->ref); });
+ { if(buffer) DecrementRef(buffer->ref); });
al_free(BufferListStart);
BufferListStart = next;
}
@@ -3350,7 +3350,7 @@ START_API_FUNC
BufferList->mBuffers[BufferList->mNumBuffers++] = buffer;
if(!buffer) continue;
- IncrementRef(&buffer->ref);
+ IncrementRef(buffer->ref);
BufferList->mMaxSamples = maxu(BufferList->mMaxSamples, buffer->SampleLen);
@@ -3377,7 +3377,7 @@ START_API_FUNC
ALbufferlistitem *next{BufferListStart->mNext.load(std::memory_order_relaxed)};
std::for_each(BufferListStart->begin(), BufferListStart->end(),
[](ALbuffer *buffer) -> void
- { if(buffer) DecrementRef(&buffer->ref); });
+ { if(buffer) DecrementRef(buffer->ref); });
al_free(BufferListStart);
BufferListStart = next;
}
@@ -3460,7 +3460,7 @@ START_API_FUNC
else
{
*(buffers++) = buffer->id;
- DecrementRef(&buffer->ref);
+ DecrementRef(buffer->ref);
}
}
if(i < head->mNumBuffers)
@@ -3574,7 +3574,7 @@ ALsource::~ALsource()
ALbufferlistitem *next{BufferList->mNext.load(std::memory_order_relaxed)};
std::for_each(BufferList->begin(), BufferList->end(),
[](ALbuffer *buffer) -> void
- { if(buffer) DecrementRef(&buffer->ref); });
+ { if(buffer) DecrementRef(buffer->ref); });
al_free(BufferList);
BufferList = next;
}
@@ -3584,7 +3584,7 @@ ALsource::~ALsource()
[](ALsource::SendData &send) -> void
{
if(send.Slot)
- DecrementRef(&send.Slot->ref);
+ DecrementRef(send.Slot->ref);
send.Slot = nullptr;
}
);