aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--alc/context.cpp64
-rw-r--r--core/context.cpp70
2 files changed, 70 insertions, 64 deletions
diff --git a/alc/context.cpp b/alc/context.cpp
index 0b6bd022..af78603a 100644
--- a/alc/context.cpp
+++ b/alc/context.cpp
@@ -171,70 +171,6 @@ ContextBase::~ContextBase()
}
}
-void ContextBase::allocVoiceChanges()
-{
- constexpr size_t clustersize{128};
-
- VoiceChangeCluster cluster{std::make_unique<VoiceChange[]>(clustersize)};
- for(size_t i{1};i < clustersize;++i)
- cluster[i-1].mNext.store(std::addressof(cluster[i]), std::memory_order_relaxed);
- cluster[clustersize-1].mNext.store(mVoiceChangeTail, std::memory_order_relaxed);
-
- mVoiceChangeClusters.emplace_back(std::move(cluster));
- mVoiceChangeTail = mVoiceChangeClusters.back().get();
-}
-
-void ContextBase::allocVoiceProps()
-{
- constexpr size_t clustersize{32};
-
- TRACE("Increasing allocated voice properties to %zu\n",
- (mVoicePropClusters.size()+1) * clustersize);
-
- VoicePropsCluster cluster{std::make_unique<VoicePropsItem[]>(clustersize)};
- for(size_t i{1};i < clustersize;++i)
- cluster[i-1].next.store(std::addressof(cluster[i]), std::memory_order_relaxed);
- mVoicePropClusters.emplace_back(std::move(cluster));
-
- VoicePropsItem *oldhead{mFreeVoiceProps.load(std::memory_order_acquire)};
- do {
- mVoicePropClusters.back()[clustersize-1].next.store(oldhead, std::memory_order_relaxed);
- } while(mFreeVoiceProps.compare_exchange_weak(oldhead, mVoicePropClusters.back().get(),
- std::memory_order_acq_rel, std::memory_order_acquire) == false);
-}
-
-void ContextBase::allocVoices(size_t addcount)
-{
- constexpr size_t clustersize{32};
- /* Convert element count to cluster count. */
- addcount = (addcount+(clustersize-1)) / clustersize;
-
- if(addcount >= std::numeric_limits<int>::max()/clustersize - mVoiceClusters.size())
- throw std::runtime_error{"Allocating too many voices"};
- const size_t totalcount{(mVoiceClusters.size()+addcount) * clustersize};
- TRACE("Increasing allocated voices to %zu\n", totalcount);
-
- auto newarray = VoiceArray::Create(totalcount);
- while(addcount)
- {
- mVoiceClusters.emplace_back(std::make_unique<Voice[]>(clustersize));
- --addcount;
- }
-
- auto voice_iter = newarray->begin();
- for(VoiceCluster &cluster : mVoiceClusters)
- {
- for(size_t i{0};i < clustersize;++i)
- *(voice_iter++) = &cluster[i];
- }
-
- if(auto *oldvoices = mVoices.exchange(newarray.release(), std::memory_order_acq_rel))
- {
- mDevice->waitForMix();
- delete oldvoices;
- }
-}
-
ALCcontext::ALCcontext(al::intrusive_ptr<ALCdevice> device)
: ContextBase{device.get()}, mALDevice{std::move(device)}
diff --git a/core/context.cpp b/core/context.cpp
index f1c310aa..c8d9ea93 100644
--- a/core/context.cpp
+++ b/core/context.cpp
@@ -1,5 +1,75 @@
#include "config.h"
+#include <memory>
+
#include "context.h"
+#include "device.h"
+#include "logging.h"
+#include "voice.h"
+#include "voice_change.h"
+
+
+void ContextBase::allocVoiceChanges()
+{
+ constexpr size_t clustersize{128};
+
+ VoiceChangeCluster cluster{std::make_unique<VoiceChange[]>(clustersize)};
+ for(size_t i{1};i < clustersize;++i)
+ cluster[i-1].mNext.store(std::addressof(cluster[i]), std::memory_order_relaxed);
+ cluster[clustersize-1].mNext.store(mVoiceChangeTail, std::memory_order_relaxed);
+
+ mVoiceChangeClusters.emplace_back(std::move(cluster));
+ mVoiceChangeTail = mVoiceChangeClusters.back().get();
+}
+
+void ContextBase::allocVoiceProps()
+{
+ constexpr size_t clustersize{32};
+
+ TRACE("Increasing allocated voice properties to %zu\n",
+ (mVoicePropClusters.size()+1) * clustersize);
+
+ VoicePropsCluster cluster{std::make_unique<VoicePropsItem[]>(clustersize)};
+ for(size_t i{1};i < clustersize;++i)
+ cluster[i-1].next.store(std::addressof(cluster[i]), std::memory_order_relaxed);
+ mVoicePropClusters.emplace_back(std::move(cluster));
+
+ VoicePropsItem *oldhead{mFreeVoiceProps.load(std::memory_order_acquire)};
+ do {
+ mVoicePropClusters.back()[clustersize-1].next.store(oldhead, std::memory_order_relaxed);
+ } while(mFreeVoiceProps.compare_exchange_weak(oldhead, mVoicePropClusters.back().get(),
+ std::memory_order_acq_rel, std::memory_order_acquire) == false);
+}
+
+void ContextBase::allocVoices(size_t addcount)
+{
+ constexpr size_t clustersize{32};
+ /* Convert element count to cluster count. */
+ addcount = (addcount+(clustersize-1)) / clustersize;
+
+ if(addcount >= std::numeric_limits<int>::max()/clustersize - mVoiceClusters.size())
+ throw std::runtime_error{"Allocating too many voices"};
+ const size_t totalcount{(mVoiceClusters.size()+addcount) * clustersize};
+ TRACE("Increasing allocated voices to %zu\n", totalcount);
+
+ auto newarray = VoiceArray::Create(totalcount);
+ while(addcount)
+ {
+ mVoiceClusters.emplace_back(std::make_unique<Voice[]>(clustersize));
+ --addcount;
+ }
+
+ auto voice_iter = newarray->begin();
+ for(VoiceCluster &cluster : mVoiceClusters)
+ {
+ for(size_t i{0};i < clustersize;++i)
+ *(voice_iter++) = &cluster[i];
+ }
+ if(auto *oldvoices = mVoices.exchange(newarray.release(), std::memory_order_acq_rel))
+ {
+ mDevice->waitForMix();
+ delete oldvoices;
+ }
+}