audio: Make SDL_AudioDevice::shutdown an atomic value.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 01 Aug 2016 11:45:45 -0400
changeset 10215 3fbf4a6c6101
parent 10214 4f29bb9e19c3
child 10216 d188ffeca506
audio: Make SDL_AudioDevice::shutdown an atomic value. Just to make sure this get communicated to the audio thread properly.
src/audio/SDL_audio.c
src/audio/SDL_sysaudio.h
--- a/src/audio/SDL_audio.c	Mon Aug 01 00:20:47 2016 -0400
+++ b/src/audio/SDL_audio.c	Mon Aug 01 11:45:45 2016 -0400
@@ -103,7 +103,7 @@
     &ESD_bootstrap,
 #endif
 #if SDL_AUDIO_DRIVER_NACL
-   &NACLAUD_bootstrap,
+    &NACLAUD_bootstrap,
 #endif
 #if SDL_AUDIO_DRIVER_NAS
     &NAS_bootstrap,
@@ -611,7 +611,7 @@
     current_audio.impl.ThreadInit(device);
 
     /* Loop, filling the audio buffers */
-    while (!device->shutdown) {
+    while (!SDL_AtomicGet(&device->shutdown)) {
         /* Fill the current buffer with sound */
         if (device->convert.needed) {
             stream = device->convert.buf;
@@ -874,7 +874,7 @@
 close_audio_device(SDL_AudioDevice * device)
 {
     device->enabled = 0;
-    device->shutdown = 1;
+    SDL_AtomicSet(&device->shutdown, 1);
     if (device->thread != NULL) {
         SDL_WaitThread(device->thread, NULL);
     }
--- a/src/audio/SDL_sysaudio.h	Mon Aug 01 00:20:47 2016 -0400
+++ b/src/audio/SDL_sysaudio.h	Mon Aug 01 11:45:45 2016 -0400
@@ -157,10 +157,10 @@
     SDL_AudioStreamer streamer;
 
     /* Current state flags */
-    /* !!! FIXME: should be SDL_bool */
+    SDL_atomic_t shutdown; /* true if we are signaling the play thread to end. */
+    /* !!! FIXME: these should be SDL_bool */
     int iscapture;
     int enabled;  /* true if device is functioning and connected. */
-    int shutdown; /* true if we are signaling the play thread to end. */
     int paused;
     int opened;