From 9efce111c916f77ffcb86b50c03a3399f51323e5 Mon Sep 17 00:00:00 2001 From: John Lorentzson Date: Thu, 24 Apr 2025 22:24:11 +0200 Subject: [PATCH] Implement audio backend mutexes This is apparently necessary, and I thought it was leading to the main game thread freezing, but after implementing and testing, that does not appear to be the case. Still, implementing these is correct, so it's best to have it done anyway. --- src/Backends/Audio/SoftwareMixer/Solaris.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Backends/Audio/SoftwareMixer/Solaris.cpp b/src/Backends/Audio/SoftwareMixer/Solaris.cpp index 02e014a4..23f47d39 100644 --- a/src/Backends/Audio/SoftwareMixer/Solaris.cpp +++ b/src/Backends/Audio/SoftwareMixer/Solaris.cpp @@ -20,6 +20,9 @@ static const int bufferSize = 300; static const int samplingRate = 8000; +static pthread_mutex_t mixerMutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t organyaMutex = PTHREAD_MUTEX_INITIALIZER; + static int buffersWritten = 0; static int sndfp; static FILE* sndfile; @@ -118,6 +121,9 @@ unsigned long SoftwareMixerBackend_Init(void (*callback)(long *stream, size_t fr audioInfo.play = info; ioctl(sndfp, AUDIO_SETINFO, &audioInfo); + pthread_mutex_init(&mixerMutex, NULL); + pthread_mutex_init(&organyaMutex, NULL); + pthread_t thread; pthread_attr_t thread_attr; pthread_attr_init(&thread_attr); @@ -136,13 +142,17 @@ bool SoftwareMixerBackend_Start(void) { } void SoftwareMixerBackend_LockMixerMutex(void) { + pthread_mutex_lock(&mixerMutex); } void SoftwareMixerBackend_UnlockMixerMutex(void) { + pthread_mutex_unlock(&mixerMutex); } void SoftwareMixerBackend_LockOrganyaMutex(void) { + pthread_mutex_lock(&organyaMutex); } void SoftwareMixerBackend_UnlockOrganyaMutex(void) { + pthread_mutex_unlock(&organyaMutex); }