[Scummvm-cvs-logs] SF.net SVN: scummvm: [29114] scummvm/trunk/engines/lure

dreammaster at users.sourceforge.net dreammaster at users.sourceforge.net
Fri Sep 28 09:55:02 CEST 2007


Revision: 29114
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29114&view=rev
Author:   dreammaster
Date:     2007-09-28 00:55:02 -0700 (Fri, 28 Sep 2007)

Log Message:
-----------
Wrapped access to the playing sounds list in a mutex

Modified Paths:
--------------
    scummvm/trunk/engines/lure/sound.cpp
    scummvm/trunk/engines/lure/sound.h

Modified: scummvm/trunk/engines/lure/sound.cpp
===================================================================
--- scummvm/trunk/engines/lure/sound.cpp	2007-09-27 20:39:06 UTC (rev 29113)
+++ scummvm/trunk/engines/lure/sound.cpp	2007-09-28 07:55:02 UTC (rev 29114)
@@ -36,6 +36,8 @@
 namespace Lure {
 
 SoundManager::SoundManager() {
+	_soundMutex = g_system->createMutex();
+
 	int index;
 	_descs = Disk::getReference().getEntry(SOUND_DESC_RESOURCE_ID);
 	_numDescs = _descs->size() / sizeof(SoundDescResource);
@@ -69,9 +71,11 @@
 
 	removeSounds();
 	_activeSounds.clear();
+
+	g_system->lockMutex(_soundMutex);
 	_playingSounds.clear();
+	g_system->unlockMutex(_soundMutex);
 
-
 	delete _descs;
 	if (_soundData)
 		delete _soundData;
@@ -79,6 +83,8 @@
 	if (_driver)
 		_driver->close();
 	_driver = NULL;
+
+	g_system->deleteMutex(_soundMutex);
 }
 
 void SoundManager::loadSection(uint16 sectionId) {
@@ -370,9 +376,11 @@
 		dataSize = nextDataOfs - dataOfs;
 	}
 
+	g_system->lockMutex(_soundMutex);
 	MidiMusic *sound = new MidiMusic(_driver, _channelsInner, channelNumber, soundNumber, 
 		soundStart, dataSize);
 	_playingSounds.push_back(sound);		
+	g_system->unlockMutex(_soundMutex);
 }
 
 // musicInterface_Stop
@@ -383,14 +391,16 @@
 	musicInterface_TidySounds();
 	uint8 soundNum = soundNumber & 0x7f;
 
+	g_system->lockMutex(_soundMutex);
 	ManagedList<MidiMusic *>::iterator i;
 	for (i = _playingSounds.begin(); i != _playingSounds.end(); ++i) {
 		MidiMusic *music = *i;
 		if (music->soundNumber() == soundNum) {
 			_playingSounds.erase(i);
-			return;
+			break;
 		}
 	}
+	g_system->unlockMutex(_soundMutex);
 }
 
 // musicInterface_CheckPlaying
@@ -434,6 +444,7 @@
 	debugC(ERROR_INTERMEDIATE, kLureDebugSounds, "musicInterface_KillAll");
 	musicInterface_TidySounds();
 
+	g_system->lockMutex(_soundMutex);
 	ManagedList<MidiMusic *>::iterator i;
 	for (i = _playingSounds.begin(); i != _playingSounds.end(); ++i) {
 		MidiMusic *music = *i;
@@ -442,6 +453,7 @@
 
 	_playingSounds.clear();
 	_activeSounds.clear();
+	g_system->unlockMutex(_soundMutex);
 }
 
 // musicInterface_ContinuePlaying
@@ -464,6 +476,8 @@
 
 void SoundManager::musicInterface_TidySounds() {
 	debugC(ERROR_DETAILED, kLureDebugSounds, "musicInterface_TidySounds");
+
+	g_system->lockMutex(_soundMutex);
 	ManagedList<MidiMusic *>::iterator i = _playingSounds.begin(); 
 	while (i != _playingSounds.end()) {
 		MidiMusic *music = *i;
@@ -472,17 +486,25 @@
 		else
 			++i;
 	}
+	g_system->unlockMutex(_soundMutex);
 }
 
 void SoundManager::onTimer(void *data) {
 	SoundManager *snd = (SoundManager *) data;
+	snd->doTimer();
+}
 
+void SoundManager::doTimer() {
+	g_system->lockMutex(_soundMutex);
+
 	ManagedList<MidiMusic *>::iterator i;
-	for (i = snd->_playingSounds.begin(); i != snd->_playingSounds.end(); ++i) {
+	for (i = _playingSounds.begin(); i != _playingSounds.end(); ++i) {
 		MidiMusic *music = *i;
 		if (music->isPlaying()) 
 			music->onTimer();
 	}
+
+	g_system->unlockMutex(_soundMutex);
 }
 
 /*------------------------------------------------------------------------*/

Modified: scummvm/trunk/engines/lure/sound.h
===================================================================
--- scummvm/trunk/engines/lure/sound.h	2007-09-27 20:39:06 UTC (rev 29113)
+++ scummvm/trunk/engines/lure/sound.h	2007-09-28 07:55:02 UTC (rev 29114)
@@ -117,11 +117,13 @@
 	bool _channelsInUse[NUM_CHANNELS_OUTER];
 	bool _isPlaying;
 	bool _nativeMT32;
+	Common::MutexRef _soundMutex;
 
 	// Internal support methods
 	void bellsBodge();
 	void musicInterface_TidySounds();
 	static void onTimer(void *data);
+	void doTimer();
 public:
 	SoundManager();
 	~SoundManager();


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list