changeset 1554:f7c630358bda

Merge thread locking/mutex fix from XMMS-SID. Fixes a race between getting file/song information while xs_reinit() is being run.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 02 Sep 2007 01:31:55 +0300
parents 22f1948c9c28
children c3b8dedeedc5
files src/sid/xmms-sid.c
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/sid/xmms-sid.c	Sun Sep 02 01:30:22 2007 +0300
+++ b/src/sid/xmms-sid.c	Sun Sep 02 01:31:55 2007 +0300
@@ -145,6 +145,9 @@
 		XS_MUTEX_UNLOCK(xs_status);
 	}
 
+	XS_MUTEX_LOCK(xs_status);
+	XS_MUTEX_LOCK(xs_cfg);
+
 	/* Initialize status and sanitize configuration */
 	xs_memset(&xs_status, 0, sizeof(xs_status));
 
@@ -195,12 +198,16 @@
 
 	XSDEBUG("init#2: %s, %i\n", (isInitialized) ? "OK" : "FAILED", iPlayer);
 
+
 	/* Get settings back, in case the chosen emulator backend changed them */
 	xs_cfg.audioFrequency = xs_status.audioFrequency;
 	xs_cfg.audioBitsPerSample = xs_status.audioBitsPerSample;
 	xs_cfg.audioChannels = xs_status.audioChannels;
 	xs_cfg.oversampleEnable = xs_status.oversampleEnable;
 
+	XS_MUTEX_UNLOCK(xs_status);
+	XS_MUTEX_UNLOCK(xs_cfg);
+
 	/* Initialize song-length database */
 	xs_songlen_close();
 	if (xs_cfg.songlenDBEnable && (xs_songlen_init() != 0)) {
@@ -212,6 +219,7 @@
 	if (xs_cfg.stilDBEnable && (xs_stil_init() != 0)) {
 		xs_error(_("Error initializing STIL database!\n"));
 	}
+
 }
 
 
@@ -922,11 +930,15 @@
 void xs_get_song_info(gchar * songFilename, gchar ** songTitle, gint * songLength)
 {
 	t_xs_tuneinfo *pInfo;
+	
+	XS_MUTEX_LOCK(xs_status);
 
 	/* Get tune information from emulation engine */
 	pInfo = xs_status.sidPlayer->plrGetSIDInfo(songFilename);
-	if (!pInfo)
+	if (!pInfo) {
+		XS_MUTEX_UNLOCK(xs_status);
 		return;
+	}
 
 	/* Get sub-tune information, if available */
 	if ((pInfo->startTune > 0) && (pInfo->startTune <= pInfo->nsubTunes)) {
@@ -943,6 +955,7 @@
 
 	/* Free tune information */
 	xs_tuneinfo_free(pInfo);
+	XS_MUTEX_UNLOCK(xs_status);
 }