diff --git a/BeastConfig.h b/BeastConfig.h index 29fd83645..d31678c8b 100644 --- a/BeastConfig.h +++ b/BeastConfig.h @@ -12,12 +12,22 @@ //#define BEAST_LOG_ASSERTIONS 1 #endif -#ifndef BEAST_CHECK_MEMORY_LEAKS - //#define BEAST_CHECK_MEMORY_LEAKS +#ifndef BEAST_CHECK_MEMORY_LEAKS +#define BEAST_CHECK_MEMORY_LEAKS 1 #endif #ifndef BEAST_DONT_AUTOLINK_TO_WIN32_LIBRARIES //#define BEAST_DONT_AUTOLINK_TO_WIN32_LIBRARIES #endif +// beast_basics flags + +#ifndef BEAST_USE_BOOST +#define BEAST_USE_BOOST 0 +#endif + +#ifndef BEAST_USE_LEAKCHECKED +#define BEAST_USE_LEAKCHECKED BEAST_CHECK_MEMORY_LEAKS +#endif + #endif diff --git a/Builds/VisualStudio2012/RippleD.vcxproj b/Builds/VisualStudio2012/RippleD.vcxproj index fe9bb96f6..2c8ef11bb 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj +++ b/Builds/VisualStudio2012/RippleD.vcxproj @@ -1577,10 +1577,10 @@ true - true - true - true - true + false + false + false + false diff --git a/SConstruct b/SConstruct index 6a3ce2871..93ee8531a 100644 --- a/SConstruct +++ b/SConstruct @@ -113,6 +113,7 @@ INCLUDE_PATHS = [ COMPILED_FILES = [ 'Subtrees/beast/modules/beast_core/beast_core.cpp', + 'Subtrees/beast/modules/beast_basics/beast_basics.cpp', 'modules/ripple_basics/ripple_basics.cpp', 'modules/ripple_core/ripple_core.cpp', 'modules/ripple_data/ripple_data.cpp', diff --git a/TODO.txt b/TODO.txt index 9b2f40516..29fce90d6 100644 --- a/TODO.txt +++ b/TODO.txt @@ -2,6 +2,25 @@ TODO -------------------------------------------------------------------------------- +- Fix all leaks on exit (!) + + Say there's a leak, a ledger that can never be accessed is locked in some + structure. If the organized teardown code frees that structure, the leak + will not be reported. + Yes, so you'll detect some small subset of leaks that way. + You'll still have to be vigilant for the leaks that won't detect. + The problem is ordering. There are lots of circular dependencies. + The biggest problem is the order of destruction of global objects. (I think) + Getting rid of global objects is a good solution to that. + Vinnie Falco: Those I can resolve with my ReferenceCountedSingleton. And + yeah thats a good approach, one that I am doing slowly anyway + Yeah, that's good for other reasons too, not just the unpredictability of + creation order that can hide bugs. + There may also just be some missing destructors. + Some of it may be things being shut down in the wrong order. Like if you shut + down the cache and then something that uses the cache, objects may get + put in the cache after it was shut down. + - Remove "ENABLE_INSECURE" when the time is right. - lift bind, function, and placeholders into ripple namespace diff --git a/modules/ripple_basics/ripple_basics.h b/modules/ripple_basics/ripple_basics.h index e9e24b1ac..5c605e588 100644 --- a/modules/ripple_basics/ripple_basics.h +++ b/modules/ripple_basics/ripple_basics.h @@ -40,6 +40,7 @@ #include "BeastConfig.h" // Must come before any Beast includes #include "modules/beast_core/beast_core.h" +#include "modules/beast_basics/beast_basics.h" // VFALCO TODO Fix this for FreeBSD //#include "modules/beast_basics/beast_basics.h" @@ -49,6 +50,11 @@ namespace ripple { +// VFALCO TODO Make this work. We have to get rid of BIND_TYPE, +// FUNC_TYPE, and P_* placeholders. +// +//using namespace beast; + using beast::int16; using beast::int32; using beast::int64; diff --git a/src/cpp/ripple/ripple_LoadManager.cpp b/src/cpp/ripple/ripple_LoadManager.cpp index 6bd6004c1..ebc1e412f 100644 --- a/src/cpp/ripple/ripple_LoadManager.cpp +++ b/src/cpp/ripple/ripple_LoadManager.cpp @@ -8,7 +8,9 @@ SETUP_LOG (LoadManager) //------------------------------------------------------------------------------ -class LoadManager : public ILoadManager +class LoadManager + : public ILoadManager + , public beast::InterruptibleThread::EntryPoint { private: /* Entry mapping utilization to cost. @@ -58,15 +60,18 @@ private: public: LoadManager () - : mCreditRate (100) + : m_thread ("loadmgr") + , m_logThread ("loadmgr_log") + , mCreditRate (100) , mCreditLimit (500) , mDebitWarn (-500) , mDebitLimit (-1000) - , mShutdown (false) , mArmed (false) , mDeadLock (0) , mCosts (LT_MAX) { + m_logThread.start (); + /** Flags indicating the type of load. Utilization may include any combination of: @@ -111,25 +116,14 @@ private: { UptimeTimer::getInstance ().endManualUpdates (); - // VFALCO TODO What is the purpose of this loop? Figure out - // a better way to do it. - for (;;) - { - boost::this_thread::sleep (boost::posix_time::milliseconds (100)); - { - boost::mutex::scoped_lock sl (mLock); - - if (!mShutdown) - return; - } - } + m_thread.interrupt (); } void startThread () { UptimeTimer::getInstance ().beginManualUpdates (); - boost::thread (boost::bind (&LoadManager::threadEntry, this)).detach (); + m_thread.start (this); } void canonicalize (LoadSource& source, int now) const @@ -315,29 +309,19 @@ private: // VFALCO NOTE Where's the thread object? It's not a data member... // - void threadEntry () + void threadRun () { - setCallingThreadName ("loadmgr"); - // VFALCO TODO replace this with a beast Time object? // // Initialize the clock to the current time. boost::posix_time::ptime t = boost::posix_time::microsec_clock::universal_time (); - for (;;) + while (! m_thread.interruptionPoint ()) { { // VFALCO NOTE What is this lock protecting? boost::mutex::scoped_lock sl (mLock); - // Check for the shutdown flag. - if (mShutdown) - { - // VFALCO NOTE Why clear the flag now? - mShutdown = false; - return; - } - // VFALCO NOTE I think this is to reduce calls to the operating system // for retrieving the current time. // @@ -361,7 +345,7 @@ private: { // VFALCO TODO Replace this with a dedicated thread with call queue. // - boost::thread (BIND_TYPE (&logDeadlock, timeSpentDeadlocked)).detach (); + m_logThread.call (&logDeadlock, timeSpentDeadlocked); } // If we go over 500 seconds spent deadlocked, it means that the @@ -370,7 +354,6 @@ private: // assert (timeSpentDeadlocked < 500); } - } bool change; @@ -403,17 +386,21 @@ private: t = boost::posix_time::microsec_clock::universal_time (); } else + { boost::this_thread::sleep (when); + } } } private: + beast::InterruptibleThread m_thread; + beast::ThreadWithCallQueue m_logThread; + int mCreditRate; // credits gained/lost per second int mCreditLimit; // the most credits a source can have 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 mShutdown; bool mArmed; int mDeadLock; // Detect server deadlocks