aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2003-07-05 15:19:11 +0000
committerMax Horn2003-07-05 15:19:11 +0000
commitd098334fe651616afa8b5314bcf580ae835185b2 (patch)
tree5442e167b6a58dea66f8482a1afcae264dfbbc1a /common
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
Diffstat (limited to 'common')
-rw-r--r--common/timer.h2
-rw-r--r--common/util.cpp19
-rw-r--r--common/util.h14
3 files changed, 34 insertions, 1 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