changeset 606:59046d70c0ef

Fixed a thread race conds in xs_reinit() and xs_get_song_info()
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 31 Aug 2007 16:54:04 +0000
parents 0675613af00c
children e22db8f24976
files src/xmms-sid.c
diffstat 1 files changed, 14 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/xmms-sid.c	Fri Aug 31 16:52:05 2007 +0000
+++ b/src/xmms-sid.c	Fri Aug 31 16:54:04 2007 +0000
@@ -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"));
 	}
+
 }
 
 
@@ -940,11 +948,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)) {
@@ -961,6 +973,7 @@
 
 	/* Free tune information */
 	xs_tuneinfo_free(pInfo);
+	XS_MUTEX_UNLOCK(xs_status);
 }