diff --git a/src/cpp/ripple/ripple_Application.cpp b/src/cpp/ripple/ripple_Application.cpp index 3d6f011182..2d8fdef005 100644 --- a/src/cpp/ripple/ripple_Application.cpp +++ b/src/cpp/ripple/ripple_Application.cpp @@ -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) @@ -469,7 +470,7 @@ void Application::setup () { getApp().getHashNodeDB ()->getDB ()->executeSQL (boost::str (boost::format ("PRAGMA cache_size=-%d;") % (theConfig.getSize (siHashNodeDBCache) * 1024))); - getApp().getHashNodeDB ()->getDB ()->setupCheckpointing (&mJobQueue); + getApp().getHashNodeDB ()->getDB ()->setupCheckpointing (&mJobQueue); } getApp().getLedgerDB ()->getDB ()->executeSQL (boost::str (boost::format ("PRAGMA cache_size=-%d;") % @@ -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 () diff --git a/src/cpp/ripple/ripple_ILoadManager.h b/src/cpp/ripple/ripple_ILoadManager.h index 54e24350eb..002ad7814e 100644 --- a/src/cpp/ripple/ripple_ILoadManager.h +++ b/src/cpp/ripple/ripple_ILoadManager.h @@ -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. diff --git a/src/cpp/ripple/ripple_LoadManager.cpp b/src/cpp/ripple/ripple_LoadManager.cpp index c4dd829184..76163ad0d3 100644 --- a/src/cpp/ripple/ripple_LoadManager.cpp +++ b/src/cpp/ripple/ripple_LoadManager.cpp @@ -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 (); - m_thread.interrupt (); + 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