changeset 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 dc83901850df
children 99e468c53dff
files src/alsa/alsa.c src/alsa/alsa.h src/alsa/audio.c src/alsa/init.c
diffstat 4 files changed, 8 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/alsa/alsa.c	Wed Sep 19 17:44:13 2007 +0200
+++ b/src/alsa/alsa.c	Thu Sep 20 10:36:56 2007 -0500
@@ -55,8 +55,4 @@
 		free(alsa_cfg.mixer_device);
 		alsa_cfg.mixer_device = NULL;
 	}
-
-	/* release our mutex */
-	g_mutex_free(alsa_mutex);
-	alsa_mutex = NULL;
 }
--- a/src/alsa/alsa.h	Wed Sep 19 17:44:13 2007 +0200
+++ b/src/alsa/alsa.h	Thu Sep 20 10:36:56 2007 -0500
@@ -81,6 +81,6 @@
 int alsa_get_written_time(void);
 void alsa_tell(AFormat * fmt, gint * rate, gint * nch);
 
-extern GMutex *alsa_mutex;
+extern GStaticMutex alsa_mutex;
 
 #endif
--- 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;
--- a/src/alsa/init.c	Wed Sep 19 17:44:13 2007 +0200
+++ b/src/alsa/init.c	Thu Sep 20 10:36:56 2007 -0500
@@ -55,6 +55,4 @@
 		g_message("Cannot load alsa library: %s", dlerror());
 		/* FIXME, this plugin wont work... */
 	}
-
-	alsa_mutex = g_mutex_new();
 }