aboutsummaryrefslogtreecommitdiffstats
path: root/al
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2023-12-29 03:39:58 -0800
committerChris Robinson <[email protected]>2023-12-29 03:39:58 -0800
commit10ecdff7d1dfcc16bd2a090f089781310ea9a93d (patch)
treeecd0f09a18f211ca7df2120e7c998aa037f5dfe4 /al
parent768781bab97732fbd0d66fa153d4ebc768be1240 (diff)
Handle pointer ownership a bit better
Diffstat (limited to 'al')
-rw-r--r--al/auxeffectslot.cpp30
-rw-r--r--al/buffer.cpp10
-rw-r--r--al/effect.cpp10
-rw-r--r--al/filter.cpp10
-rw-r--r--al/source.cpp15
5 files changed, 37 insertions, 38 deletions
diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp
index ea41a842..695c5788 100644
--- a/al/auxeffectslot.cpp
+++ b/al/auxeffectslot.cpp
@@ -96,7 +96,7 @@ inline ALeffectslot *LookupEffectSlot(ALCcontext *context, ALuint id) noexcept
EffectSlotSubList &sublist{context->mEffectSlotList[lidx]};
if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr;
- return sublist.EffectSlots + slidx;
+ return al::to_address(sublist.EffectSlots->begin() + slidx);
}
inline ALeffect *LookupEffect(ALCdevice *device, ALuint id) noexcept
@@ -109,7 +109,7 @@ inline ALeffect *LookupEffect(ALCdevice *device, ALuint id) noexcept
EffectSubList &sublist = device->EffectList[lidx];
if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr;
- return sublist.Effects + slidx;
+ return al::to_address(sublist.Effects->begin() + slidx);
}
inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id) noexcept
@@ -122,7 +122,7 @@ inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id) noexcept
BufferSubList &sublist = device->BufferList[lidx];
if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr;
- return sublist.Buffers + slidx;
+ return al::to_address(sublist.Buffers->begin() + slidx);
}
@@ -246,8 +246,8 @@ bool EnsureEffectSlots(ALCcontext *context, size_t needed)
context->mEffectSlotList.emplace_back();
auto sublist = context->mEffectSlotList.end() - 1;
sublist->FreeMask = ~0_u64;
- sublist->EffectSlots = static_cast<gsl::owner<ALeffectslot*>>(
- al_calloc(alignof(ALeffectslot), sizeof(ALeffectslot)*64));
+ sublist->EffectSlots = static_cast<gsl::owner<std::array<ALeffectslot,64>*>>(
+ al_calloc(alignof(ALeffectslot), sizeof(*sublist->EffectSlots)));
if(!sublist->EffectSlots) UNLIKELY
{
context->mEffectSlotList.pop_back();
@@ -267,7 +267,8 @@ ALeffectslot *AllocEffectSlot(ALCcontext *context)
auto slidx = static_cast<ALuint>(al::countr_zero(sublist->FreeMask));
ASSUME(slidx < 64);
- ALeffectslot *slot{al::construct_at(sublist->EffectSlots + slidx, context)};
+ ALeffectslot *slot{al::construct_at(al::to_address(sublist->EffectSlots->begin() + slidx),
+ context)};
aluInitEffectPanning(slot->mSlot, context);
/* Add 1 to avoid ID 0. */
@@ -875,12 +876,9 @@ ALeffectslot::~ALeffectslot()
DecrementRef(Buffer->ref);
Buffer = nullptr;
- if(EffectSlotProps *props{mSlot->Update.exchange(nullptr)})
- {
+ if(std::unique_ptr<EffectSlotProps> props{mSlot->Update.exchange(nullptr)})
TRACE("Freed unapplied AuxiliaryEffectSlot update %p\n",
- decltype(std::declval<void*>()){props});
- delete props;
- }
+ decltype(std::declval<void*>()){props.get()});
mSlot->mEffectState = nullptr;
mSlot->InUse = false;
@@ -983,12 +981,12 @@ void UpdateAllEffectSlotProps(ALCcontext *context)
uint64_t usemask{~sublist.FreeMask};
while(usemask)
{
- const int idx{al::countr_zero(usemask)};
+ const auto idx = static_cast<uint>(al::countr_zero(usemask));
usemask &= ~(1_u64 << idx);
- ALeffectslot *slot{sublist.EffectSlots + idx};
+ auto &slot = (*sublist.EffectSlots)[idx];
- if(slot->mState != SlotState::Stopped && std::exchange(slot->mPropsDirty, false))
- slot->updateProps(context);
+ if(slot.mState != SlotState::Stopped && std::exchange(slot.mPropsDirty, false))
+ slot.updateProps(context);
}
}
}
@@ -1002,7 +1000,7 @@ EffectSlotSubList::~EffectSlotSubList()
while(usemask)
{
const int idx{al::countr_zero(usemask)};
- std::destroy_at(EffectSlots+idx);
+ std::destroy_at(al::to_address(EffectSlots->begin() + idx));
usemask &= ~(1_u64 << idx);
}
FreeMask = ~usemask;
diff --git a/al/buffer.cpp b/al/buffer.cpp
index c0f3f348..46ef8ece 100644
--- a/al/buffer.cpp
+++ b/al/buffer.cpp
@@ -186,8 +186,8 @@ bool EnsureBuffers(ALCdevice *device, size_t needed)
device->BufferList.emplace_back();
auto sublist = device->BufferList.end() - 1;
sublist->FreeMask = ~0_u64;
- sublist->Buffers = static_cast<gsl::owner<ALbuffer*>>(al_calloc(alignof(ALbuffer),
- sizeof(ALbuffer)*64));
+ sublist->Buffers = static_cast<gsl::owner<std::array<ALbuffer,64>*>>(al_calloc(
+ alignof(ALbuffer), sizeof(*sublist->Buffers)));
if(!sublist->Buffers) UNLIKELY
{
device->BufferList.pop_back();
@@ -207,7 +207,7 @@ ALbuffer *AllocBuffer(ALCdevice *device)
auto slidx = static_cast<ALuint>(al::countr_zero(sublist->FreeMask));
ASSUME(slidx < 64);
- ALbuffer *buffer{al::construct_at(sublist->Buffers + slidx)};
+ ALbuffer *buffer{al::construct_at(al::to_address(sublist->Buffers->begin() + slidx))};
/* Add 1 to avoid buffer ID 0. */
buffer->id = ((lidx<<6) | slidx) + 1;
@@ -244,7 +244,7 @@ inline ALbuffer *LookupBuffer(ALCdevice *device, ALuint id)
BufferSubList &sublist = device->BufferList[lidx];
if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr;
- return sublist.Buffers + slidx;
+ return al::to_address(sublist.Buffers->begin() + slidx);
}
@@ -1486,7 +1486,7 @@ BufferSubList::~BufferSubList()
while(usemask)
{
const int idx{al::countr_zero(usemask)};
- std::destroy_at(Buffers+idx);
+ std::destroy_at(al::to_address(Buffers->begin() + idx));
usemask &= ~(1_u64 << idx);
}
FreeMask = ~usemask;
diff --git a/al/effect.cpp b/al/effect.cpp
index c2a2d1b1..1024de80 100644
--- a/al/effect.cpp
+++ b/al/effect.cpp
@@ -134,8 +134,8 @@ bool EnsureEffects(ALCdevice *device, size_t needed)
device->EffectList.emplace_back();
auto sublist = device->EffectList.end() - 1;
sublist->FreeMask = ~0_u64;
- sublist->Effects = static_cast<gsl::owner<ALeffect*>>(al_calloc(alignof(ALeffect),
- sizeof(ALeffect)*64));
+ sublist->Effects = static_cast<gsl::owner<std::array<ALeffect,64>*>>(al_calloc(
+ alignof(ALeffect), sizeof(*sublist->Effects)));
if(!sublist->Effects) UNLIKELY
{
device->EffectList.pop_back();
@@ -155,7 +155,7 @@ ALeffect *AllocEffect(ALCdevice *device)
auto slidx = static_cast<ALuint>(al::countr_zero(sublist->FreeMask));
ASSUME(slidx < 64);
- ALeffect *effect{al::construct_at(sublist->Effects + slidx)};
+ ALeffect *effect{al::construct_at(al::to_address(sublist->Effects->begin() + slidx))};
InitEffectParams(effect, AL_EFFECT_NULL);
/* Add 1 to avoid effect ID 0. */
@@ -189,7 +189,7 @@ inline ALeffect *LookupEffect(ALCdevice *device, ALuint id)
EffectSubList &sublist = device->EffectList[lidx];
if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr;
- return sublist.Effects + slidx;
+ return al::to_address(sublist.Effects->begin() + slidx);
}
} // namespace
@@ -568,7 +568,7 @@ EffectSubList::~EffectSubList()
while(usemask)
{
const int idx{al::countr_zero(usemask)};
- std::destroy_at(Effects+idx);
+ std::destroy_at(al::to_address(Effects->begin()+idx));
usemask &= ~(1_u64 << idx);
}
FreeMask = ~usemask;
diff --git a/al/filter.cpp b/al/filter.cpp
index ce37b0aa..4a24a38f 100644
--- a/al/filter.cpp
+++ b/al/filter.cpp
@@ -129,8 +129,8 @@ bool EnsureFilters(ALCdevice *device, size_t needed)
device->FilterList.emplace_back();
auto sublist = device->FilterList.end() - 1;
sublist->FreeMask = ~0_u64;
- sublist->Filters = static_cast<gsl::owner<ALfilter*>>(al_calloc(alignof(ALfilter),
- sizeof(ALfilter)*64));
+ sublist->Filters = static_cast<gsl::owner<std::array<ALfilter,64>*>>(al_calloc(
+ alignof(ALfilter), sizeof(*sublist->Filters)));
if(!sublist->Filters) UNLIKELY
{
device->FilterList.pop_back();
@@ -151,7 +151,7 @@ ALfilter *AllocFilter(ALCdevice *device)
auto slidx = static_cast<ALuint>(al::countr_zero(sublist->FreeMask));
ASSUME(slidx < 64);
- ALfilter *filter{al::construct_at(sublist->Filters + slidx)};
+ ALfilter *filter{al::construct_at(al::to_address(sublist->Filters->begin() + slidx))};
InitFilterParams(filter, AL_FILTER_NULL);
/* Add 1 to avoid filter ID 0. */
@@ -186,7 +186,7 @@ inline ALfilter *LookupFilter(ALCdevice *device, ALuint id)
FilterSubList &sublist = device->FilterList[lidx];
if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr;
- return sublist.Filters + slidx;
+ return al::to_address(sublist.Filters->begin() + slidx);
}
} // namespace
@@ -696,7 +696,7 @@ FilterSubList::~FilterSubList()
while(usemask)
{
const int idx{al::countr_zero(usemask)};
- std::destroy_at(Filters+idx);
+ std::destroy_at(al::to_address(Filters->begin() + idx));
usemask &= ~(1_u64 << idx);
}
FreeMask = ~usemask;
diff --git a/al/source.cpp b/al/source.cpp
index bf96a769..1ac3bf28 100644
--- a/al/source.cpp
+++ b/al/source.cpp
@@ -729,7 +729,8 @@ bool EnsureSources(ALCcontext *context, size_t needed)
context->mSourceList.emplace_back();
auto sublist = context->mSourceList.end() - 1;
sublist->FreeMask = ~0_u64;
- sublist->Sources = static_cast<ALsource*>(al_calloc(alignof(ALsource), sizeof(ALsource)*64));
+ sublist->Sources = static_cast<gsl::owner<std::array<ALsource,64>*>>(al_calloc(
+ alignof(ALsource), sizeof(*sublist->Sources)));
if(!sublist->Sources) UNLIKELY
{
context->mSourceList.pop_back();
@@ -749,7 +750,7 @@ ALsource *AllocSource(ALCcontext *context)
auto slidx = static_cast<ALuint>(al::countr_zero(sublist->FreeMask));
ASSUME(slidx < 64);
- ALsource *source{al::construct_at(sublist->Sources + slidx)};
+ ALsource *source{al::construct_at(al::to_address(sublist->Sources->begin() + slidx))};
/* Add 1 to avoid source ID 0. */
source->id = ((lidx<<6) | slidx) + 1;
@@ -797,7 +798,7 @@ inline ALsource *LookupSource(ALCcontext *context, ALuint id) noexcept
SourceSubList &sublist{context->mSourceList[lidx]};
if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr;
- return sublist.Sources + slidx;
+ return al::to_address(sublist.Sources->begin() + slidx);
}
auto LookupBuffer = [](ALCdevice *device, auto id) noexcept -> ALbuffer*
@@ -810,7 +811,7 @@ auto LookupBuffer = [](ALCdevice *device, auto id) noexcept -> ALbuffer*
BufferSubList &sublist = device->BufferList[static_cast<size_t>(lidx)];
if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr;
- return sublist.Buffers + static_cast<size_t>(slidx);
+ return al::to_address(sublist.Buffers->begin() + static_cast<size_t>(slidx));
};
auto LookupFilter = [](ALCdevice *device, auto id) noexcept -> ALfilter*
@@ -823,7 +824,7 @@ auto LookupFilter = [](ALCdevice *device, auto id) noexcept -> ALfilter*
FilterSubList &sublist = device->FilterList[static_cast<size_t>(lidx)];
if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr;
- return sublist.Filters + static_cast<size_t>(slidx);
+ return al::to_address(sublist.Filters->begin() + static_cast<size_t>(slidx));
};
auto LookupEffectSlot = [](ALCcontext *context, auto id) noexcept -> ALeffectslot*
@@ -836,7 +837,7 @@ auto LookupEffectSlot = [](ALCcontext *context, auto id) noexcept -> ALeffectslo
EffectSlotSubList &sublist{context->mEffectSlotList[static_cast<size_t>(lidx)]};
if(sublist.FreeMask & (1_u64 << slidx)) UNLIKELY
return nullptr;
- return sublist.EffectSlots + static_cast<size_t>(slidx);
+ return al::to_address(sublist.EffectSlots->begin() + static_cast<size_t>(slidx));
};
@@ -3639,7 +3640,7 @@ SourceSubList::~SourceSubList()
{
const int idx{al::countr_zero(usemask)};
usemask &= ~(1_u64 << idx);
- std::destroy_at(Sources+idx);
+ std::destroy_at(al::to_address(Sources->begin() + idx));
}
FreeMask = ~usemask;
al_free(Sources);