Some work towards clean shudown

This commit is contained in:
JoelKatz
2013-07-02 21:28:15 -07:00
parent 582c2758b0
commit c091e80e11
3 changed files with 26 additions and 3 deletions

View File

@@ -333,6 +333,7 @@ void Application::stop ()
mEphemeralLDB = NULL;
WriteLog (lsINFO, Application) << "Stopped: " << mIOService.stopped ();
mShutdown = false;
}
static void InitDB (DatabaseCon** dbCon, const char* fileName, const char* dbInit[], int dbCount)
@@ -665,7 +666,12 @@ void Application::run ()
if (mWSPrivateDoor)
mWSPrivateDoor->stop ();
getApp().getLoadManager().stopThread();
mSweepTimer.cancel();
WriteLog (lsINFO, Application) << "Done.";
while (mShutdown)
boost::this_thread::sleep (boost::posix_time::milliseconds (100));
}
void Application::sweep ()

View File

@@ -224,6 +224,7 @@ public:
*/
// VFALCO TODO Simplify the two stage initialization to one stage (construction).
virtual void startThread () = 0;
virtual void stopThread () = 0;
/** Turn on deadlock detection.

View File

@@ -67,6 +67,7 @@ public:
, mDebitWarn (-500)
, mDebitLimit (-1000)
, mArmed (false)
, mRunning (false)
, mDeadLock (0)
, mCosts (LT_MAX)
{
@@ -116,7 +117,11 @@ private:
{
UptimeTimer::getInstance ().endManualUpdates ();
if (mRunning)
{
m_thread.interrupt ();
m_thread.join ();
}
}
void startThread ()
@@ -124,6 +129,17 @@ private:
UptimeTimer::getInstance ().beginManualUpdates ();
m_thread.start (this);
mRunning = true;
}
void stopThread()
{
if (mRunning)
{
m_thread.interrupt ();
m_thread.join ();
mRunning = false;
}
}
void canonicalize (LoadSource& source, int now) const
@@ -401,7 +417,7 @@ private:
int mDebitWarn; // when a source drops below this, we warn
int mDebitLimit; // when a source drops below this, we cut it off (should be negative)
bool mArmed;
bool mArmed, mRunning;
int mDeadLock; // Detect server deadlocks