diff options
author | Chris Robinson <[email protected]> | 2023-12-26 22:37:12 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2023-12-26 22:37:12 -0800 |
commit | 205a73876234c0b1363189306530ada73ece56f2 (patch) | |
tree | 185ccb4d06ba136e4fee84324c6f1102c184734d /al | |
parent | 1fddc044ac765d00e64628e59edcbcd71f0046b1 (diff) |
Try to start being a bit more pointer-owner conscious
Diffstat (limited to 'al')
-rw-r--r-- | al/auxeffectslot.cpp | 25 | ||||
-rw-r--r-- | al/buffer.cpp | 3 | ||||
-rw-r--r-- | al/effect.cpp | 3 | ||||
-rw-r--r-- | al/filter.cpp | 3 |
4 files changed, 16 insertions, 18 deletions
diff --git a/al/auxeffectslot.cpp b/al/auxeffectslot.cpp index 408b742b..ea41a842 100644 --- a/al/auxeffectslot.cpp +++ b/al/auxeffectslot.cpp @@ -155,19 +155,17 @@ void AddActiveEffectSlots(const al::span<ALeffectslot*> auxslots, ALCcontext *co */ if(newcount < newarray->size()) UNLIKELY { - curarray = newarray; + std::unique_ptr<EffectSlotArray> oldarray{newarray}; newarray = EffectSlot::CreatePtrArray(newcount); - std::copy_n(curarray->begin(), newcount, newarray->begin()); - delete curarray; - curarray = nullptr; + std::copy_n(oldarray->begin(), newcount, newarray->begin()); } std::uninitialized_fill_n(newarray->end(), newcount, nullptr); - curarray = context->mActiveAuxSlots.exchange(newarray, std::memory_order_acq_rel); + std::unique_ptr<EffectSlotArray> oldarray{context->mActiveAuxSlots.exchange(newarray, + std::memory_order_acq_rel)}; std::ignore = context->mDevice->waitForMix(); - std::destroy_n(curarray->end(), curarray->size()); - delete curarray; + std::destroy_n(oldarray->end(), oldarray->size()); } void RemoveActiveEffectSlots(const al::span<ALeffectslot*> auxslots, ALCcontext *context) @@ -193,20 +191,17 @@ void RemoveActiveEffectSlots(const al::span<ALeffectslot*> auxslots, ALCcontext auto newsize = static_cast<size_t>(std::distance(newarray->begin(), new_end)); if(newsize != newarray->size()) LIKELY { - curarray = newarray; + std::unique_ptr<EffectSlotArray> oldarray{newarray}; newarray = EffectSlot::CreatePtrArray(newsize); - std::copy_n(curarray->begin(), newsize, newarray->begin()); - - delete curarray; - curarray = nullptr; + std::copy_n(oldarray->begin(), newsize, newarray->begin()); } std::uninitialized_fill_n(newarray->end(), newsize, nullptr); - curarray = context->mActiveAuxSlots.exchange(newarray, std::memory_order_acq_rel); + std::unique_ptr<EffectSlotArray> oldarray{context->mActiveAuxSlots.exchange(newarray, + std::memory_order_acq_rel)}; std::ignore = context->mDevice->waitForMix(); std::destroy_n(curarray->end(), curarray->size()); - delete curarray; } @@ -251,7 +246,7 @@ 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<ALeffectslot*>( + sublist->EffectSlots = static_cast<gsl::owner<ALeffectslot*>>( al_calloc(alignof(ALeffectslot), sizeof(ALeffectslot)*64)); if(!sublist->EffectSlots) UNLIKELY { diff --git a/al/buffer.cpp b/al/buffer.cpp index e577e17a..c0f3f348 100644 --- a/al/buffer.cpp +++ b/al/buffer.cpp @@ -186,7 +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<ALbuffer*>(al_calloc(alignof(ALbuffer), sizeof(ALbuffer)*64)); + sublist->Buffers = static_cast<gsl::owner<ALbuffer*>>(al_calloc(alignof(ALbuffer), + sizeof(ALbuffer)*64)); if(!sublist->Buffers) UNLIKELY { device->BufferList.pop_back(); diff --git a/al/effect.cpp b/al/effect.cpp index c33faa2c..c2a2d1b1 100644 --- a/al/effect.cpp +++ b/al/effect.cpp @@ -134,7 +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<ALeffect*>(al_calloc(alignof(ALeffect), sizeof(ALeffect)*64)); + sublist->Effects = static_cast<gsl::owner<ALeffect*>>(al_calloc(alignof(ALeffect), + sizeof(ALeffect)*64)); if(!sublist->Effects) UNLIKELY { device->EffectList.pop_back(); diff --git a/al/filter.cpp b/al/filter.cpp index 9c8e4c62..ce37b0aa 100644 --- a/al/filter.cpp +++ b/al/filter.cpp @@ -129,7 +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<ALfilter*>(al_calloc(alignof(ALfilter), sizeof(ALfilter)*64)); + sublist->Filters = static_cast<gsl::owner<ALfilter*>>(al_calloc(alignof(ALfilter), + sizeof(ALfilter)*64)); if(!sublist->Filters) UNLIKELY { device->FilterList.pop_back(); |