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.
This commit is contained in:
John Lorentzson 2025-04-24 22:24:11 +02:00
parent c841d343a3
commit 9efce111c9

View file

@ -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);
}