aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorMax Horn2011-03-23 11:47:07 +0100
committerMax Horn2011-03-23 15:25:46 +0100
commit7b02dac3c5678bb47216495fc97130b98ff2bfe4 (patch)
treeebeba91f309e1321b4a72136d59672b696eb7849 /engines
parent99dbecf3b4a14382fa867610a43201fc150bfda9 (diff)
downloadscummvm-rg350-7b02dac3c5678bb47216495fc97130b98ff2bfe4.tar.gz
scummvm-rg350-7b02dac3c5678bb47216495fc97130b98ff2bfe4.tar.bz2
scummvm-rg350-7b02dac3c5678bb47216495fc97130b98ff2bfe4.zip
ENGINES: Use Common::StackLock in more places
Diffstat (limited to 'engines')
-rw-r--r--engines/hugo/sound.cpp19
-rw-r--r--engines/parallaction/sound_br.cpp11
-rw-r--r--engines/parallaction/sound_ns.cpp18
-rw-r--r--engines/queen/music.cpp11
-rw-r--r--engines/sci/sound/music.cpp21
-rw-r--r--engines/scumm/player_pce.cpp4
-rw-r--r--engines/scumm/player_sid.cpp18
-rw-r--r--engines/sky/music/musicbase.cpp9
-rw-r--r--engines/touche/midi.cpp17
9 files changed, 49 insertions, 79 deletions
diff --git a/engines/hugo/sound.cpp b/engines/hugo/sound.cpp
index c4feb5fb1c..33627fb240 100644
--- a/engines/hugo/sound.cpp
+++ b/engines/hugo/sound.cpp
@@ -98,26 +98,26 @@ void MidiPlayer::play(uint8 *stream, uint16 size) {
_midiData = (uint8 *)malloc(size);
if (_midiData) {
memcpy(_midiData, stream, size);
- _mutex.lock();
+
+ Common::StackLock lock(_mutex);
syncVolume();
_parser->loadMusic(_midiData, size);
_parser->setTrack(0);
_isLooping = false;
_isPlaying = true;
- _mutex.unlock();
}
}
void MidiPlayer::stop() {
debugC(3, kDebugMusic, "MidiPlayer::stop");
- _mutex.lock();
+
+ Common::StackLock lock(_mutex);
if (_isPlaying) {
_isPlaying = false;
_parser->unloadMusic();
free(_midiData);
_midiData = 0;
}
- _mutex.unlock();
}
void MidiPlayer::pause(bool p) {
@@ -135,11 +135,10 @@ void MidiPlayer::updateTimer() {
return;
}
- _mutex.lock();
+ Common::StackLock lock(_mutex);
if (_isPlaying) {
_parser->onTimer();
}
- _mutex.unlock();
}
void MidiPlayer::adjustVolume(int diff) {
@@ -159,13 +158,13 @@ void MidiPlayer::syncVolume() {
void MidiPlayer::setVolume(int volume) {
debugC(3, kDebugMusic, "MidiPlayer::setVolume");
_masterVolume = CLIP(volume, 0, 255);
- _mutex.lock();
+
+ Common::StackLock lock(_mutex);
for (int i = 0; i < kNumbChannels; ++i) {
if (_channelsTable[i]) {
_channelsTable[i]->volume(_channelsVolume[i] * _masterVolume / 255);
}
}
- _mutex.unlock();
}
void MidiPlayer::setChannelVolume(int channel) {
@@ -198,7 +197,8 @@ bool MidiPlayer::isOpen() const {
void MidiPlayer::close() {
stop();
- _mutex.lock();
+
+ Common::StackLock lock(_mutex);
_driver->setTimerCallback(0, 0);
_driver->close();
delete _driver;
@@ -206,7 +206,6 @@ void MidiPlayer::close() {
if (_parser)
_parser->setMidiDriver(0);
delete _parser;
- _mutex.unlock();
}
void MidiPlayer::send(uint32 b) {
diff --git a/engines/parallaction/sound_br.cpp b/engines/parallaction/sound_br.cpp
index 5be953936d..80bd95779d 100644
--- a/engines/parallaction/sound_br.cpp
+++ b/engines/parallaction/sound_br.cpp
@@ -278,24 +278,23 @@ void MidiPlayer_MSC::play(Common::SeekableReadStream *stream) {
if (_midiData) {
stream->read(_midiData, size);
delete stream;
- _mutex.lock();
+
+ Common::StackLock lock(_mutex);
_parser->loadMusic(_midiData, size);
_parser->setTrack(0);
_isLooping = true;
_isPlaying = true;
- _mutex.unlock();
}
}
void MidiPlayer_MSC::stop() {
- _mutex.lock();
+ Common::StackLock lock(_mutex);
if (_isPlaying) {
_isPlaying = false;
_parser->unloadMusic();
free(_midiData);
_midiData = 0;
}
- _mutex.unlock();
}
void MidiPlayer_MSC::pause(bool p) {
@@ -349,14 +348,14 @@ bool MidiPlayer_MSC::isOpen() const {
void MidiPlayer_MSC::close() {
stop();
- _mutex.lock();
+
+ Common::StackLock lock(_mutex);
_driver->setTimerCallback(NULL, NULL);
_driver->close();
delete _driver;
_driver = 0;
_parser->setMidiDriver(NULL);
delete _parser;
- _mutex.unlock();
}
void MidiPlayer_MSC::send(uint32 b) {
diff --git a/engines/parallaction/sound_ns.cpp b/engines/parallaction/sound_ns.cpp
index de8a861d4b..aeb934fd8b 100644
--- a/engines/parallaction/sound_ns.cpp
+++ b/engines/parallaction/sound_ns.cpp
@@ -111,24 +111,23 @@ void MidiPlayer::play(Common::SeekableReadStream *stream) {
if (_midiData) {
stream->read(_midiData, size);
delete stream;
- _mutex.lock();
+
+ Common::StackLock lock(_mutex);
_parser->loadMusic(_midiData, size);
_parser->setTrack(0);
_isLooping = true;
_isPlaying = true;
- _mutex.unlock();
}
}
void MidiPlayer::stop() {
- _mutex.lock();
+ Common::StackLock lock(_mutex);
if (_isPlaying) {
_isPlaying = false;
_parser->unloadMusic();
free(_midiData);
_midiData = 0;
}
- _mutex.unlock();
}
void MidiPlayer::pause(bool p) {
@@ -146,11 +145,10 @@ void MidiPlayer::updateTimer() {
return;
}
- _mutex.lock();
+ Common::StackLock lock(_mutex);
if (_isPlaying) {
_parser->onTimer();
}
- _mutex.unlock();
}
void MidiPlayer::adjustVolume(int diff) {
@@ -159,13 +157,13 @@ void MidiPlayer::adjustVolume(int diff) {
void MidiPlayer::setVolume(int volume) {
_masterVolume = CLIP(volume, 0, 255);
- _mutex.lock();
+
+ Common::StackLock lock(_mutex);
for (int i = 0; i < NUM_CHANNELS; ++i) {
if (_channelsTable[i]) {
_channelsTable[i]->volume(_channelsVolume[i] * _masterVolume / 255);
}
}
- _mutex.unlock();
}
int MidiPlayer::open() {
@@ -185,14 +183,14 @@ bool MidiPlayer::isOpen() const {
void MidiPlayer::close() {
stop();
- _mutex.lock();
+
+ Common::StackLock lock(_mutex);
_driver->setTimerCallback(NULL, NULL);
_driver->close();
delete _driver;
_driver = 0;
_parser->setMidiDriver(NULL);
delete _parser;
- _mutex.unlock();
}
void MidiPlayer::send(uint32 b) {
diff --git a/engines/queen/music.cpp b/engines/queen/music.cpp
index 044717878b..e04527d42a 100644
--- a/engines/queen/music.cpp
+++ b/engines/queen/music.cpp
@@ -218,10 +218,9 @@ void MidiMusic::metaEvent(byte type, byte *data, uint16 length) {
}
void MidiMusic::onTimer() {
- _mutex.lock();
+ Common::StackLock lock(_mutex);
if (_isPlaying)
_parser->onTimer();
- _mutex.unlock();
}
void MidiMusic::queueTuneList(int16 tuneList) {
@@ -319,11 +318,10 @@ void MidiMusic::playMusic() {
stopMusic();
- _mutex.lock();
+ Common::StackLock lock(_mutex);
_parser->loadMusic(musicPtr, size);
_parser->setTrack(0);
_isPlaying = true;
- _mutex.unlock();
debug(8, "Playing song %d [queue position: %d]", songNum, _queuePos);
queueUpdatePos();
@@ -349,14 +347,13 @@ uint8 MidiMusic::randomQueuePos() {
if (!queueSize)
return 0;
- return (uint8) _rnd.getRandomNumber(queueSize - 1) & 0xFF;
+ return (uint8)_rnd.getRandomNumber(queueSize - 1) & 0xFF;
}
void MidiMusic::stopMusic() {
- _mutex.lock();
+ Common::StackLock lock(_mutex);
_isPlaying = false;
_parser->unloadMusic();
- _mutex.unlock();
}
uint32 MidiMusic::songOffset(uint16 songNum) const {
diff --git a/engines/sci/sound/music.cpp b/engines/sci/sound/music.cpp
index a028617e74..0ed99c154b 100644
--- a/engines/sci/sound/music.cpp
+++ b/engines/sci/sound/music.cpp
@@ -303,7 +303,7 @@ void SciMusic::soundInitSnd(MusicEntry *pSnd) {
pSnd->hCurrentAud = Audio::SoundHandle();
} else {
// play MIDI track
- _mutex.lock();
+ Common::StackLock lock(_mutex);
pSnd->soundType = Audio::Mixer::kMusicSoundType;
if (pSnd->pMidiParser == NULL) {
pSnd->pMidiParser = new MidiParser_SCI(_soundVersion, this);
@@ -334,7 +334,6 @@ void SciMusic::soundInitSnd(MusicEntry *pSnd) {
pSnd->loop = prevLoop;
pSnd->hold = prevHold;
pSnd->pMidiParser->mainThreadEnd();
- _mutex.unlock();
}
}
}
@@ -441,7 +440,7 @@ void SciMusic::soundPlay(MusicEntry *pSnd) {
}
} else {
if (pSnd->pMidiParser) {
- _mutex.lock();
+ Common::StackLock lock(_mutex);
pSnd->pMidiParser->mainThreadBegin();
pSnd->pMidiParser->tryToOwnChannels();
if (pSnd->status != kSoundPaused)
@@ -468,7 +467,6 @@ void SciMusic::soundPlay(MusicEntry *pSnd) {
pSnd->loop = prevLoop;
pSnd->hold = prevHold;
pSnd->pMidiParser->mainThreadEnd();
- _mutex.unlock();
}
}
@@ -484,7 +482,7 @@ void SciMusic::soundStop(MusicEntry *pSnd) {
_pMixer->stopHandle(pSnd->hCurrentAud);
if (pSnd->pMidiParser) {
- _mutex.lock();
+ Common::StackLock lock(_mutex);
pSnd->pMidiParser->mainThreadBegin();
// We shouldn't call stop in case it's paused, otherwise we would send
// allNotesOff() again
@@ -492,7 +490,6 @@ void SciMusic::soundStop(MusicEntry *pSnd) {
pSnd->pMidiParser->stop();
freeChannels(pSnd);
pSnd->pMidiParser->mainThreadEnd();
- _mutex.unlock();
}
pSnd->fadeStep = 0; // end fading, if fading was in progress
@@ -504,11 +501,10 @@ void SciMusic::soundSetVolume(MusicEntry *pSnd, byte volume) {
// we simply ignore volume changes for samples, because sierra sci also
// doesn't support volume for samples via kDoSound
} else if (pSnd->pMidiParser) {
- _mutex.lock();
+ Common::StackLock lock(_mutex);
pSnd->pMidiParser->mainThreadBegin();
pSnd->pMidiParser->setVolume(volume);
pSnd->pMidiParser->mainThreadEnd();
- _mutex.unlock();
}
}
@@ -530,13 +526,12 @@ void SciMusic::soundKill(MusicEntry *pSnd) {
pSnd->status = kSoundStopped;
if (pSnd->pMidiParser) {
- _mutex.lock();
+ Common::StackLock lock(_mutex);
pSnd->pMidiParser->mainThreadBegin();
pSnd->pMidiParser->unloadMusic();
pSnd->pMidiParser->mainThreadEnd();
delete pSnd->pMidiParser;
pSnd->pMidiParser = NULL;
- _mutex.unlock();
}
if (pSnd->pStreamAud) {
@@ -547,7 +542,7 @@ void SciMusic::soundKill(MusicEntry *pSnd) {
pSnd->pLoopStream = 0;
}
- _mutex.lock();
+ Common::StackLock lock(_mutex);
uint sz = _playList.size(), i;
// Remove sound from playlist
for (i = 0; i < sz; i++) {
@@ -558,7 +553,6 @@ void SciMusic::soundKill(MusicEntry *pSnd) {
break;
}
}
- _mutex.unlock();
}
void SciMusic::soundPause(MusicEntry *pSnd) {
@@ -581,12 +575,11 @@ void SciMusic::soundPause(MusicEntry *pSnd) {
_pMixer->pauseHandle(pSnd->hCurrentAud, true);
} else {
if (pSnd->pMidiParser) {
- _mutex.lock();
+ Common::StackLock lock(_mutex);
pSnd->pMidiParser->mainThreadBegin();
pSnd->pMidiParser->pause();
freeChannels(pSnd);
pSnd->pMidiParser->mainThreadEnd();
- _mutex.unlock();
}
}
}
diff --git a/engines/scumm/player_pce.cpp b/engines/scumm/player_pce.cpp
index 4236fb2d6b..46d976773d 100644
--- a/engines/scumm/player_pce.cpp
+++ b/engines/scumm/player_pce.cpp
@@ -515,7 +515,7 @@ int Player_PCE::readBuffer(int16 *buffer, const int numSamples) {
int sampleCopyCnt;
int samplesLeft = numSamples;
- _mutex.lock();
+ Common::StackLock lock(_mutex);
while (true) {
// copy samples to output buffer
@@ -543,8 +543,6 @@ int Player_PCE::readBuffer(int16 *buffer, const int numSamples) {
_sampleBufferCnt * sizeof(int16));
}
- _mutex.unlock();
-
return numSamples;
}
diff --git a/engines/scumm/player_sid.cpp b/engines/scumm/player_sid.cpp
index 34654a68c5..0d5832a5fb 100644
--- a/engines/scumm/player_sid.cpp
+++ b/engines/scumm/player_sid.cpp
@@ -1287,7 +1287,7 @@ uint8 *Player_SID::getResource(int resID) {
int Player_SID::readBuffer(int16 *buffer, const int numSamples) {
int samplesLeft = numSamples;
- _mutex.lock();
+ Common::StackLock lock(_mutex);
while (samplesLeft > 0) {
// update SID status after each frame
@@ -1301,8 +1301,6 @@ int Player_SID::readBuffer(int16 *buffer, const int numSamples) {
buffer += sampleCount;
}
- _mutex.unlock();
-
return numSamples;
}
@@ -1337,7 +1335,7 @@ void Player_SID::startSound(int nr) {
// prio 7 is never used in any sound file use this byte for auto-detection.
bool isMusic = (data[4] == 0x07);
- _mutex.lock();
+ Common::StackLock lock(_mutex);
if (isMusic) {
initMusic(nr);
@@ -1345,29 +1343,25 @@ void Player_SID::startSound(int nr) {
stopSound_intern(nr);
initSound(nr);
}
-
- _mutex.unlock();
}
void Player_SID::stopSound(int nr) {
if (nr == -1)
return;
- _mutex.lock();
+ Common::StackLock lock(_mutex);
stopSound_intern(nr);
- _mutex.unlock();
}
void Player_SID::stopAllSounds() {
- _mutex.lock();
+ Common::StackLock lock(_mutex);
stopAllSounds_intern();
- _mutex.unlock();
}
int Player_SID::getSoundStatus(int nr) const {
int result = 0;
- //_mutex.lock();
+ //Common::StackLock lock(_mutex);
if (resID_song == nr && isMusicPlaying) {
result = 1;
@@ -1379,8 +1373,6 @@ int Player_SID::getSoundStatus(int nr) const {
}
}
- //_mutex.unlock();
-
return result;
}
diff --git a/engines/sky/music/musicbase.cpp b/engines/sky/music/musicbase.cpp
index 0d3cb65e1b..e1044a9505 100644
--- a/engines/sky/music/musicbase.cpp
+++ b/engines/sky/music/musicbase.cpp
@@ -44,7 +44,7 @@ MusicBase::~MusicBase() {
}
void MusicBase::loadSection(uint8 pSection) {
- _mutex.lock();
+ Common::StackLock lock(_mutex);
if (_currentMusic)
stopMusicInternal();
free(_musicData);
@@ -58,7 +58,6 @@ void MusicBase::loadSection(uint8 pSection) {
_numberOfChannels = _currentMusic = 0;
setupPointers();
startDriver();
- _mutex.unlock();
}
bool MusicBase::musicIsPlaying() {
@@ -69,9 +68,8 @@ bool MusicBase::musicIsPlaying() {
}
void MusicBase::stopMusic() {
- _mutex.lock();
+ Common::StackLock lock(_mutex);
stopMusicInternal();
- _mutex.unlock();
}
void MusicBase::stopMusicInternal() {
@@ -113,7 +111,7 @@ void MusicBase::loadNewMusic() {
}
void MusicBase::pollMusic() {
- _mutex.lock();
+ Common::StackLock lock(_mutex);
uint8 newTempo;
if (_onNextPoll.musicToProcess != _currentMusic)
loadNewMusic();
@@ -127,7 +125,6 @@ void MusicBase::pollMusic() {
updateTempo();
}
}
- _mutex.unlock();
_aktTime &= 0xFFFF;
}
diff --git a/engines/touche/midi.cpp b/engines/touche/midi.cpp
index c420fb34ff..c1270dd2e2 100644
--- a/engines/touche/midi.cpp
+++ b/engines/touche/midi.cpp
@@ -48,32 +48,30 @@ void MidiPlayer::play(Common::ReadStream &stream, int size, bool loop) {
_midiData = (uint8 *)malloc(size);
if (_midiData) {
stream.read(_midiData, size);
- _mutex.lock();
+
+ Common::StackLock lock(_mutex);
_parser->loadMusic(_midiData, size);
_parser->setTrack(0);
_isLooping = loop;
_isPlaying = true;
- _mutex.unlock();
}
}
void MidiPlayer::stop() {
- _mutex.lock();
+ Common::StackLock lock(_mutex);
if (_isPlaying) {
_isPlaying = false;
_parser->unloadMusic();
free(_midiData);
_midiData = 0;
}
- _mutex.unlock();
}
void MidiPlayer::updateTimer() {
- _mutex.lock();
+ Common::StackLock lock(_mutex);
if (_isPlaying) {
_parser->onTimer();
}
- _mutex.unlock();
}
void MidiPlayer::adjustVolume(int diff) {
@@ -82,13 +80,12 @@ void MidiPlayer::adjustVolume(int diff) {
void MidiPlayer::setVolume(int volume) {
_masterVolume = CLIP(volume, 0, 255);
- _mutex.lock();
+ Common::StackLock lock(_mutex);
for (int i = 0; i < NUM_CHANNELS; ++i) {
if (_channelsTable[i]) {
_channelsTable[i]->volume(_channelsVolume[i] * _masterVolume / 255);
}
}
- _mutex.unlock();
}
int MidiPlayer::open() {
@@ -116,14 +113,14 @@ bool MidiPlayer::isOpen() const {
void MidiPlayer::close() {
stop();
- _mutex.lock();
+
+ Common::StackLock lock(_mutex);
_driver->setTimerCallback(NULL, NULL);
_driver->close();
delete _driver;
_driver = 0;
_parser->setMidiDriver(NULL);
delete _parser;
- _mutex.unlock();
}
void MidiPlayer::send(uint32 b) {