SDL_mixer: testaudiodecoder: Use an atomic int for the done flag. (2b0e3)

From 2b0e3c1b16131a82ba8b594950d5164420ae6698 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 2 Jun 2026 14:13:44 -0400
Subject: [PATCH] testaudiodecoder: Use an atomic int for the done flag.

It's shared between two threads.

Reference Issue #861.

(cherry picked from commit f9d0987966ce86cee1247265f0f6f246f26c0cd6)
---
 test/testaudiodecoder.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/test/testaudiodecoder.c b/test/testaudiodecoder.c
index fc81e79e..57f7338f 100644
--- a/test/testaudiodecoder.c
+++ b/test/testaudiodecoder.c
@@ -24,7 +24,7 @@
 #include <SDL3/SDL_main.h>
 #include "SDL3_mixer/SDL_mixer.h"
 
-static bool done = false;
+static SDL_AtomicInt done;  /* the device callback happens in another thread, so use an atomic int for this flag. */
 static SDL_AudioSpec spec;
 
 static void SDLCALL AudioDeviceCallback(void *userdata, SDL_AudioStream *stream, int additional_amount, int total_amount)
@@ -36,7 +36,7 @@ static void SDLCALL AudioDeviceCallback(void *userdata, SDL_AudioStream *stream,
         const int needed = SDL_min((int)sizeof(buffer), additional_amount);
         const int br = MIX_DecodeAudio(audiodecoder, buffer, needed, &spec);
         if (br <= 0) {
-            done = true;
+            SDL_SetAtomicInt(&done, 1);
             break;
         }
 
@@ -81,6 +81,8 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
 
     SDL_ResumeAudioStreamDevice(stream);
 
+    SDL_SetAtomicInt(&done, 0);
+
     return SDL_APP_CONTINUE;
 }
 
@@ -94,7 +96,7 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
 
 SDL_AppResult SDL_AppIterate(void *appstate)
 {
-    return done ? SDL_APP_SUCCESS : SDL_APP_CONTINUE;
+    return SDL_GetAtomicInt(&done) ? SDL_APP_SUCCESS : SDL_APP_CONTINUE;
 }
 
 void SDL_AppQuit(void *appstate, SDL_AppResult result)