diff options
author | Paul Gilbert | 2007-09-28 07:55:02 +0000 |
---|---|---|
committer | Paul Gilbert | 2007-09-28 07:55:02 +0000 |
commit | c5edcaa2ef09467aa3d46fd40491ca9cdf6dc2c8 (patch) | |
tree | 8d3bfa4c9f04ca18c90578b1c8a9ae63087e3ed7 /engines/lure | |
parent | 61a642b1ccd8afc9bffc50ef1ed934f1706b6ce8 (diff) | |
download | scummvm-rg350-c5edcaa2ef09467aa3d46fd40491ca9cdf6dc2c8.tar.gz scummvm-rg350-c5edcaa2ef09467aa3d46fd40491ca9cdf6dc2c8.tar.bz2 scummvm-rg350-c5edcaa2ef09467aa3d46fd40491ca9cdf6dc2c8.zip |
Wrapped access to the playing sounds list in a mutex
svn-id: r29114
Diffstat (limited to 'engines/lure')
-rw-r--r-- | engines/lure/sound.cpp | 28 | ||||
-rw-r--r-- | engines/lure/sound.h | 2 |
2 files changed, 27 insertions, 3 deletions
diff --git a/engines/lure/sound.cpp b/engines/lure/sound.cpp index 6a6f681508..5da2519c72 100644 --- a/engines/lure/sound.cpp +++ b/engines/lure/sound.cpp @@ -36,6 +36,8 @@ DECLARE_SINGLETON(Lure::SoundManager); namespace Lure { SoundManager::SoundManager() { + _soundMutex = g_system->createMutex(); + int index; _descs = Disk::getReference().getEntry(SOUND_DESC_RESOURCE_ID); _numDescs = _descs->size() / sizeof(SoundDescResource); @@ -69,8 +71,10 @@ SoundManager::~SoundManager() { removeSounds(); _activeSounds.clear(); - _playingSounds.clear(); + g_system->lockMutex(_soundMutex); + _playingSounds.clear(); + g_system->unlockMutex(_soundMutex); delete _descs; if (_soundData) @@ -79,6 +83,8 @@ SoundManager::~SoundManager() { if (_driver) _driver->close(); _driver = NULL; + + g_system->deleteMutex(_soundMutex); } void SoundManager::loadSection(uint16 sectionId) { @@ -370,9 +376,11 @@ void SoundManager::musicInterface_Play(uint8 soundNumber, uint8 channelNumber) { 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 @@ void SoundManager::musicInterface_Stop(uint8 soundNumber) { 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 @@ void SoundManager::musicInterface_KillAll() { 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 @@ void SoundManager::musicInterface_KillAll() { _playingSounds.clear(); _activeSounds.clear(); + g_system->unlockMutex(_soundMutex); } // musicInterface_ContinuePlaying @@ -464,6 +476,8 @@ void SoundManager::musicInterface_TrashReverb() { 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 @@ void SoundManager::musicInterface_TidySounds() { 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); } /*------------------------------------------------------------------------*/ diff --git a/engines/lure/sound.h b/engines/lure/sound.h index cfe0739298..c9c5e191c1 100644 --- a/engines/lure/sound.h +++ b/engines/lure/sound.h @@ -117,11 +117,13 @@ private: 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(); |