ref: 497adce14b3bfb7096ac2694396076e63dfdb28d
parent: 2f8e771333ecdcb9a147bee0ad34c9a3c7563120
author: Clownacy <Clownacy@users.noreply.github.com>
date: Thu Oct 15 10:22:49 EDT 2020
Add mutexes to 3DS audio backend
--- a/src/Backends/Audio/3DS.cpp
+++ b/src/Backends/Audio/3DS.cpp
@@ -35,6 +35,8 @@
static void (*organya_callback)(void);
static unsigned int organya_callback_timer;
+static LightLock organya_mutex;
+
static Thread audio_thread;
static bool audio_thread_die;
@@ -44,17 +46,20 @@
while (!audio_thread_die)
{
- if (organya_callback_timer == 0)
+ LightLock_Lock(&organya_mutex);
+
+ unsigned int sleep_milliseconds = 10;
+
+ if (organya_callback_timer != 0)
{
- // If Organya isn't currently playing, idle for 10ms and check again
- svcSleepThread(10 * 1000000);
- }
- else
- {
organya_callback();
- svcSleepThread(organya_callback_timer * 1000000);
+ sleep_milliseconds = organya_callback_timer;
}
+
+ LightLock_Unlock(&organya_mutex);
+
+ svcSleepThread(sleep_milliseconds * 1000000);
}
}
@@ -93,6 +98,8 @@
ndspSetOutputMode(NDSP_OUTPUT_STEREO);
+ LightLock_Init(&organya_mutex);
+
audio_thread_die = false;
audio_thread = threadCreate(OrganyaThread, NULL, 32 * 1024, 0x18, -1, false);
@@ -255,10 +262,18 @@
void AudioBackend_SetOrganyaCallback(void (*callback)(void))
{
+ LightLock_Lock(&organya_mutex);
+
organya_callback = callback;
+
+ LightLock_Unlock(&organya_mutex);
}
void AudioBackend_SetOrganyaTimer(unsigned int milliseconds)
{
+ LightLock_Lock(&organya_mutex);
+
organya_callback_timer = milliseconds;
+
+ LightLock_Unlock(&organya_mutex);
}