aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorMax Horn2004-03-15 01:52:07 +0000
committerMax Horn2004-03-15 01:52:07 +0000
commitaf80eef70e4f6ec3585425a9e0b8f3614cbbd57f (patch)
treef89741d681c5447556f66e8d6bf155bbbc66b6fa /common
parent2314cdf03635deb54e1b93eba32a914227f262d9 (diff)
downloadscummvm-rg350-af80eef70e4f6ec3585425a9e0b8f3614cbbd57f.tar.gz
scummvm-rg350-af80eef70e4f6ec3585425a9e0b8f3614cbbd57f.tar.bz2
scummvm-rg350-af80eef70e4f6ec3585425a9e0b8f3614cbbd57f.zip
fix circular header dependency, by moving StackLock class to common/system.h (it ties closely into OSystem anyway)
svn-id: r13292
Diffstat (limited to 'common')
-rw-r--r--common/system.cpp34
-rw-r--r--common/system.h35
-rw-r--r--common/util.cpp30
-rw-r--r--common/util.h16
4 files changed, 68 insertions, 47 deletions
diff --git a/common/system.cpp b/common/system.cpp
index ef41f7c234..ce9ba67c3c 100644
--- a/common/system.cpp
+++ b/common/system.cpp
@@ -83,3 +83,37 @@ bool OSystem::setGraphicsMode(const char *name) {
return false;
}
+
+#pragma mark -
+
+
+namespace Common {
+
+StackLock::StackLock(OSystem::MutexRef mutex, OSystem *syst, const char *mutexName)
+ : _mutex(mutex), _syst(syst), _mutexName(mutexName) {
+ if (syst == 0)
+ _syst = g_system;
+ lock();
+}
+
+StackLock::~StackLock() {
+ unlock();
+}
+
+void StackLock::lock() {
+ assert(_syst);
+ if (_mutexName != NULL)
+ debug(6, "Locking mutex %s", _mutexName);
+
+ _syst->lockMutex(_mutex);
+}
+
+void StackLock::unlock() {
+ assert(_syst);
+ if (_mutexName != NULL)
+ debug(6, "Unlocking mutex %s", _mutexName);
+
+ _syst->unlockMutex(_mutex);
+}
+
+} // End of namespace Common
diff --git a/common/system.h b/common/system.h
index 3afe519617..3ddf4982d7 100644
--- a/common/system.h
+++ b/common/system.h
@@ -25,6 +25,8 @@
#include "common/scummsys.h"
#include "common/savefile.h"
+#include "common/util.h"
+#include "common/rect.h"
/**
@@ -479,7 +481,19 @@ public:
- /** @name Mutex handling */
+ /**
+ * @name Mutex handling
+ * Historically, the OSystem API used to have a method which allowed
+ * creating threads. Hence mutex support was needed for thread syncing.
+ * To ease portability, though, we decided to remove the threading API.
+ * Instead, we now use timers (see setTimerCallback() and Common::Timer).
+ * But since those may be implemented using threads (and in fact, that's
+ * how our primary backend, the SDL one, does it on many systems), we
+ * still have to do mutex syncing in our timer callbacks.
+ *
+ * Hence backends which do not use threads to implement the timers simply
+ * can use dummy implementations for these methods.
+ */
//@{
typedef struct Mutex *MutexRef;
@@ -570,5 +584,24 @@ public:
/** The global OSystem instance. Inited in main(). */
#define g_system (OSystem::instance())
+namespace Common {
+
+/**
+ * Auxillary class to (un)lock a mutex on the stack.
+ */
+class StackLock {
+ OSystem::MutexRef _mutex;
+ OSystem *_syst;
+ const char *_mutexName;
+
+ void lock();
+ void unlock();
+public:
+ StackLock(OSystem::MutexRef mutex, OSystem *syst = 0, const char *mutexName = NULL);
+ ~StackLock();
+};
+
+} // End of namespace Common
+
#endif
diff --git a/common/util.cpp b/common/util.cpp
index 811140618e..bb7c4ed9ba 100644
--- a/common/util.cpp
+++ b/common/util.cpp
@@ -100,36 +100,6 @@ uint RandomSource::getRandomNumberRng(uint min, uint max) {
return getRandomNumber(max - min) + min;
}
-#pragma mark -
-
-
-StackLock::StackLock(OSystem::MutexRef mutex, OSystem *syst, const char *mutexName)
- : _mutex(mutex), _syst(syst), _mutexName(mutexName) {
- if (syst == 0)
- _syst = g_system;
- lock();
-}
-
-StackLock::~StackLock() {
- unlock();
-}
-
-void StackLock::lock() {
- assert(_syst);
- if (_mutexName != NULL)
- debug(6, "Locking mutex %s", _mutexName);
-
- _syst->lockMutex(_mutex);
-}
-
-void StackLock::unlock() {
- assert(_syst);
- if (_mutexName != NULL)
- debug(6, "Unlocking mutex %s", _mutexName);
-
- _syst->unlockMutex(_mutex);
-}
-
#pragma mark -
diff --git a/common/util.h b/common/util.h
index b602f3ef85..68c47a1fb5 100644
--- a/common/util.h
+++ b/common/util.h
@@ -22,7 +22,6 @@
#define COMMON_UTIL_H
#include "common/scummsys.h"
-#include "common/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; }
@@ -76,21 +75,6 @@ public:
};
/**
- * Auxillary class to (un)lock a mutex on the stack.
- */
-class StackLock {
- OSystem::MutexRef _mutex;
- OSystem *_syst;
- const char *_mutexName;
-
- void lock();
- void unlock();
-public:
- StackLock(OSystem::MutexRef mutex, OSystem *syst = 0, const char *mutexName = NULL);
- ~StackLock();
-};
-
-/**
* List of language ids.
* @note The order and mappings of the values 0..8 are *required* to stay the
* way they are now, as scripts in COMI rely on them. So don't touch them.