diff src/alsa/audio.c @ 1753:c730f0212456

Use a GStaticMutex instead of a GMutex to avoid crashing and resource conflicts.
author William Pitcock <nenolod@atheme.org>
date Thu, 20 Sep 2007 10:36:56 -0500
parents 63feceeb3799
children c62011e48c61
line wrap: on
line diff
--- a/src/alsa/audio.c	Wed Sep 19 17:44:13 2007 +0200
+++ b/src/alsa/audio.c	Thu Sep 20 10:36:56 2007 -0500
@@ -66,7 +66,7 @@
 static gboolean pause_request;	 /* pause status currently requested */
 static int flush_request;	 /* flush status (time) currently requested */
 static int prebuffer_size;
-GMutex *alsa_mutex;
+GStaticMutex alsa_mutex = G_STATIC_MUTEX_INIT;
 
 static guint mixer_timeout;
 
@@ -265,7 +265,7 @@
 
 	g_thread_join(audio_thread);
 
-	g_mutex_lock(alsa_mutex); /* alsa_loop locks alsa_mutex! */
+	g_static_mutex_lock(&alsa_mutex); /* alsa_loop locks alsa_mutex! */
 
 	alsa_cleanup_mixer();
 
@@ -284,7 +284,7 @@
 		snd_output_close(logs);
 	debug("Device closed");
 
-	g_mutex_unlock(alsa_mutex);
+	g_static_mutex_unlock(&alsa_mutex);
 }
 
 /* reopen ALSA PCM */
@@ -679,7 +679,7 @@
 	int npfds = snd_pcm_poll_descriptors_count(alsa_pcm);
 	int wr = 0;
 
-	g_mutex_lock(alsa_mutex);
+	g_static_mutex_lock(&alsa_mutex);
 
 	if (npfds <= 0)
 		goto _error;
@@ -716,7 +716,7 @@
 	}
 
  _error:
-	g_mutex_unlock(alsa_mutex);
+	g_static_mutex_unlock(&alsa_mutex);
 	alsa_close_pcm();
 	g_free(thread_buffer);
 	thread_buffer = NULL;
@@ -740,7 +740,7 @@
 		return 0;
 	}
 
-	g_mutex_lock(alsa_mutex);
+	g_static_mutex_lock(&alsa_mutex);
 
 	if (!mixer)
 		alsa_setup_mixer();
@@ -769,7 +769,7 @@
 	pause_request = FALSE;
 	flush_request = -1;
 
-	g_mutex_unlock(alsa_mutex);
+	g_static_mutex_unlock(&alsa_mutex);
 	
 	audio_thread = g_thread_create((GThreadFunc)alsa_loop, NULL, TRUE, NULL);
 	return 1;