aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2003-07-05 15:19:11 +0000
committerMax Horn2003-07-05 15:19:11 +0000
commitd098334fe651616afa8b5314bcf580ae835185b2 (patch)
tree5442e167b6a58dea66f8482a1afcae264dfbbc1a
parent4611b12c0a84ec528f9f020dc85bf4e9a0108c82 (diff)
downloadscummvm-rg350-d098334fe651616afa8b5314bcf580ae835185b2.tar.gz
scummvm-rg350-d098334fe651616afa8b5314bcf580ae835185b2.tar.bz2
scummvm-rg350-d098334fe651616afa8b5314bcf580ae835185b2.zip
updated code to use type MutexRef; added class StackLock (from sdl backend, now in util.*)
svn-id: r8777
-rw-r--r--common/timer.h2
-rw-r--r--common/util.cpp19
-rw-r--r--common/util.h14
-rw-r--r--scumm/imuse.h3
-rw-r--r--scumm/player_v2.h3
-rw-r--r--simon/midi.h2
-rw-r--r--sky/music/musicbase.h2
-rw-r--r--sound/mixer.h2
-rw-r--r--sound/mpu401.h3
9 files changed, 43 insertions, 7 deletions
diff --git a/common/timer.h b/common/timer.h
index 78877963f4..0277f46709 100644
--- a/common/timer.h
+++ b/common/timer.h
@@ -36,7 +36,7 @@ class Timer {
private:
Engine *_engine;
- void *_mutex;
+ OSystem::MutexRef _mutex;
void *_timerHandler;
int32 _thisTime;
int32 _lastTime;
diff --git a/common/util.cpp b/common/util.cpp
index a8be442248..548fcb6a41 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -19,6 +19,7 @@
*/
#include "stdafx.h"
+#include "engine.h"
#include "util.h"
//
@@ -165,3 +166,21 @@ uint RandomSource::getRandomNumberRng(uint min, uint max) {
return getRandomNumber(max - min) + min;
}
+StackLock::StackLock(OSystem::MutexRef mutex) : _mutex(mutex) {
+ lock();
+}
+
+StackLock::~StackLock() {
+ unlock();
+}
+
+void StackLock::lock() {
+ assert(g_system);
+ g_system->lock_mutex(_mutex);
+}
+
+void StackLock::unlock() {
+ assert(g_system);
+ g_system->unlock_mutex(_mutex);
+}
+
diff --git a/common/util.h b/common/util.h
index cc9a45c0e7..8c0409e0ef 100644
--- a/common/util.h
+++ b/common/util.h
@@ -22,6 +22,7 @@
#define COMMON_UTIL_H
#include "scummsys.h"
+#include "system.h"
template<typename T> inline T ABS (T x) { return (x>=0) ? x : -x; }
template<typename T> inline T MIN (T a, T b) { return (a<b) ? a : b; }
@@ -74,4 +75,17 @@ public:
uint getRandomNumberRng(uint min, uint max);
};
+/**
+ * Auxillary class to (un)lock a mutex on the stack.
+ */
+class StackLock {
+ OSystem::MutexRef _mutex;
+ void lock();
+ void unlock();
+public:
+ StackLock(OSystem::MutexRef mutex);
+ ~StackLock();
+};
+
+
#endif
diff --git a/scumm/imuse.h b/scumm/imuse.h
index 7c9033c940..ff3d809101 100644
--- a/scumm/imuse.h
+++ b/scumm/imuse.h
@@ -24,6 +24,7 @@
#define IMUSE_H
#include "scummsys.h"
+#include "common/system.h"
class IMuseInternal;
class MidiDriver;
@@ -36,7 +37,7 @@ class IMuse {
private:
OSystem *_system;
IMuseInternal *_target;
- void *_mutex;
+ OSystem::MutexRef _mutex;
IMuse (OSystem *system, IMuseInternal *target);
void in();
diff --git a/scumm/player_v2.h b/scumm/player_v2.h
index 7680754c82..1bdfa96382 100644
--- a/scumm/player_v2.h
+++ b/scumm/player_v2.h
@@ -24,6 +24,7 @@
#define PLAYER_V2_H
#include "common/scummsys.h"
+#include "common/system.h"
#if !defined(__GNUC__)
#pragma START_PACK_STRUCTS
@@ -116,7 +117,7 @@ private:
byte *next_data;
byte *retaddr;
- void *_mutex;
+ OSystem::MutexRef _mutex;
void mutex_up() { _system->lock_mutex (_mutex); }
void mutex_down() { _system->unlock_mutex (_mutex); }
diff --git a/simon/midi.h b/simon/midi.h
index 95637f2c91..fb6d9f3e4f 100644
--- a/simon/midi.h
+++ b/simon/midi.h
@@ -48,7 +48,7 @@ struct MusicInfo {
class MidiPlayer : public MidiDriver {
protected:
OSystem *_system;
- void *_mutex;
+ OSystem::MutexRef _mutex;
MidiDriver *_driver;
MusicInfo _music;
diff --git a/sky/music/musicbase.h b/sky/music/musicbase.h
index 1c992e98cb..418e13dfd2 100644
--- a/sky/music/musicbase.h
+++ b/sky/music/musicbase.h
@@ -69,7 +69,7 @@ protected:
uint32 _aktTime;
Actions _onNextPoll;
SkyChannelBase *_channels[10];
- void *_mutex;
+ OSystem::MutexRef _mutex;
virtual void setupPointers(void) = 0;
virtual void setupChannels(uint8 *channelData) = 0;
diff --git a/sound/mixer.h b/sound/mixer.h
index 16e94f3326..cc281c0458 100644
--- a/sound/mixer.h
+++ b/sound/mixer.h
@@ -54,7 +54,7 @@ private:
static void onGenerateSamples(void *s, byte *samples, int len);
OSystem *_syst;
- void *_mutex;
+ OSystem::MutexRef _mutex;
void *_premixParam;
PremixProc *_premixProc;
diff --git a/sound/mpu401.h b/sound/mpu401.h
index 592ca67a20..f1d7dc8d2a 100644
--- a/sound/mpu401.h
+++ b/sound/mpu401.h
@@ -22,6 +22,7 @@
#ifndef SOUND_MPU401_H
#define SOUND_MPU401_H
+#include "common/system.h"
#include "mididrv.h"
////////////////////////////////////////
@@ -79,7 +80,7 @@ private:
MidiChannel_MPU401 _midi_channels [16];
volatile bool _started_thread;
- void *_mutex; // Concurrent shutdown barrier
+ OSystem::MutexRef _mutex; // Concurrent shutdown barrier
volatile TimerCallback _timer_proc;
void *_timer_param;