[Scummvm-cvs-logs] CVS: scummvm/sound mixer.cpp,1.60,1.61

Max Horn fingolfin at users.sourceforge.net
Sat Jul 5 09:02:08 CEST 2003


Update of /cvsroot/scummvm/scummvm/sound
In directory sc8-pr-cvs1:/tmp/cvs-serv28983

Modified Files:
	mixer.cpp 
Log Message:
protect calls to insertChannel with mutex, too (and switch to using StackLock)

Index: mixer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/sound/mixer.cpp,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- mixer.cpp	4 Jul 2003 20:08:02 -0000	1.60
+++ mixer.cpp	5 Jul 2003 16:01:55 -0000	1.61
@@ -24,6 +24,7 @@
 #include "mixer.h"
 #include "common/engine.h"	// for warning/error/debug
 #include "common/file.h"
+#include "common/util.h"
 
 
 class Channel {
@@ -182,7 +183,7 @@
 }
 
 void SoundMixer::appendStream(int index, void *sound, uint32 size) {
-	_syst->lock_mutex(_mutex);
+	StackLock lock(_mutex);
 
 	ChannelStream *chan = dynamic_cast<ChannelStream *>(_channels[index]);
 	if (!chan) {
@@ -190,12 +191,10 @@
 	} else {
 		chan->append(sound, size);
 	}
-
-	_syst->unlock_mutex(_mutex);
 }
 
 void SoundMixer::endStream(int index) {
-	_syst->lock_mutex(_mutex);
+	StackLock lock(_mutex);
 
 	ChannelStream *chan = dynamic_cast<ChannelStream *>(_channels[index]);
 	if (!chan) {
@@ -203,8 +202,6 @@
 	} else {
 		chan->finish();
 	}
-
-	_syst->unlock_mutex(_mutex);
 }
 
 int SoundMixer::insertChannel(PlayingSoundHandle *handle, Channel *chan) {
@@ -229,41 +226,43 @@
 }
 
 int SoundMixer::playRaw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags, int id) {
+	StackLock lock(_mutex);	
+
 	// Prevent duplicate sounds
 	if (id != -1) {
-		_syst->lock_mutex(_mutex);	
-		    for (int i = 0; i != NUM_CHANNELS; i++)
-			        if (_channels[i] != NULL && _channels[i]->_id == id) {
-						_syst->unlock_mutex(_mutex);
-						return -1;
-					}
-		_syst->unlock_mutex(_mutex);
+		for (int i = 0; i != NUM_CHANNELS; i++)
+			if (_channels[i]->_id == id && _channels[i] != NULL)
+				return -1;
 	}
 
 	return insertChannel(handle, new ChannelRaw(this, sound, size, rate, flags, id));
 }
 
 int SoundMixer::newStream(void *sound, uint32 size, uint rate, byte flags, int32 buffer_size) {
+	StackLock lock(_mutex);	
 	return insertChannel(NULL, new ChannelStream(this, sound, size, rate, flags, buffer_size));
 }
 
 #ifdef USE_MAD
 int SoundMixer::playMP3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags) {
+	StackLock lock(_mutex);	
 	return insertChannel(handle, new ChannelMP3(this, sound, size, flags));
 }
 int SoundMixer::playMP3CDTrack(PlayingSoundHandle *handle, File *file, mad_timer_t duration) {
+	StackLock lock(_mutex);	
 	return insertChannel(handle, new ChannelMP3CDMusic(this, file, duration));
 }
 #endif
 
 #ifdef USE_VORBIS
 int SoundMixer::playVorbis(PlayingSoundHandle *handle, OggVorbis_File *ov_file, int duration, bool is_cd_track) {
+	StackLock lock(_mutex);	
 	return insertChannel(handle, new ChannelVorbis(this, ov_file, duration, is_cd_track));
 }
 #endif
 
 void SoundMixer::mix(int16 *buf, uint len) {
-	_syst->lock_mutex(_mutex);
+	StackLock lock(_mutex);
 	
 	if (_premixProc && !_paused) {
 		int i;
@@ -291,8 +290,6 @@
 					_channels[i]->mix(buf, len);
 			}
 	}
-	
-	_syst->unlock_mutex(_mutex);
 }
 
 void SoundMixer::onGenerateSamples(void *s, byte *samples, int len) {





More information about the Scummvm-git-logs mailing list