From 70a8cf88041d88c49dcd258587e6b84960752851 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 1 Jan 2024 15:54:30 -0800 Subject: Use an atomic unique_ptr for the device's context array --- alc/context.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'alc/context.cpp') diff --git a/alc/context.cpp b/alc/context.cpp index 0f6dbbae..67f08aee 100644 --- a/alc/context.cpp +++ b/alc/context.cpp @@ -263,12 +263,8 @@ void ALCcontext::deinit() if(auto toremove = static_cast(std::count(oldarray->begin(), oldarray->end(), this))) { using ContextArray = al::FlexArray; - auto alloc_ctx_array = [](const size_t count) -> ContextArray* - { - if(count == 0) return &DeviceBase::sEmptyContextArray; - return ContextArray::Create(count).release(); - }; - auto *newarray = alloc_ctx_array(oldarray->size() - toremove); + const size_t newsize{oldarray->size() - toremove}; + auto newarray = ContextArray::Create(newsize); /* Copy the current/old context handles to the new array, excluding the * given context. @@ -279,14 +275,10 @@ void ALCcontext::deinit() /* Store the new context array in the device. Wait for any current mix * to finish before deleting the old array. */ - mDevice->mContexts.store(newarray); - if(oldarray != &DeviceBase::sEmptyContextArray) - { - std::ignore = mDevice->waitForMix(); - delete oldarray; - } + auto prevarray = mDevice->mContexts.exchange(std::move(newarray)); + std::ignore = mDevice->waitForMix(); - stopPlayback = newarray->empty(); + stopPlayback = (newsize == 0); } else stopPlayback = oldarray->empty(); -- cgit v1.2.3