summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2020-10-11 18:01:48 -0700
committerMichael Pavone <pavone@retrodev.com>2020-10-11 18:01:48 -0700
commit2ecfb587c3ebb613ba8743857caa60ffe4b261fa (patch)
treef178c33ff8fbe90a3ca3ef103467d610ebc04edb
parentff73b22ed9ade6d863c408dd5a6218750870fa03 (diff)
Fix occasional deadlock on startup when using audio sync
-rwxr-xr-xrender_sdl.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/render_sdl.c b/render_sdl.c
index 9e2c9ae..81c2675 100755
--- a/render_sdl.c
+++ b/render_sdl.c
@@ -172,7 +172,13 @@ void render_free_audio_opaque(void *opaque)
void render_audio_created(audio_source *source)
{
if (sync_src == SYNC_AUDIO) {
- SDL_PauseAudio(0);
+ //SDL_PauseAudio acquires the audio device lock, which is held while the callback runs
+ //since our callback can itself be stuck waiting on the audio_ready condition variable
+ //calling SDL_PauseAudio(0) again for audio sources after the first can deadlock
+ //fortunately SDL_GetAudioStatus does not acquire the lock so is safe to call here
+ if (SDL_GetAudioStatus() == SDL_AUDIO_PAUSED) {
+ SDL_PauseAudio(0);
+ }
}
if (current_system && sync_src == SYNC_AUDIO_THREAD) {
system_request_exit(current_system, 0);
@@ -195,7 +201,13 @@ void render_source_paused(audio_source *src, uint8_t remaining_sources)
void render_source_resumed(audio_source *src)
{
if (sync_src == SYNC_AUDIO) {
- SDL_PauseAudio(0);
+ //SDL_PauseAudio acquires the audio device lock, which is held while the callback runs
+ //since our callback can itself be stuck waiting on the audio_ready condition variable
+ //calling SDL_PauseAudio(0) again for audio sources after the first can deadlock
+ //fortunately SDL_GetAudioStatus does not acquire the lock so is safe to call here
+ if (SDL_GetAudioStatus() == SDL_AUDIO_PAUSED) {
+ SDL_PauseAudio(0);
+ }
}
if (current_system && sync_src == SYNC_AUDIO_THREAD) {
system_request_exit(current_system, 0);