aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorAndre Heider2009-02-26 19:32:22 +0000
committerAndre Heider2009-02-26 19:32:22 +0000
commitdbe632e8edc54591d30bbe141494d329ba0d141b (patch)
tree89ec8c37b25e2bb8d2591368a0925628f36ca8aa /engines
parent84daa0410f27571915d5b718f90e6d44e97b8f81 (diff)
downloadscummvm-rg350-dbe632e8edc54591d30bbe141494d329ba0d141b.tar.gz
scummvm-rg350-dbe632e8edc54591d30bbe141494d329ba0d141b.tar.bz2
scummvm-rg350-dbe632e8edc54591d30bbe141494d329ba0d141b.zip
protect the sfx timer with the callbackMutex to fix the race the condition when restarting or restoring a game.
svn-id: r38913
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/sfx/core.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/engines/sci/sfx/core.cpp b/engines/sci/sfx/core.cpp
index 54dde65ca5..fba63c6722 100644
--- a/engines/sci/sfx/core.cpp
+++ b/engines/sci/sfx/core.cpp
@@ -50,7 +50,7 @@ static sfx_timer_t *timer = NULL;
extern sfx_timer_t sfx_timer_scummvm;
extern sfx_pcm_device_t sfx_pcm_driver_scummvm;
-Common::Mutex* callbackMutex;
+Common::Mutex* callbackMutex = NULL;
int sfx_pcm_available() {
return (pcm_device != NULL);
@@ -343,9 +343,6 @@ static void _update(sfx_state_t *self) {
_update_single_song(self);
}
-
-static int _sfx_timer_active = 0; /* Timer toggle */
-
int sfx_play_iterator_pcm(song_iterator_t *it, song_handle_t handle) {
#ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Playing PCM: %08lx\n", handle);
@@ -362,15 +359,16 @@ int sfx_play_iterator_pcm(song_iterator_t *it, song_handle_t handle) {
}
static void _sfx_timer_callback(void *data) {
- if (_sfx_timer_active) {
- Common::StackLock lock(*callbackMutex);
+ Common::StackLock lock(*callbackMutex);
+
+ if (timer) {
/* First run the player, to give it a chance to fill
** the audio buffer */
if (player)
player->maintenance();
- assert(_sfx_timer_active);
+ assert(timer);
if (mixer)
mixer->process(mixer);
@@ -378,7 +376,11 @@ static void _sfx_timer_callback(void *data) {
}
void sfx_init(sfx_state_t *self, ResourceManager *resmgr, int flags) {
- callbackMutex = new Common::Mutex();
+ if (!callbackMutex)
+ callbackMutex = new Common::Mutex();
+
+ Common::StackLock lock(*callbackMutex);
+
song_lib_init(&self->songlib);
self->song = NULL;
self->flags = flags;
@@ -465,13 +467,11 @@ void sfx_init(sfx_state_t *self, ResourceManager *resmgr, int flags) {
sciprintf("[SFX] No song player found\n");
else
sciprintf("[SFX] Using song player '%s', v%s\n", player->name, player->version);
-
- _sfx_timer_active = 1;
}
void sfx_exit(sfx_state_t *self) {
callbackMutex->lock();
- _sfx_timer_active = 0;
+
#ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Uninitialising\n");
#endif
@@ -483,6 +483,8 @@ void sfx_exit(sfx_state_t *self) {
if (timer && timer->exit())
warning("[SFX] Timer reported error on exit");
+ timer = NULL;
+
/* WARNING: The mixer may hold feeds from the
** player, so we must stop the mixer BEFORE
** stopping the player. */
@@ -497,7 +499,7 @@ void sfx_exit(sfx_state_t *self) {
callbackMutex->unlock();
delete callbackMutex;
- callbackMutex = 0;
+ callbackMutex = NULL;
}
void sfx_suspend(sfx_state_t *self, int suspend) {