aboutsummaryrefslogtreecommitdiffstats
path: root/alc/alcontext.h
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-02-20 22:50:37 -0800
committerChris Robinson <[email protected]>2020-02-20 22:50:37 -0800
commitbdb8ef22b02fb278017d95c70d36e6b815533de9 (patch)
tree6d56d19b244a403d2fd9f038984af4c8a51cf09f /alc/alcontext.h
parentacf7f6f74e3b5d133fd121093e8ccf301a8697cd (diff)
Asynchronously stop voices if its source is being deleted
Diffstat (limited to 'alc/alcontext.h')
-rw-r--r--alc/alcontext.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/alc/alcontext.h b/alc/alcontext.h
index ba3942f5..59fda1a7 100644
--- a/alc/alcontext.h
+++ b/alc/alcontext.h
@@ -56,6 +56,17 @@ struct ALcontextProps {
};
+struct VoiceChange {
+ ALvoice *mVoice{nullptr};
+ ALuint mSourceID{0};
+ ALenum mState{0};
+
+ std::atomic<VoiceChange*> mNext{nullptr};
+
+ DEF_NEWDEL(VoiceChange)
+};
+
+
struct SourceSubList {
uint64_t FreeMask{~0_u64};
ALsource *Sources{nullptr}; /* 64 */
@@ -128,6 +139,24 @@ struct ALCcontext : public al::intrusive_ref<ALCcontext> {
std::atomic<ALvoiceProps*> mFreeVoiceProps{nullptr};
std::atomic<ALeffectslotProps*> mFreeEffectslotProps{nullptr};
+ /* Asynchronous voice change actions are processed as a linked list of
+ * VoiceChange objects by the mixer, which is atomically appended to.
+ * However, to avoid allocating each object individually, they're allocated
+ * in clusters that are stored in a vector for easy automatic cleanup.
+ */
+ using VoiceChangeCluster = std::unique_ptr<VoiceChange[]>;
+ al::vector<VoiceChangeCluster> mVoiceChangeCluster;
+
+ /* 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
+ * new ones need to be allocated. The current voice change is the element
+ * last processed, and any after are pending.
+ */
+ VoiceChange *mVoiceChangeTail{};
+ std::atomic<VoiceChange*> mCurrentVoiceChange{};
+
+ void allocVoiceChanges(size_t addcount);
+
al::vector<ALvoice> mVoices;
using ALeffectslotArray = al::FlexArray<ALeffectslot*>;