[Scummvm-cvs-logs] CVS: scummvm/common system.cpp,1.8,1.9 system.h,1.58,1.59 util.cpp,1.42,1.43 util.h,1.43,1.44

Max Horn fingolfin at users.sourceforge.net
Sun Mar 14 18:46:38 CET 2004


Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14112

Modified Files:
	system.cpp system.h util.cpp util.h 
Log Message:
fix circular header dependency, by moving StackLock class to common/system.h (it ties closely into OSystem anyway)

Index: system.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/system.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- system.cpp	15 Mar 2004 00:45:36 -0000	1.8
+++ system.cpp	15 Mar 2004 01:52:07 -0000	1.9
@@ -83,3 +83,37 @@
 
 	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

Index: system.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/system.h,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- system.h	15 Mar 2004 01:18:46 -0000	1.58
+++ system.h	15 Mar 2004 01:52:07 -0000	1.59
@@ -25,6 +25,8 @@
 
 #include "common/scummsys.h"
 #include "common/savefile.h"
+#include "common/util.h"
+#include "common/rect.h"
 
 
 /**
@@ -479,7 +481,19 @@
 
 
 
-	/** @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 @@
 /** 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 

Index: util.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/util.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- util.cpp	2 Mar 2004 00:37:23 -0000	1.42
+++ util.cpp	15 Mar 2004 01:52:07 -0000	1.43
@@ -100,36 +100,6 @@
 	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 -
 

Index: util.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/util.h,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- util.h	2 Mar 2004 00:37:23 -0000	1.43
+++ util.h	15 Mar 2004 01:52:07 -0000	1.44
@@ -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 @@
 };
 
 /**
- * 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.





More information about the Scummvm-git-logs mailing list