mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-02-01 01:03:11 +00:00
Use HAVE_THREADS around the mutex
This commit is contained in:
parent
0c8f9663f2
commit
a088113f4c
@ -24,9 +24,12 @@
|
||||
#include <audio/audio_resampler.h>
|
||||
|
||||
#include <formats/rwav.h>
|
||||
#include <rthreads/rthreads.h>
|
||||
#include <memalign.h>
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
#include <rthreads/rthreads.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
@ -105,7 +108,10 @@ struct audio_mixer_voice
|
||||
|
||||
static struct audio_mixer_voice s_voices[AUDIO_MIXER_MAX_VOICES];
|
||||
static unsigned s_rate = 0;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
static slock_t* s_locker = NULL;
|
||||
#endif
|
||||
|
||||
static bool wav2float(const rwav_t* wav, float** pcm, size_t samples_out)
|
||||
{
|
||||
@ -228,16 +234,20 @@ void audio_mixer_init(unsigned rate)
|
||||
for (i = 0; i < AUDIO_MIXER_MAX_VOICES; i++)
|
||||
s_voices[i].type = AUDIO_MIXER_TYPE_NONE;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
s_locker = slock_new();
|
||||
#endif
|
||||
}
|
||||
|
||||
void audio_mixer_done(void)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
/* Dont call audio mixer functions after this point */
|
||||
slock_free(s_locker);
|
||||
s_locker = NULL;
|
||||
#endif
|
||||
|
||||
for (i = 0; i < AUDIO_MIXER_MAX_VOICES; i++)
|
||||
s_voices[i].type = AUDIO_MIXER_TYPE_NONE;
|
||||
@ -417,7 +427,9 @@ audio_mixer_voice_t* audio_mixer_play(audio_mixer_sound_t* sound, bool repeat,
|
||||
if (!sound)
|
||||
return NULL;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
slock_lock(s_locker);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < AUDIO_MIXER_MAX_VOICES; i++, voice++)
|
||||
{
|
||||
@ -441,31 +453,46 @@ audio_mixer_voice_t* audio_mixer_play(audio_mixer_sound_t* sound, bool repeat,
|
||||
break;
|
||||
}
|
||||
|
||||
if (res)
|
||||
{
|
||||
voice->type = sound->type;
|
||||
voice->repeat = repeat;
|
||||
voice->volume = volume;
|
||||
voice->sound = sound;
|
||||
voice->stop_cb = stop_cb;
|
||||
}
|
||||
else
|
||||
voice = NULL;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
slock_unlock(s_locker);
|
||||
|
||||
if (!res)
|
||||
return NULL;
|
||||
|
||||
voice->type = sound->type;
|
||||
voice->repeat = repeat;
|
||||
voice->volume = volume;
|
||||
voice->sound = sound;
|
||||
voice->stop_cb = stop_cb;
|
||||
#endif
|
||||
|
||||
return voice;
|
||||
}
|
||||
|
||||
void audio_mixer_stop(audio_mixer_voice_t* voice)
|
||||
{
|
||||
audio_mixer_stop_cb_t stop_cb = NULL;
|
||||
audio_mixer_sound_t* sound = NULL;
|
||||
|
||||
if (voice)
|
||||
{
|
||||
stop_cb = voice->stop_cb;
|
||||
sound = voice->sound;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
slock_lock(s_locker);
|
||||
|
||||
if (voice->stop_cb)
|
||||
voice->stop_cb(voice->sound, AUDIO_MIXER_SOUND_STOPPED);
|
||||
|
||||
#endif
|
||||
|
||||
voice->type = AUDIO_MIXER_TYPE_NONE;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
slock_unlock(s_locker);
|
||||
#endif
|
||||
|
||||
if (stop_cb)
|
||||
stop_cb(sound, AUDIO_MIXER_SOUND_STOPPED);
|
||||
}
|
||||
}
|
||||
|
||||
@ -592,7 +619,9 @@ void audio_mixer_mix(float* buffer, size_t num_frames)
|
||||
float* sample = NULL;
|
||||
audio_mixer_voice_t* voice = s_voices;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
slock_lock(s_locker);
|
||||
#endif
|
||||
|
||||
for (i = 0; i < AUDIO_MIXER_MAX_VOICES; i++, voice++)
|
||||
{
|
||||
@ -613,7 +642,9 @@ void audio_mixer_mix(float* buffer, size_t num_frames)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
slock_unlock(s_locker);
|
||||
#endif
|
||||
|
||||
for (j = 0, sample = buffer; j < num_frames; j++, sample++)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user