[Scummvm-cvs-logs] CVS: scummvm/common system.h,1.62,1.63 timer.cpp,1.28,1.29

Max Horn fingolfin at users.sourceforge.net
Sat Mar 27 10:42:07 CET 2004


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

Modified Files:
	system.h timer.cpp 
Log Message:
clarify OSystem specification (setTimerCallback() must be 'atomic')

Index: system.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/system.h,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- system.h	16 Mar 2004 08:24:58 -0000	1.62
+++ system.h	27 Mar 2004 18:30:30 -0000	1.63
@@ -421,9 +421,14 @@
 	 * the previous one. In particular, passing a callback pointer value of 0
 	 * is legal and can be used to clear the current timer callback.
 	 * @see Common::Timer
+	 * @note The implementation of this method must be 'atomic' in the sense
+	 *       that when the method returns, the previously set callback must
+	 *       not be in use anymore (in particular, if timers are implemented
+	 *       via threads, then it must be ensured that the timer thread is
+	 *       not using the old callback function anymore).
 	 *
 	 * @param callback	pointer to the callback. May be 0 to reset the timer
-	 * @param interval	the intervall (in milliseconds) between invocations
+	 * @param interval	the interval (in milliseconds) between invocations
 	 *                  of the callback
 	 */
 	virtual void setTimerCallback(TimerProc callback, int interval) = 0;

Index: timer.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/timer.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- timer.cpp	27 Mar 2004 18:22:36 -0000	1.28
+++ timer.cpp	27 Mar 2004 18:30:30 -0000	1.29
@@ -51,6 +51,9 @@
 }
 
 Timer::~Timer() {
+	// Remove the timer callback. 
+	// Note: backends *must* gurantee that after this method call returns,
+	// the handler is not in use anymore; else race condtions could occurs.
 	_system->setTimerCallback(0, 0);
 
 	{
@@ -62,15 +65,6 @@
 		}
 	}
 
-
-	// FIXME: There is still a potential race condition here, depending on how
-	// the system backend implements setTimerCallback: If timers are done using
-	// threads, and if setTimerCallback does *not* gurantee that after it terminates
-	// that timer thread is not run anymore, we are fine. However, if the timer
-	// is still running in parallel to this destructor, then it might be that
-	// 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.
 	_system->deleteMutex(_mutex);
 }
 





More information about the Scummvm-git-logs mailing list