[Box Backup-commit] COMMIT r3378 - in box/trunk: bin/bbackupd infrastructure lib/common
subversion at boxbackup.org
subversion at boxbackup.org
Thu Sep 4 02:36:13 BST 2014
Author: chris
Date: 2014-09-04 02:36:13 +0100 (Thu, 04 Sep 2014)
New Revision: 3378
Modified:
box/trunk/bin/bbackupd/BackupDaemon.cpp
box/trunk/infrastructure/buildenv-testmain-template.cpp
box/trunk/lib/common/CommonException.txt
box/trunk/lib/common/Timer.cpp
box/trunk/lib/common/Timer.h
Log:
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.
Modified: box/trunk/bin/bbackupd/BackupDaemon.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupDaemon.cpp 2014-09-04 01:36:08 UTC (rev 3377)
+++ box/trunk/bin/bbackupd/BackupDaemon.cpp 2014-09-04 01:36:13 UTC (rev 3378)
@@ -490,6 +490,7 @@
"exception, ignored.");
}
+ mapCommandSocketPollTimer.reset();
Timers::Cleanup();
throw;
@@ -497,6 +498,7 @@
// Clean up
mapCommandSocketInfo.reset();
+ mapCommandSocketPollTimer.reset();
Timers::Cleanup();
}
Modified: box/trunk/infrastructure/buildenv-testmain-template.cpp
===================================================================
--- box/trunk/infrastructure/buildenv-testmain-template.cpp 2014-09-04 01:36:08 UTC (rev 3377)
+++ box/trunk/infrastructure/buildenv-testmain-template.cpp 2014-09-04 01:36:13 UTC (rev 3378)
@@ -407,7 +407,7 @@
Timers::Init();
int returncode = test(argc, (const char **)argv);
- Timers::Cleanup();
+ Timers::Cleanup(false);
fflush(stdout);
fflush(stderr);
Modified: box/trunk/lib/common/CommonException.txt
===================================================================
--- box/trunk/lib/common/CommonException.txt 2014-09-04 01:36:08 UTC (rev 3377)
+++ box/trunk/lib/common/CommonException.txt 2014-09-04 01:36:13 UTC (rev 3378)
@@ -55,3 +55,4 @@
DatabaseRecordBadSize 48 The database contains a record with an invalid size
DatabaseIterateFailed 49 Failed to iterate over the database keys
ReferenceNotFound 50 The database does not contain an expected reference
+TimersNotInitialised 51 The timer framework should have been ready at this point
Modified: box/trunk/lib/common/Timer.cpp
===================================================================
--- box/trunk/lib/common/Timer.cpp 2014-09-04 01:36:08 UTC (rev 3377)
+++ box/trunk/lib/common/Timer.cpp 2014-09-04 01:36:13 UTC (rev 3378)
@@ -72,14 +72,24 @@
// 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
// no cleanup needed
@@ -110,6 +120,26 @@
// --------------------------------------------------------------------------
//
// 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::Remove(Timer& rTimer)
{
+ ASSERT(&rTimer);
+
+ if(!spTimers)
+ {
+ BOX_WARNING(TIMER_ID_OF(rTimer) " was still active after "
+ "timer subsystem was cleaned up, already removed.");
+ return;
+ }
+
ASSERT(spTimers);
- ASSERT(&rTimer);
BOX_TRACE(TIMER_ID_OF(rTimer) " removed from global queue, rescheduling");
bool restart = true;
Modified: box/trunk/lib/common/Timer.h
===================================================================
--- box/trunk/lib/common/Timer.h 2014-09-04 01:36:08 UTC (rev 3377)
+++ box/trunk/lib/common/Timer.h 2014-09-04 01:36:13 UTC (rev 3378)
@@ -43,7 +43,8 @@
public:
static void Init();
- static void Cleanup();
+ static void Cleanup(bool throw_exception_if_not_initialised = true);
+ static void AssertInitialised();
static void Add (Timer& rTimer);
static void Remove(Timer& rTimer);
static void RequestReschedule();
More information about the Boxbackup-commit
mailing list