diff options
author | Chris Robinson <[email protected]> | 2019-09-04 23:04:55 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-09-04 23:04:55 -0700 |
commit | ef2769af03825f278b855858681e4cbe55c0734b (patch) | |
tree | 527d0ffb2be392ce90824cacfb3466ca1d409793 /alc | |
parent | c47a6d2279b80031db9b012713c27885b2d14047 (diff) |
Use a normal vector for the voices array
Diffstat (limited to 'alc')
-rw-r--r-- | alc/alc.cpp | 50 | ||||
-rw-r--r-- | alc/alcontext.h | 5 | ||||
-rw-r--r-- | alc/alu.cpp | 7 | ||||
-rw-r--r-- | alc/alu.h | 1 |
4 files changed, 9 insertions, 54 deletions
diff --git a/alc/alc.cpp b/alc/alc.cpp index 7964a2b3..81afaeb0 100644 --- a/alc/alc.cpp +++ b/alc/alc.cpp @@ -2182,8 +2182,6 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) vprops = next; } - auto voices = context->mVoices.get(); - auto voices_end = voices->begin() + context->mVoiceCount.load(std::memory_order_relaxed); if(device->NumAuxSends < old_sends) { const ALsizei num_sends{device->NumAuxSends}; @@ -2201,7 +2199,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) }; std::for_each(voice.mChans.begin(), voice.mChans.end(), clear_chan_sends); }; - std::for_each(voices->begin(), voices_end, clear_sends); + std::for_each(context->mVoices.begin(), context->mVoices.end(), clear_sends); } auto reset_voice = [device](ALvoice &voice) -> void { @@ -2225,7 +2223,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList) init_nfc); } }; - std::for_each(voices->begin(), voices_end, reset_voice); + std::for_each(context->mVoices.begin(), context->mVoices.end(), reset_voice); srclock.unlock(); context->mPropsClean.test_and_set(std::memory_order_release); @@ -2378,8 +2376,7 @@ ALCcontext::~ALCcontext() } TRACE("Freed %zu voice property object%s\n", count, (count==1)?"":"s"); - mVoices = nullptr; - mVoiceCount.store(0, std::memory_order_relaxed); + mVoices.clear(); ALlistenerProps *lprops{mListener.Params.Update.exchange(nullptr, std::memory_order_relaxed)}; if(lprops) @@ -2459,7 +2456,8 @@ void ALCcontext::init() StartEventThrd(this); - allocVoices(256); + mVoices.reserve(256); + mVoices.resize(64); } bool ALCcontext::deinit() @@ -2548,44 +2546,6 @@ ContextRef GetContextRef(void) } -void ALCcontext::allocVoices(size_t num_voices) -{ - const ALsizei num_sends{mDevice->NumAuxSends}; - - if(mVoices && num_voices == mVoices->size()) - return; - - using ALvoiceArray = al::FlexArray<ALvoice>; - std::unique_ptr<ALvoiceArray> voices{ALvoiceArray::Create(num_voices)}; - - const size_t v_count{minz(mVoiceCount.load(std::memory_order_relaxed), num_voices)}; - if(mVoices) - { - /* Copy the old voice data to the new storage. */ - auto viter = std::move(mVoices->begin(), mVoices->begin()+v_count, voices->begin()); - - /* Clear extraneous property set sends. */ - auto clear_sends = [num_sends](ALvoice &voice) -> void - { - std::fill(std::begin(voice.mProps.Send)+num_sends, std::end(voice.mProps.Send), - ALvoiceProps::SendData{}); - - std::fill(voice.mSend.begin()+num_sends, voice.mSend.end(), ALvoice::SendData{}); - auto clear_chan_sends = [num_sends](ALvoice::ChannelData &chandata) -> void - { - std::fill(chandata.mWetParams.begin()+num_sends, chandata.mWetParams.end(), - SendParams{}); - }; - std::for_each(voice.mChans.begin(), voice.mChans.end(), clear_chan_sends); - }; - std::for_each(voices->begin(), viter, clear_sends); - } - - mVoices = std::move(voices); - mVoiceCount.store(static_cast<ALuint>(v_count), std::memory_order_relaxed); -} - - /************************************************ * Standard ALC functions ************************************************/ diff --git a/alc/alcontext.h b/alc/alcontext.h index c91d0a21..dd622654 100644 --- a/alc/alcontext.h +++ b/alc/alcontext.h @@ -127,8 +127,7 @@ struct ALCcontext : public al::intrusive_ref<ALCcontext> { std::atomic<ALvoiceProps*> mFreeVoiceProps{nullptr}; std::atomic<ALeffectslotProps*> mFreeEffectslotProps{nullptr}; - std::unique_ptr<al::FlexArray<ALvoice>> mVoices{nullptr}; - std::atomic<ALuint> mVoiceCount{0u}; + al::vector<ALvoice> mVoices; using ALeffectslotArray = al::FlexArray<ALeffectslot*>; std::atomic<ALeffectslotArray*> mActiveAuxSlots{nullptr}; @@ -163,8 +162,6 @@ struct ALCcontext : public al::intrusive_ref<ALCcontext> { */ bool deinit(); - void allocVoices(size_t num_voices); - /** * Defers/suspends updates for the given context's listener and sources. * This does *NOT* stop mixing, but rather prevents certain property diff --git a/alc/alu.cpp b/alc/alu.cpp index 861929ef..e58ff3b4 100644 --- a/alc/alu.cpp +++ b/alc/alu.cpp @@ -1348,8 +1348,7 @@ void ProcessContext(ALCcontext *ctx, const ALuint SamplesToDo) ASSUME(SamplesToDo > 0); const ALeffectslotArray &auxslots = *ctx->mActiveAuxSlots.load(std::memory_order_acquire); - const al::span<ALvoice> voices{ctx->mVoices->data(), - ctx->mVoiceCount.load(std::memory_order_acquire)}; + const al::span<ALvoice> voices{ctx->mVoices.data(), ctx->mVoices.size()}; /* Process pending propery updates for objects on the context. */ ProcessParamUpdates(ctx, auxslots, voices); @@ -1755,9 +1754,7 @@ void aluHandleDisconnect(ALCdevice *device, const char *msg, ...) voice.mSourceID.store(0u, std::memory_order_relaxed); voice.mPlayState.store(ALvoice::Stopped, std::memory_order_release); }; - std::for_each(ctx->mVoices->begin(), - ctx->mVoices->begin() + ctx->mVoiceCount.load(std::memory_order_acquire), - stop_voice); + std::for_each(ctx->mVoices.begin(), ctx->mVoices.end(), stop_voice); } IncrementRef(device->MixCount); } @@ -269,6 +269,7 @@ struct ALvoice { ALvoice() = default; ALvoice(const ALvoice&) = delete; + ALvoice(ALvoice&& rhs) noexcept { *this = std::move(rhs); } ~ALvoice() { delete mUpdate.exchange(nullptr, std::memory_order_acq_rel); } ALvoice& operator=(const ALvoice&) = delete; ALvoice& operator=(ALvoice&& rhs) noexcept |