Protect SDL_PauseAudio*() with the audio callback lock.
authorRyan C. Gordon <icculus@icculus.org>
Sun, 14 Jul 2013 12:42:12 -0400
changeset 7447 6860de5bcb8c
parent 7446 6cbb6aaedc20
child 7448 c1f9032d0634
Protect SDL_PauseAudio*() with the audio callback lock. Otherwise, you can pause audio and still have the callback running, or run one more time. This makes sure the callback is definitely stopped by the time you return from SDL_PauseAudio().
src/audio/SDL_audio.c
--- a/src/audio/SDL_audio.c	Sun Jul 14 11:28:18 2013 -0400
+++ b/src/audio/SDL_audio.c	Sun Jul 14 12:42:12 2013 -0400
@@ -480,13 +480,13 @@
                 }
             }
 
+            SDL_LockMutex(device->mixer_lock);
             if (device->paused) {
                 SDL_memset(stream, silence, stream_len);
             } else {
-                SDL_LockMutex(device->mixer_lock);
                 (*fill) (udata, stream, stream_len);
-                SDL_UnlockMutex(device->mixer_lock);
             }
+            SDL_UnlockMutex(device->mixer_lock);
 
             /* Convert the audio if necessary */
             if (device->convert.needed) {
@@ -1114,7 +1114,9 @@
 {
     SDL_AudioDevice *device = get_audio_device(devid);
     if (device) {
+        current_audio.impl.LockDevice(device);
         device->paused = pause_on;
+        current_audio.impl.UnlockDevice(device);
     }
 }