From f8604758bc7cc43efa52a305a578ee9cf474f0d6 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 3 Jan 2024 13:16:09 -0800 Subject: Allocate effect slot property updates in clusters --- core/context.cpp | 29 ++++++++++++++++++++--------- core/context.h | 7 +++++-- 2 files changed, 25 insertions(+), 11 deletions(-) (limited to 'core') diff --git a/core/context.cpp b/core/context.cpp index cb00ae70..46f703a9 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -40,15 +40,6 @@ ContextBase::~ContextBase() } TRACE("Freed %zu context property object%s\n", count, (count==1)?"":"s"); - count = 0; - EffectSlotProps *eprops{mFreeEffectslotProps.exchange(nullptr, std::memory_order_acquire)}; - while(std::unique_ptr old{eprops}) - { - eprops = old->next.load(std::memory_order_relaxed); - ++count; - } - TRACE("Freed %zu AuxiliaryEffectSlot property object%s\n", count, (count==1)?"":"s"); - if(std::unique_ptr curarray{mActiveAuxSlots.exchange(nullptr, std::memory_order_relaxed)}) std::destroy_n(curarray->end(), curarray->size()); @@ -147,6 +138,26 @@ void ContextBase::allocVoices(size_t addcount) } +void ContextBase::allocEffectSlotProps() +{ + static constexpr size_t clustersize{std::tuple_size_v}; + + TRACE("Increasing allocated effect slot properties to %zu\n", + (mEffectSlotPropClusters.size()+1) * clustersize); + + auto clusterptr = std::make_unique(); + auto cluster = al::span{*clusterptr}; + for(size_t i{1};i < clustersize;++i) + cluster[i-1].next.store(std::addressof(cluster[i]), std::memory_order_relaxed); + auto *newcluster = mEffectSlotPropClusters.emplace_back(std::move(clusterptr)).get(); + + EffectSlotProps *oldhead{mFreeEffectSlotProps.load(std::memory_order_acquire)}; + do { + newcluster->back().next.store(oldhead, std::memory_order_relaxed); + } while(mFreeEffectSlotProps.compare_exchange_weak(oldhead, newcluster->data(), + std::memory_order_acq_rel, std::memory_order_acquire) == false); +} + EffectSlot *ContextBase::getEffectSlot() { for(auto& clusterptr : mEffectSlotClusters) diff --git a/core/context.h b/core/context.h index 6fc1ed5d..16d1b415 100644 --- a/core/context.h +++ b/core/context.h @@ -95,7 +95,7 @@ struct ContextBase { */ std::atomic mFreeContextProps{nullptr}; std::atomic mFreeVoiceProps{nullptr}; - std::atomic mFreeEffectslotProps{nullptr}; + std::atomic mFreeEffectSlotProps{nullptr}; /* The voice change tail is the beginning of the "free" elements, up to and * *excluding* the current. If tail==current, there's no free elements and @@ -107,7 +107,7 @@ struct ContextBase { void allocVoiceChanges(); void allocVoiceProps(); - + void allocEffectSlotProps(); ContextParams mParams; @@ -157,6 +157,9 @@ struct ContextBase { using EffectSlotCluster = std::unique_ptr>; std::vector mEffectSlotClusters; + using EffectSlotPropsCluster = std::unique_ptr>; + std::vector mEffectSlotPropClusters; + ContextBase(DeviceBase *device); ContextBase(const ContextBase&) = delete; -- cgit v1.2.3