Protect SDL_PauseAudio*() with the audio callback lock.
authorRyan C. Gordon
Sun, 14 Jul 2013 12:42:12 -0400
changeset 74476860de5bcb8c
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
     1.1 --- a/src/audio/SDL_audio.c	Sun Jul 14 11:28:18 2013 -0400
     1.2 +++ b/src/audio/SDL_audio.c	Sun Jul 14 12:42:12 2013 -0400
     1.3 @@ -480,13 +480,13 @@
     1.4                  }
     1.5              }
     1.6  
     1.7 +            SDL_LockMutex(device->mixer_lock);
     1.8              if (device->paused) {
     1.9                  SDL_memset(stream, silence, stream_len);
    1.10              } else {
    1.11 -                SDL_LockMutex(device->mixer_lock);
    1.12                  (*fill) (udata, stream, stream_len);
    1.13 -                SDL_UnlockMutex(device->mixer_lock);
    1.14              }
    1.15 +            SDL_UnlockMutex(device->mixer_lock);
    1.16  
    1.17              /* Convert the audio if necessary */
    1.18              if (device->convert.needed) {
    1.19 @@ -1114,7 +1114,9 @@
    1.20  {
    1.21      SDL_AudioDevice *device = get_audio_device(devid);
    1.22      if (device) {
    1.23 +        current_audio.impl.LockDevice(device);
    1.24          device->paused = pause_on;
    1.25 +        current_audio.impl.UnlockDevice(device);
    1.26      }
    1.27  }
    1.28