From f5559de703a2deca65f6a716fdf6e68aa7413607 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 20 Mar 2007 18:59:28 +0000 Subject: Fix a potential race condition (leading to lockups) in IMuseDigital::refreshScripts svn-id: r26254 --- engines/scumm/imuse_digi/dimuse_script.cpp | 20 ++++++++++++-------- engines/scumm/imuse_digi/dimuse_track.cpp | 6 +++--- 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'engines') diff --git a/engines/scumm/imuse_digi/dimuse_script.cpp b/engines/scumm/imuse_digi/dimuse_script.cpp index 1a257c905f..ad976e3300 100644 --- a/engines/scumm/imuse_digi/dimuse_script.cpp +++ b/engines/scumm/imuse_digi/dimuse_script.cpp @@ -189,16 +189,20 @@ void IMuseDigital::flushTracks() { } void IMuseDigital::refreshScripts() { - Common::StackLock lock(_mutex, "IMuseDigital::refreshScripts()"); - debug(5, "refreshScripts()"); - bool found = false; - for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { - Track *track = _track[l]; - if (track->used && !track->toBeRemoved && (track->volGroupId == IMUSE_VOLGRP_MUSIC)) { - found = true; + { + Common::StackLock lock(_mutex, "IMuseDigital::refreshScripts()"); + debug(5, "refreshScripts()"); + bool found = false; + for (int l = 0; l < MAX_DIGITAL_TRACKS; l++) { + Track *track = _track[l]; + if (track->used && !track->toBeRemoved && (track->volGroupId == IMUSE_VOLGRP_MUSIC)) { + found = true; + } } } - + + // Make sure parseScriptCmds is *not* called while the mutex is locked + // (else race conditions can occur). if (!found && (_curMusicSeq != 0)) { debug(5, "refreshScripts() Start Sequence"); parseScriptCmds(0x1001, 0, 0, 0, 0, 0, 0, 0); diff --git a/engines/scumm/imuse_digi/dimuse_track.cpp b/engines/scumm/imuse_digi/dimuse_track.cpp index b58d73c8d5..968f01c9e8 100644 --- a/engines/scumm/imuse_digi/dimuse_track.cpp +++ b/engines/scumm/imuse_digi/dimuse_track.cpp @@ -45,7 +45,7 @@ int IMuseDigital::allocSlot(int priority) { } if (trackId == -1) { - debug(5, "IMuseDigital::startSound(): All slots are full"); + debug(5, "IMuseDigital::allocSlot(): All slots are full"); for (l = 0; l < MAX_DIGITAL_TRACKS; l++) { Track *track = _track[l]; if (track->used && !track->toBeRemoved && @@ -57,9 +57,9 @@ int IMuseDigital::allocSlot(int priority) { if (lowest_priority <= priority) { assert(trackId != -1); _track[trackId]->toBeRemoved = true; - debug(5, "IMuseDigital::startSound(): Removed sound %d from track %d", _track[trackId]->soundId, trackId); + debug(5, "IMuseDigital::allocSlot(): Removed sound %d from track %d", _track[trackId]->soundId, trackId); } else { - debug(5, "IMuseDigital::startSound(): Priority sound too low"); + debug(5, "IMuseDigital::allocSlot(): Priority sound too low"); return -1; } } -- cgit v1.2.3