aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2009-02-15 16:09:55 +0000
committerWillem Jan Palenstijn2009-02-15 16:09:55 +0000
commitf046858d5dfe3924bc2455b931dfab8eea41401c (patch)
treecb141e9c4ccb8a450eaff5623134ed9cc925166d /engines
parentfaa156c9d5437fc8deaa51b27231e8c2419e77a3 (diff)
downloadscummvm-rg350-f046858d5dfe3924bc2455b931dfab8eea41401c.tar.gz
scummvm-rg350-f046858d5dfe3924bc2455b931dfab8eea41401c.tar.bz2
scummvm-rg350-f046858d5dfe3924bc2455b931dfab8eea41401c.zip
fix race condition: sfx_exit could stop and delete the mixer while the mixing callback was being executed
svn-id: r38263
Diffstat (limited to 'engines')
-rw-r--r--engines/sci/sfx/core.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/engines/sci/sfx/core.cpp b/engines/sci/sfx/core.cpp
index 1516af3b21..4f48326ed7 100644
--- a/engines/sci/sfx/core.cpp
+++ b/engines/sci/sfx/core.cpp
@@ -32,6 +32,7 @@
#include "sci/include/sfx_player.h"
#include "sci/sfx/mixer.h"
#include "sci/include/sci_midi.h"
+#include "common/mutex.h"
/*#define DEBUG_SONG_API*/
@@ -45,6 +46,9 @@ sfx_pcm_mixer_t *mixer = NULL;
static sfx_pcm_device_t *pcm_device = NULL;
static sfx_timer_t *timer = NULL;
+Common::Mutex* callbackMutex;
+
+
#define MILLION 1000000
int
@@ -427,12 +431,15 @@ static void
_sfx_timer_callback(void *data)
{
if (_sfx_timer_active) {
+ Common::StackLock lock(*callbackMutex);
/* First run the player, to give it a chance to fill
** the audio buffer */
if (player)
player->maintenance();
+ assert(_sfx_timer_active);
+
if (mixer)
mixer->process(mixer);
}
@@ -441,6 +448,7 @@ _sfx_timer_callback(void *data)
void
sfx_init(sfx_state_t *self, resource_mgr_t *resmgr, int flags)
{
+ callbackMutex = new Common::Mutex();
song_lib_init(&self->songlib);
self->song = NULL;
self->flags = flags;
@@ -541,6 +549,7 @@ sfx_init(sfx_state_t *self, resource_mgr_t *resmgr, int flags)
void
sfx_exit(sfx_state_t *self)
{
+ callbackMutex->lock();
_sfx_timer_active = 0;
#ifdef DEBUG_SONG_API
fprintf(stderr, "[sfx-core] Uninitialising\n");
@@ -567,6 +576,9 @@ sfx_exit(sfx_state_t *self)
/* See above: This must happen AFTER stopping the mixer */
player->exit();
+ callbackMutex->unlock();
+ delete callbackMutex;
+ callbackMutex = 0;
}
static inline int