summaryrefslogtreecommitdiff
path: root/lib/common/Timer.cpp
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2007-01-14 20:29:49 +0000
committerChris Wilson <chris+github@qwirx.com>2007-01-14 20:29:49 +0000
commit961deddb62406b1824d00c5278384b2e5d4f5988 (patch)
tree06afd01c93c624794d39307a32e7b50c6228fc2f /lib/common/Timer.cpp
parent7adebdfb61eced2905d3606d829de9e129ab6e39 (diff)
Don't do things with essential side effects inside ASSERT() macros
(refs #3, refs #9)
Diffstat (limited to 'lib/common/Timer.cpp')
-rw-r--r--lib/common/Timer.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/common/Timer.cpp b/lib/common/Timer.cpp
index dcfe2ce2..4b596931 100644
--- a/lib/common/Timer.cpp
+++ b/lib/common/Timer.cpp
@@ -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 @@ void Timers::Init()
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 @@ void Timers::Cleanup()
#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::Remove(Timer& rTimer)
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