changeset 755:614df17de975

Add mutex locking to audio stream stuff.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 05 May 2013 03:38:49 +0300
parents ce7acde37dc7
children 4dda14ff8e1a
files dmengine.h dmsimple.c
diffstat 2 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/dmengine.h	Sun May 05 03:34:32 2013 +0300
+++ b/dmengine.h	Sun May 05 03:38:49 2013 +0300
@@ -252,6 +252,8 @@
 
     SDL_AudioSpec optAfmt;
     int optAudioSetup;
+
+    DMMutex *audioStreamMutex;
     Uint8 * audioStreamBuf;
     size_t audioStreamLen;
 
--- a/dmsimple.c	Sun May 05 03:34:32 2013 +0300
+++ b/dmsimple.c	Sun May 05 03:38:49 2013 +0300
@@ -65,6 +65,7 @@
 {
     (void) userdata;
 
+    dmMutexLock(engine.audioStreamMutex);
     engine.audioStreamBuf = stream;
     engine.audioStreamLen = len;
 
@@ -96,6 +97,8 @@
         default:
             break;
     }
+
+    dmMutexUnlock(engine.audioStreamMutex);
 }
 
 
@@ -698,6 +701,7 @@
         engine.optAfmt.format, engine.optAfmt.channels, engine.optAfmt.freq);
 
     engine.optAfmt.callback = engineAudioCallback;
+    engine.audioStreamMutex = dmCreateMutex();
     
     if (SDL_OpenAudio(&engine.optAfmt, NULL) < 0)
     {
@@ -891,6 +895,9 @@
     }
 #endif
     SDL_UnlockAudio();
+    
+    if (engine.audioStreamMutex != NULL)
+        dmDestroyMutex(engine.audioStreamMutex);
 
 #ifdef DM_USE_TIMELINE
     dmFreeTimeline(engine.tl);