ref: f78f6b7105f59538822c80f4e7abdff260ba3a31
parent: 1ad6fdf539e5a088eeb3ee0c3322d4af9989ddbf
author: Clownacy <Clownacy@users.noreply.github.com>
date: Fri Apr 17 20:54:24 EDT 2020
Split Organya callback data The function pointer only ever needs to be set once, unlike the timer. This should avoid any scary race-conditions.
--- a/src/Backends/Audio.h
+++ b/src/Backends/Audio.h
@@ -18,4 +18,5 @@
void AudioBackend_SetSoundVolume(AudioBackend_Sound *sound, long volume);
void AudioBackend_SetSoundPan(AudioBackend_Sound *sound, long pan);
-void AudioBackend_SetOrganyaCallback(void (*callback)(void), unsigned int milliseconds);
+void AudioBackend_SetOrganyaCallback(void (*callback)(void));
+void AudioBackend_SetOrganyaTimer(unsigned int milliseconds);
--- a/src/Backends/Audio/WiiU.cpp
+++ b/src/Backends/Audio/WiiU.cpp
@@ -338,11 +338,17 @@
OSUnlockMutex(&sound_list_mutex);
}
-void AudioBackend_SetOrganyaCallback(void (*callback)(void), unsigned int milliseconds)
+void AudioBackend_SetOrganyaCallback(void (*callback)(void))
{
+ // As far as thread-safety goes - this is guarded by
+ // `organya_milliseconds`, which is guarded by `organya_mutex`.
+ organya_callback = callback;
+}
+
+void AudioBackend_SetOrganyaTimer(unsigned int milliseconds)
+{
OSLockMutex(&organya_mutex);
- organya_callback = callback;
organya_milliseconds = milliseconds;
OSUnlockMutex(&organya_mutex);
--- a/src/Organya.cpp
+++ b/src/Organya.cpp
@@ -790,6 +790,8 @@
org_data.InitOrgData();
+ AudioBackend_SetOrganyaCallback(OrganyaCallback);
+
return TRUE;
}
@@ -835,7 +837,7 @@
if (!audio_backend_initialised)
return;
- AudioBackend_SetOrganyaCallback(OrganyaCallback, org_data.info.wait);
+ AudioBackend_SetOrganyaTimer(org_data.info.wait);
}
BOOL ChangeOrganyaVolume(signed int volume)
@@ -855,7 +857,7 @@
if (!audio_backend_initialised)
return;
- AudioBackend_SetOrganyaCallback(NULL, 0);
+ AudioBackend_SetOrganyaTimer(0);
// Stop notes
for (int i = 0; i < MAXMELODY; i++)
@@ -878,7 +880,7 @@
if (!audio_backend_initialised)
return;
- AudioBackend_SetOrganyaCallback(NULL, 0);
+ AudioBackend_SetOrganyaTimer(0);
// Release everything related to org
org_data.ReleaseNote();