From ec2927cd32a1d3a48da81947d611ace6d8361dca Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 27 Nov 2018 21:19:30 -0800 Subject: [PATCH] Small cleanup for ~ALCcontext_struct --- Alc/alc.cpp | 34 +++++++++++++++++----------------- Alc/alu.cpp | 2 +- OpenAL32/Include/alu.h | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Alc/alc.cpp b/Alc/alc.cpp index 59ff2306..3d636354 100644 --- a/Alc/alc.cpp +++ b/Alc/alc.cpp @@ -2558,26 +2558,23 @@ ALCcontext_struct::~ALCcontext_struct() { TRACE("%p\n", this); - struct ALcontextProps *cprops{Update.load(std::memory_order_relaxed)}; + ALcontextProps *cprops{Update.exchange(nullptr, std::memory_order_relaxed)}; if(cprops) { TRACE("Freed unapplied context update %p\n", cprops); al_free(cprops); } size_t count{0}; - cprops = FreeContextProps.load(std::memory_order_acquire); + cprops = FreeContextProps.exchange(nullptr, std::memory_order_acquire); while(cprops) { - struct ALcontextProps *next{cprops->next.load(std::memory_order_relaxed)}; + ALcontextProps *next{cprops->next.load(std::memory_order_relaxed)}; al_free(cprops); cprops = next; ++count; } TRACE("Freed " SZFMT " context property object%s\n", count, (count==1)?"":"s"); - al_free(ActiveAuxSlots.exchange(nullptr, std::memory_order_relaxed)); - DefaultSlot = nullptr; - count = 0; for(auto &sublist : SourceList) count += POPCNT64(~sublist.FreeMask); @@ -2587,10 +2584,10 @@ ALCcontext_struct::~ALCcontext_struct() NumSources = 0; count = 0; - struct ALeffectslotProps *eprops{FreeEffectslotProps.load(std::memory_order_acquire)}; + ALeffectslotProps *eprops{FreeEffectslotProps.exchange(nullptr, std::memory_order_acquire)}; while(eprops) { - struct ALeffectslotProps *next{eprops->next.load(std::memory_order_relaxed)}; + ALeffectslotProps *next{eprops->next.load(std::memory_order_relaxed)}; if(eprops->State) eprops->State->DecRef(); al_free(eprops); eprops = next; @@ -2598,18 +2595,21 @@ ALCcontext_struct::~ALCcontext_struct() } TRACE("Freed " SZFMT " AuxiliaryEffectSlot property object%s\n", count, (count==1)?"":"s"); - count = 0; - for(auto &slot : EffectSlotList) - count += slot ? 1 : 0; + al_free(ActiveAuxSlots.exchange(nullptr, std::memory_order_relaxed)); + DefaultSlot = nullptr; + + count = std::count_if(EffectSlotList.cbegin(), EffectSlotList.cend(), + [](const ALeffectslotPtr &slot) noexcept -> bool { return slot != nullptr; } + ); if(count > 0) WARN(SZFMT " AuxiliaryEffectSlot%s not deleted\n", count, (count==1)?"":"s"); EffectSlotList.clear(); count = 0; - struct ALvoiceProps *vprops{FreeVoiceProps.load(std::memory_order_acquire)}; + ALvoiceProps *vprops{FreeVoiceProps.exchange(nullptr, std::memory_order_acquire)}; while(vprops) { - struct ALvoiceProps *next{vprops->next.load(std::memory_order_relaxed)}; + ALvoiceProps *next{vprops->next.load(std::memory_order_relaxed)}; al_free(vprops); vprops = next; ++count; @@ -2617,24 +2617,24 @@ ALCcontext_struct::~ALCcontext_struct() TRACE("Freed " SZFMT " voice property object%s\n", count, (count==1)?"":"s"); std::for_each(Voices, Voices + VoiceCount.load(std::memory_order_relaxed), - [](ALvoice *voice) -> void { DeinitVoice(voice); } + [](ALvoice *voice) noexcept -> void { DeinitVoice(voice); } ); al_free(Voices); Voices = nullptr; VoiceCount.store(0, std::memory_order_relaxed); MaxVoices = 0; - struct ALlistenerProps *lprops{Listener.Update.load(std::memory_order_relaxed)}; + ALlistenerProps *lprops{Listener.Update.exchange(nullptr, std::memory_order_relaxed)}; if(lprops) { TRACE("Freed unapplied listener update %p\n", lprops); al_free(lprops); } count = 0; - lprops = FreeListenerProps.load(std::memory_order_acquire); + lprops = FreeListenerProps.exchange(nullptr, std::memory_order_acquire); while(lprops) { - struct ALlistenerProps *next{lprops->next.load(std::memory_order_relaxed)}; + ALlistenerProps *next{lprops->next.load(std::memory_order_relaxed)}; al_free(lprops); lprops = next; ++count; diff --git a/Alc/alu.cpp b/Alc/alu.cpp index c7ed0878..edf3249d 100644 --- a/Alc/alu.cpp +++ b/Alc/alu.cpp @@ -99,7 +99,7 @@ void aluInit(void) } -void DeinitVoice(ALvoice *voice) +void DeinitVoice(ALvoice *voice) noexcept { al_free(voice->Update.exchange(nullptr)); } diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index d51000c8..68f539f3 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -264,7 +264,7 @@ typedef struct ALvoice { } Send[]; } ALvoice; -void DeinitVoice(ALvoice *voice); +void DeinitVoice(ALvoice *voice) noexcept; typedef void (*MixerFunc)(const ALfloat *data, ALsizei OutChans, -- 2.11.4.GIT