[Scummvm-cvs-logs] SF.net SVN: scummvm:[38263] scummvm/trunk/engines/sci/sfx/core.cpp
wjpalenstijn at users.sourceforge.net
wjpalenstijn at users.sourceforge.net
Sun Feb 15 17:10:00 CET 2009
Revision: 38263
http://scummvm.svn.sourceforge.net/scummvm/?rev=38263&view=rev
Author: wjpalenstijn
Date: 2009-02-15 16:09:55 +0000 (Sun, 15 Feb 2009)
Log Message:
-----------
fix race condition: sfx_exit could stop and delete the mixer while the mixing callback was being executed
Modified Paths:
--------------
scummvm/trunk/engines/sci/sfx/core.cpp
Modified: scummvm/trunk/engines/sci/sfx/core.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/core.cpp 2009-02-15 15:51:56 UTC (rev 38262)
+++ scummvm/trunk/engines/sci/sfx/core.cpp 2009-02-15 16:09:55 UTC (rev 38263)
@@ -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 @@
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 @@
_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 @@
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 @@
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 @@
/* See above: This must happen AFTER stopping the mixer */
player->exit();
+ callbackMutex->unlock();
+ delete callbackMutex;
+ callbackMutex = 0;
}
static inline int
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list