Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dosbox-staging/dosbox-staging.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKirk Klobe <kklobe@gmail.com>2022-06-07 03:09:21 +0300
committerKirk Klobe <kklobe@gmail.com>2022-06-07 06:29:04 +0300
commit73c3757eea2c3027ac394d33e3822547c7471757 (patch)
treee2fb745682b8fdd23dc8ca764462deda5b8c72d7
parent57ee00e462ac5c97627425107a3af2b0a03fc169 (diff)
Fix mixer race conditionkk/mixer-sample-rate-atomic
mixer.sample_rate is accessed from the callback thread and should be atomic.
-rw-r--r--src/hardware/mixer.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/hardware/mixer.cpp b/src/hardware/mixer.cpp
index fe76b838e..f6651571a 100644
--- a/src/hardware/mixer.cpp
+++ b/src/hardware/mixer.cpp
@@ -110,7 +110,7 @@ struct mixer_t {
std::atomic<int> tick_add = 0; // samples needed per millisecond tick
int tick_counter = 0;
- int sample_rate = 0; // sample rate negotiated with SDL
+ std::atomic<int> sample_rate = 0; // sample rate negotiated with SDL
uint16_t blocksize = 0; // matches SDL AudioSpec.samples type
SDL_AudioDeviceID sdldevice = 0;
@@ -308,7 +308,7 @@ void MixerChannel::ConfigureResampler()
{
const auto in_rate = zoh_upsampler.enabled ? zoh_upsampler.target_freq
: sample_rate;
- const auto out_rate = mixer.sample_rate;
+ const auto out_rate = mixer.sample_rate.load();
if (in_rate == out_rate) {
resampler.enabled = false;
} else {
@@ -1373,7 +1373,7 @@ void MIXER_Init(Section* sec) {
// Does SDL want a different playback rate?
if (obtained.freq != mixer.sample_rate) {
- LOG_WARNING("MIXER: SDL changed the playback rate from %d to %d Hz", mixer.sample_rate, obtained.freq);
+ LOG_WARNING("MIXER: SDL changed the playback rate from %d to %d Hz", mixer.sample_rate.load(), obtained.freq);
mixer.sample_rate = obtained.freq;
}
@@ -1389,7 +1389,7 @@ void MIXER_Init(Section* sec) {
SDL_PauseAudioDevice(mixer.sdldevice, 0);
LOG_MSG("MIXER: Negotiated %u-channel %u-Hz audio in %u-frame blocks",
- obtained.channels, mixer.sample_rate, mixer.blocksize);
+ obtained.channels, mixer.sample_rate.load(), mixer.blocksize);
}
//1000 = 8 *125