[Scummvm-cvs-logs] CVS: scummvm/common timer.h,1.9,1.10 timer.cpp,1.13,1.14 engine.cpp,1.37,1.38

Max Horn fingolfin at users.sourceforge.net
Wed Sep 10 05:54:06 CEST 2003


Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1:/tmp/cvs-serv18561/common

Modified Files:
	timer.h timer.cpp engine.cpp 
Log Message:
added refCon parameter to timer class

Index: timer.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/timer.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- timer.h	1 Aug 2003 12:18:35 -0000	1.9
+++ timer.h	10 Sep 2003 12:43:53 -0000	1.10
@@ -22,11 +22,11 @@
 #define COMMON_TIMER_H
 
 #include "common/scummsys.h"
-#include "common/engine.h"
+#include "common/system.h"
 
 #define MAX_TIMERS 5
 
-typedef void (*TimerProc)(void *);
+typedef void (*TimerProc)(void *refCon);
 
 #ifdef __MORPHOS__
 #include "morphos_timer.h"
@@ -35,7 +35,7 @@
 class Timer {
 
 private:
-	Engine *_engine;
+	OSystem *_system;
 	OSystem::MutexRef _mutex;
 	void *_timerHandler;
 	int32 _thisTime;
@@ -45,13 +45,14 @@
 		TimerProc procedure;
 		int32 interval;
 		int32 counter;
+		void *refCon;
 	} _timerSlots[MAX_TIMERS];
 
 public:
-	Timer(Engine *engine);
+	Timer(OSystem *system);
 	~Timer();
 
-	bool installProcedure(TimerProc procedure, int32 interval);
+	bool installProcedure(TimerProc procedure, int32 interval, void *refCon);
 	void releaseProcedure(TimerProc procedure);
 
 protected:

Index: timer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/timer.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- timer.cpp	8 Sep 2003 17:13:40 -0000	1.13
+++ timer.cpp	10 Sep 2003 12:43:53 -0000	1.14
@@ -23,16 +23,17 @@
 #include "stdafx.h"
 #include "common/scummsys.h"
 #include "common/timer.h"
+#include "common/util.h"
 
 static Timer *g_timer = NULL;
 
-Timer::Timer(Engine * engine) :
-	_engine(engine),
+Timer::Timer(OSystem *system) :
+	_system(system),
 	_mutex(0),
 	_timerHandler(0),
 	_lastTime(0) {
 
-	_mutex = _engine->_system->create_mutex();
+	_mutex = _system->create_mutex();
 
 	g_timer = this;
 	
@@ -42,23 +43,25 @@
 		_timerSlots[i].counter = 0;
 	}
 
-	_thisTime = _engine->_system->get_msecs();
+	_thisTime = _system->get_msecs();
 
 	// Set the timer last, after everything has been initialised
-	_engine->_system->set_timer(10, &timer_handler);
+	_system->set_timer(10, &timer_handler);
 
 }
 
 Timer::~Timer() {
-	_engine->_system->set_timer(0, NULL);
+	_system->set_timer(0, NULL);
 
-	_engine->_system->lock_mutex(_mutex);
-	for (int i = 0; i < MAX_TIMERS; i++) {
-		_timerSlots[i].procedure = NULL;
-		_timerSlots[i].interval = 0;
-		_timerSlots[i].counter = 0;
+	{
+		StackLock lock(_mutex);
+		for (int i = 0; i < MAX_TIMERS; i++) {
+			_timerSlots[i].procedure = NULL;
+			_timerSlots[i].interval = 0;
+			_timerSlots[i].counter = 0;
+		}
 	}
-	_engine->_system->unlock_mutex(_mutex);
+
 
 	// FIXME: There is still a potential race condition here, depending on how
 	// the system backend implements set_timer: If timers are done using
@@ -68,7 +71,7 @@
 	// it is still waiting for the _mutex. So, again depending on the backend,
 	// we might end up unlocking the mutex then immediately deleting it, while
 	// the timer thread is about to lock it.
-	_engine->_system->delete_mutex(_mutex);
+	_system->delete_mutex(_mutex);
 }
 
 int Timer::timer_handler(int t) {
@@ -78,12 +81,11 @@
 }
 
 int Timer::handler(int t) {
+	StackLock lock(_mutex);
 	uint32 interval, l;
 
-	_engine->_system->lock_mutex(_mutex);
-
 	_lastTime = _thisTime;
-	_thisTime = _engine->_system->get_msecs();
+	_thisTime = _system->get_msecs();
 	interval = 1000 * (_thisTime - _lastTime);
 
 	for (l = 0; l < MAX_TIMERS; l++) {
@@ -91,31 +93,29 @@
 			_timerSlots[l].counter -= interval;
 			if (_timerSlots[l].counter <= 0) {
 				_timerSlots[l].counter += _timerSlots[l].interval;
-				_timerSlots[l].procedure(_engine);
+				_timerSlots[l].procedure(_timerSlots[l].refCon);
 			}
 		}
 	}
 
-	_engine->_system->unlock_mutex(_mutex);
-
 	return t;
 }
 
-bool Timer::installProcedure (TimerProc procedure, int32 interval) {
+bool Timer::installProcedure(TimerProc procedure, int32 interval, void *refCon) {
+	StackLock lock(_mutex);
 	int32 l;
 	bool found = false;
 
-	_engine->_system->lock_mutex(_mutex);
 	for (l = 0; l < MAX_TIMERS; l++) {
 		if (!_timerSlots[l].procedure) {
 			_timerSlots[l].procedure = procedure;
 			_timerSlots[l].interval = interval;
 			_timerSlots[l].counter = interval;
+			_timerSlots[l].refCon = refCon;
 			found = true;
 			break;
 		}
 	}
-	_engine->_system->unlock_mutex(_mutex);
 
 	if (!found)
 		warning("Couldn't find free timer slot!");
@@ -123,18 +123,18 @@
 	return found;
 }
 
-void Timer::releaseProcedure (TimerProc procedure) {
+void Timer::releaseProcedure(TimerProc procedure) {
+	StackLock lock(_mutex);
 	int32 l;
 
-	_engine->_system->lock_mutex(_mutex);
 	for (l = 0; l < MAX_TIMERS; l++) {
 		if (_timerSlots[l].procedure == procedure) {
 			_timerSlots[l].procedure = 0;
 			_timerSlots[l].interval = 0;
 			_timerSlots[l].counter = 0;
+			_timerSlots[l].refCon = 0;
 		}
 	}
-	_engine->_system->unlock_mutex(_mutex);
 }
 
 #endif

Index: engine.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/engine.cpp,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- engine.cpp	8 Sep 2003 17:46:54 -0000	1.37
+++ engine.cpp	10 Sep 2003 12:43:53 -0000	1.38
@@ -41,7 +41,7 @@
 
 	g_system = _system; // FIXME - BIG HACK for MidiEmu
 
-	_timer = new Timer(this);
+	_timer = new Timer(_system);
 }
 
 Engine::~Engine() {





More information about the Scummvm-git-logs mailing list