summaryrefslogtreecommitdiff
path: root/lib/common/Timer.cpp
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-09-04 01:36:13 +0000
committerChris Wilson <chris+github@qwirx.com>2014-09-04 01:36:13 +0000
commita134f6eca8102400f41ae0a1e2e9ab3236b1649b (patch)
tree614ed773d8a00bc8d6c1c4a7c296877adfd878a2 /lib/common/Timer.cpp
parent426a506afd1ffb3bd67e61b4693ee9bb968097a1 (diff)
Backport Timers::Cleanup that's safe to use in test cleanup.
Allows it not to throw an exception if timers weren't initialised when cleanup was requested. Normally we want an exception thrown, but not while we're cleaning up a test that might have failed with timers uninitialised. More timers fixes after cleanup no-exception option. Merged back changes from the test refactor branch to reduce diffs.
Diffstat (limited to 'lib/common/Timer.cpp')
-rw-r--r--lib/common/Timer.cpp50
1 files changed, 44 insertions, 6 deletions
diff --git a/lib/common/Timer.cpp b/lib/common/Timer.cpp
index 68042db2..e0a4b7f7 100644
--- a/lib/common/Timer.cpp
+++ b/lib/common/Timer.cpp
@@ -72,13 +72,23 @@ void Timers::Init()
// Created: 6/11/2006
//
// --------------------------------------------------------------------------
-void Timers::Cleanup()
+void Timers::Cleanup(bool throw_exception_if_not_initialised)
{
- ASSERT(spTimers);
- if (!spTimers)
+ if (throw_exception_if_not_initialised)
{
- BOX_ERROR("Tried to clean up timers when not initialised!");
- return;
+ ASSERT(spTimers);
+ if (!spTimers)
+ {
+ BOX_ERROR("Tried to clean up timers when not initialised!");
+ return;
+ }
+ }
+ else
+ {
+ if (!spTimers)
+ {
+ return;
+ }
}
#if defined WIN32 && ! defined PLATFORM_CYGWIN
@@ -110,6 +120,26 @@ void Timers::Cleanup()
// --------------------------------------------------------------------------
//
// Function
+// Name: static void Timers::AssertInitialised()
+// Purpose: Throw an assertion error if timers are not ready
+// NOW. It's a common mistake (for me) when writing
+// tests to forget to initialise timers first.
+// Created: 15/05/2014
+//
+// --------------------------------------------------------------------------
+
+void Timers::AssertInitialised()
+{
+ if (!spTimers)
+ {
+ THROW_EXCEPTION(CommonException, TimersNotInitialised);
+ }
+ ASSERT(spTimers);
+}
+
+// --------------------------------------------------------------------------
+//
+// Function
// Name: static void Timers::Add(Timer&)
// Purpose: Add a new timer to the set, and reschedule next wakeup
// Created: 5/11/2006
@@ -135,8 +165,16 @@ void Timers::Add(Timer& rTimer)
// --------------------------------------------------------------------------
void Timers::Remove(Timer& rTimer)
{
- ASSERT(spTimers);
ASSERT(&rTimer);
+
+ if(!spTimers)
+ {
+ BOX_WARNING(TIMER_ID_OF(rTimer) " was still active after "
+ "timer subsystem was cleaned up, already removed.");
+ return;
+ }
+
+ ASSERT(spTimers);
BOX_TRACE(TIMER_ID_OF(rTimer) " removed from global queue, rescheduling");
bool restart = true;