fix circular header dependency, by moving StackLock class to common/system.h (it ties closely into OSystem anyway)

svn-id: r13292
This commit is contained in:
Max Horn 2004-03-15 01:52:07 +00:00
parent 2314cdf036
commit af80eef70e
4 changed files with 68 additions and 47 deletions

View File

@ -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

View File

@ -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

View File

@ -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 -

View File

@ -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; }
@ -75,21 +74,6 @@ public:
uint getRandomNumberRng(uint min, uint max);
};
/**
* 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