Mercurial > repos > blastem
comparison render_sdl.c @ 2004:66f08024d9e9
Fix occasional deadlock on startup when using audio sync
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 11 Oct 2020 18:01:48 -0700 |
parents | 3537514ea206 |
children | 193b804c9845 |
comparison
equal
deleted
inserted
replaced
2003:4c418ee9a9d8 | 2004:66f08024d9e9 |
---|---|
170 } | 170 } |
171 | 171 |
172 void render_audio_created(audio_source *source) | 172 void render_audio_created(audio_source *source) |
173 { | 173 { |
174 if (sync_src == SYNC_AUDIO) { | 174 if (sync_src == SYNC_AUDIO) { |
175 SDL_PauseAudio(0); | 175 //SDL_PauseAudio acquires the audio device lock, which is held while the callback runs |
176 //since our callback can itself be stuck waiting on the audio_ready condition variable | |
177 //calling SDL_PauseAudio(0) again for audio sources after the first can deadlock | |
178 //fortunately SDL_GetAudioStatus does not acquire the lock so is safe to call here | |
179 if (SDL_GetAudioStatus() == SDL_AUDIO_PAUSED) { | |
180 SDL_PauseAudio(0); | |
181 } | |
176 } | 182 } |
177 if (current_system && sync_src == SYNC_AUDIO_THREAD) { | 183 if (current_system && sync_src == SYNC_AUDIO_THREAD) { |
178 system_request_exit(current_system, 0); | 184 system_request_exit(current_system, 0); |
179 } | 185 } |
180 } | 186 } |
193 } | 199 } |
194 | 200 |
195 void render_source_resumed(audio_source *src) | 201 void render_source_resumed(audio_source *src) |
196 { | 202 { |
197 if (sync_src == SYNC_AUDIO) { | 203 if (sync_src == SYNC_AUDIO) { |
198 SDL_PauseAudio(0); | 204 //SDL_PauseAudio acquires the audio device lock, which is held while the callback runs |
205 //since our callback can itself be stuck waiting on the audio_ready condition variable | |
206 //calling SDL_PauseAudio(0) again for audio sources after the first can deadlock | |
207 //fortunately SDL_GetAudioStatus does not acquire the lock so is safe to call here | |
208 if (SDL_GetAudioStatus() == SDL_AUDIO_PAUSED) { | |
209 SDL_PauseAudio(0); | |
210 } | |
199 } | 211 } |
200 if (current_system && sync_src == SYNC_AUDIO_THREAD) { | 212 if (current_system && sync_src == SYNC_AUDIO_THREAD) { |
201 system_request_exit(current_system, 0); | 213 system_request_exit(current_system, 0); |
202 } | 214 } |
203 } | 215 } |