diff options
-rw-r--r-- | common/system.cpp | 34 | ||||
-rw-r--r-- | common/system.h | 35 | ||||
-rw-r--r-- | common/util.cpp | 30 | ||||
-rw-r--r-- | common/util.h | 16 |
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. |