changeset 3176:dca77b467ea2

Fix a race condition which can occur when flushing the output buffer, causing two locking g_conds to occur at unexpected order, halting the execution.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 05 Jun 2009 02:32:48 +0300
parents 1bb4cad57923
children 1117166277f7
files src/alsa-ng/alsa-core.c
diffstat 1 files changed, 4 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/alsa-ng/alsa-core.c	Sat May 16 15:41:43 2009 +0200
+++ b/src/alsa-ng/alsa-core.c	Fri Jun 05 02:32:48 2009 +0300
@@ -32,7 +32,7 @@
 static gint flush_request, paused;
 
 static GMutex *pcm_pause_mutex, *pcm_state_mutex;
-static GCond *pcm_pause_cond, *pcm_state_cond;
+static GCond *pcm_pause_cond, *pcm_state_cond, *pcm_flush_cond;
 
 /********************************************************************************
  * ALSA Mixer setting functions.                                                *
@@ -83,7 +83,7 @@
             wr_total = flush_request * (bps / 1000);
             flush_request = -1;
 
-            g_cond_broadcast(pcm_state_cond);
+            g_cond_broadcast(pcm_flush_cond);
         }
 
         if (alsaplug_ringbuffer_read(&pcm_ringbuf, buf, 2048) == -1)
@@ -131,6 +131,7 @@
 
     pcm_state_mutex = g_mutex_new();
     pcm_state_cond = g_cond_new();
+    pcm_flush_cond = g_cond_new();
 
     if (snd_card_next(&card) != 0)
         return OUTPUT_PLUGIN_INIT_NO_DEVICES;
@@ -282,11 +283,9 @@
     g_mutex_lock(pcm_state_mutex);
     flush_request = time;
     g_cond_broadcast(pcm_state_cond);
-    g_mutex_unlock(pcm_state_mutex);
 
     /* ...then wait for the transaction to complete. */
-    g_mutex_lock(pcm_state_mutex);
-    g_cond_wait(pcm_state_cond, pcm_state_mutex);
+    g_cond_wait(pcm_flush_cond, pcm_state_mutex);
     g_mutex_unlock(pcm_state_mutex);
 }