[Box Backup-commit] COMMIT r1246 - box/chris/merge/lib/common

boxbackup-dev at fluffy.co.uk boxbackup-dev at fluffy.co.uk
Sun Jan 14 20:29:49 GMT 2007


Author: chris
Date: 2007-01-14 20:29:49 +0000 (Sun, 14 Jan 2007)
New Revision: 1246

Modified:
   box/chris/merge/lib/common/Timer.cpp
Log:
Don't do things with essential side effects inside ASSERT() macros 
(refs #3, refs #9)


Modified: box/chris/merge/lib/common/Timer.cpp
===================================================================
--- box/chris/merge/lib/common/Timer.cpp	2007-01-14 20:28:27 UTC (rev 1245)
+++ box/chris/merge/lib/common/Timer.cpp	2007-01-14 20:29:49 UTC (rev 1246)
@@ -13,12 +13,15 @@
 #include <signal.h>
 
 #include "Timer.h"
+#include "Logging.h"
 
 #include "MemLeakFindOn.h"
 
 std::vector<Timer*>* Timers::spTimers = NULL;
 bool Timers::sRescheduleNeeded = false;
 
+typedef void (*sighandler_t)(int);
+
 // --------------------------------------------------------------------------
 //
 // Function
@@ -36,7 +39,9 @@
 		InitTimer();
 		SetTimerHandler(Timers::SignalHandler);
 	#else
-		ASSERT(::signal(SIGALRM, Timers::SignalHandler) == 0);
+		sighandler_t oldHandler = ::signal(SIGALRM, 
+			Timers::SignalHandler);
+		ASSERT(oldHandler == 0);
 	#endif // WIN32 && !PLATFORM_CYGWIN
 	
 	spTimers = new std::vector<Timer*>;
@@ -61,8 +66,12 @@
 	#else
 		struct itimerval timeout;
 		memset(&timeout, 0, sizeof(timeout));
-		ASSERT(::setitimer(ITIMER_REAL, &timeout, NULL) == 0);
-		ASSERT(::signal(SIGALRM, NULL) == Timers::SignalHandler);
+
+		int result = ::setitimer(ITIMER_REAL, &timeout, NULL);
+		ASSERT(result == 0);
+
+		sighandler_t oldHandler = ::signal(SIGALRM, NULL);
+		ASSERT(oldHandler == Timers::SignalHandler);
 	#endif // WIN32 && !PLATFORM_CYGWIN
 
 	spTimers->clear();
@@ -128,6 +137,14 @@
 void Timers::Reschedule()
 {
 	ASSERT(spTimers);
+	if (spTimers == NULL)
+	{
+		THROW_EXCEPTION(CommonException, Internal)
+	}
+	if (::signal(SIGALRM, Timers::SignalHandler) != Timers::SignalHandler)
+	{
+		THROW_EXCEPTION(CommonException, Internal)
+	}
 
 	// Clear the reschedule-needed flag to false before we start.
 	// If a timer event occurs while we are scheduling, then we




More information about the Boxbackup-commit mailing list