Split Organya callback data
The function pointer only ever needs to be set once, unlike the timer. This should avoid any scary race-conditions.
This commit is contained in:
parent
1ad6fdf539
commit
f78f6b7105
3 changed files with 15 additions and 6 deletions
|
@ -18,4 +18,5 @@ void AudioBackend_SetSoundFrequency(AudioBackend_Sound *sound, unsigned int freq
|
||||||
void AudioBackend_SetSoundVolume(AudioBackend_Sound *sound, long volume);
|
void AudioBackend_SetSoundVolume(AudioBackend_Sound *sound, long volume);
|
||||||
void AudioBackend_SetSoundPan(AudioBackend_Sound *sound, long pan);
|
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);
|
||||||
|
|
|
@ -338,11 +338,17 @@ void AudioBackend_SetSoundPan(AudioBackend_Sound *sound, long pan)
|
||||||
OSUnlockMutex(&sound_list_mutex);
|
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);
|
OSLockMutex(&organya_mutex);
|
||||||
|
|
||||||
organya_callback = callback;
|
|
||||||
organya_milliseconds = milliseconds;
|
organya_milliseconds = milliseconds;
|
||||||
|
|
||||||
OSUnlockMutex(&organya_mutex);
|
OSUnlockMutex(&organya_mutex);
|
||||||
|
|
|
@ -790,6 +790,8 @@ BOOL StartOrganya(const char *path_wave) // The argument is ignored for some rea
|
||||||
|
|
||||||
org_data.InitOrgData();
|
org_data.InitOrgData();
|
||||||
|
|
||||||
|
AudioBackend_SetOrganyaCallback(OrganyaCallback);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -835,7 +837,7 @@ void PlayOrganyaMusic(void)
|
||||||
if (!audio_backend_initialised)
|
if (!audio_backend_initialised)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AudioBackend_SetOrganyaCallback(OrganyaCallback, org_data.info.wait);
|
AudioBackend_SetOrganyaTimer(org_data.info.wait);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL ChangeOrganyaVolume(signed int volume)
|
BOOL ChangeOrganyaVolume(signed int volume)
|
||||||
|
@ -855,7 +857,7 @@ void StopOrganyaMusic(void)
|
||||||
if (!audio_backend_initialised)
|
if (!audio_backend_initialised)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AudioBackend_SetOrganyaCallback(NULL, 0);
|
AudioBackend_SetOrganyaTimer(0);
|
||||||
|
|
||||||
// Stop notes
|
// Stop notes
|
||||||
for (int i = 0; i < MAXMELODY; i++)
|
for (int i = 0; i < MAXMELODY; i++)
|
||||||
|
@ -878,7 +880,7 @@ void EndOrganya(void)
|
||||||
if (!audio_backend_initialised)
|
if (!audio_backend_initialised)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AudioBackend_SetOrganyaCallback(NULL, 0);
|
AudioBackend_SetOrganyaTimer(0);
|
||||||
|
|
||||||
// Release everything related to org
|
// Release everything related to org
|
||||||
org_data.ReleaseNote();
|
org_data.ReleaseNote();
|
||||||
|
|
Loading…
Add table
Reference in a new issue