From f14333012bd944052c264d206ef8ebcaa69dc7e0 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 22 Aug 2013 21:31:22 -0700 Subject: [PATCH] Use RippleMutex instead of boost::mutex --- BeastConfig.h | 17 +++- Builds/VisualStudio2012/RippleD.vcxproj | 1 - .../VisualStudio2012/RippleD.vcxproj.filters | 3 - .../consensus/ripple_LedgerConsensus.cpp | 2 +- modules/ripple_app/data/ripple_DatabaseCon.h | 5 +- .../ripple_app/data/ripple_SqliteDatabase.cpp | 7 +- .../ripple_app/data/ripple_SqliteDatabase.h | 5 +- modules/ripple_app/ledger/Ledger.cpp | 43 +++++---- modules/ripple_app/ledger/Ledger.h | 29 ++++-- modules/ripple_app/ledger/LedgerMaster.cpp | 54 +++++------ modules/ripple_app/ledger/LedgerMaster.h | 21 +++-- modules/ripple_app/ledger/OrderBookDB.cpp | 31 ++++--- modules/ripple_app/ledger/OrderBookDB.h | 10 +- .../ledger/ripple_AcceptedLedger.cpp | 2 +- .../ripple_app/ledger/ripple_AcceptedLedger.h | 2 +- .../ledger/ripple_InboundLedger.cpp | 24 ++--- .../ripple_app/ledger/ripple_InboundLedger.h | 2 +- .../ledger/ripple_InboundLedgers.cpp | 24 +++-- .../ripple_app/ledger/ripple_InboundLedgers.h | 10 +- .../ledger/ripple_LedgerHistory.cpp | 10 +- .../ripple_app/ledger/ripple_LedgerHistory.h | 2 +- .../ripple_app/main/ripple_Application.cpp | 7 +- modules/ripple_app/main/ripple_Application.h | 92 +------------------ .../ripple_app/main/ripple_LoadManager.cpp | 54 ++++++----- .../main/ripple_LocalCredentials.cpp | 10 +- modules/ripple_app/misc/NetworkOPs.cpp | 45 ++++----- modules/ripple_app/misc/NetworkOPs.h | 9 +- modules/ripple_app/misc/ripple_Features.cpp | 43 +++++---- modules/ripple_app/misc/ripple_HashRouter.cpp | 23 +++-- modules/ripple_app/misc/ripple_InfoSub.cpp | 9 +- modules/ripple_app/misc/ripple_InfoSub.h | 9 +- .../misc/ripple_ProofOfWorkFactory.cpp | 18 ++-- .../misc/ripple_ProofOfWorkFactory.h | 5 +- .../ripple_app/misc/ripple_Validations.cpp | 71 +++++++------- modules/ripple_app/network/WSConnection.h | 21 +++-- modules/ripple_app/network/WSDoor.cpp | 7 +- modules/ripple_app/network/WSDoor.h | 5 +- modules/ripple_app/network/ripple_WSHandler.h | 34 +++++-- modules/ripple_app/node/ripple_NodeStore.cpp | 2 +- .../node/ripple_SqliteBackendFactory.cpp | 4 +- .../ripple_app/paths/ripple_PathRequest.cpp | 27 +++--- modules/ripple_app/paths/ripple_PathRequest.h | 14 ++- .../paths/ripple_RippleLineCache.cpp | 8 +- .../ripple_app/paths/ripple_RippleLineCache.h | 11 +-- modules/ripple_app/peers/ripple_PeerSet.cpp | 13 +-- modules/ripple_app/peers/ripple_PeerSet.h | 8 +- modules/ripple_app/peers/ripple_Peers.cpp | 44 +++++---- .../peers/ripple_UniqueNodeList.cpp | 84 +++++++++-------- modules/ripple_app/rpc/RPCHandler.cpp | 2 +- modules/ripple_app/rpc/RPCSub.cpp | 4 +- modules/ripple_app/rpc/RPCSub.h | 4 +- modules/ripple_app/shamap/ripple_SHAMap.cpp | 48 ++++++---- modules/ripple_app/shamap/ripple_SHAMap.h | 14 ++- .../ripple_app/shamap/ripple_SHAMapDelta.cpp | 4 +- .../ripple_app/shamap/ripple_SHAMapSync.cpp | 27 +++--- modules/ripple_app/tx/Transaction.cpp | 2 +- modules/ripple_app/tx/TransactionMaster.h | 2 +- modules/ripple_app/tx/TransactionQueue.cpp | 16 +++- modules/ripple_app/tx/TransactionQueue.h | 10 +- modules/ripple_app/tx/Transactor.cpp | 2 +- .../tx/ripple_TransactionAcquire.cpp | 4 +- .../ripple_app/tx/ripple_TransactionAcquire.h | 2 +- .../containers/ripple_KeyCache.h | 42 +++++---- .../containers/ripple_TaggedCache.h | 80 +++++++++------- modules/ripple_basics/ripple_basics.h | 8 +- .../ripple_basics/types/ripple_BasicTypes.h | 14 +++ modules/ripple_basics/utility/ripple_Log.cpp | 21 +++-- modules/ripple_basics/utility/ripple_Log.h | 7 +- .../ripple_basics/utility/ripple_ScopedLock.h | 85 ----------------- .../functional/ripple_JobQueue.cpp | 21 +++-- .../ripple_core/functional/ripple_JobQueue.h | 7 +- .../functional/ripple_LoadFeeTrack.h | 33 ++++--- .../functional/ripple_LoadMonitor.cpp | 13 +-- .../functional/ripple_LoadMonitor.h | 5 +- .../protocol/ripple_FieldNames.cpp | 15 ++- .../ripple_data/protocol/ripple_FieldNames.h | 14 ++- .../protocol/ripple_RippleAddress.cpp | 7 +- .../ripple_net/basics/ripple_SNTPClient.cpp | 20 ++-- modules/ripple_net/basics/ripple_SNTPClient.h | 5 +- 79 files changed, 798 insertions(+), 721 deletions(-) delete mode 100644 modules/ripple_basics/utility/ripple_ScopedLock.h diff --git a/BeastConfig.h b/BeastConfig.h index 54cefe5c0a..c48de1367e 100644 --- a/BeastConfig.h +++ b/BeastConfig.h @@ -170,10 +170,19 @@ //#define RIPPLE_VERIFY_NODEOBJECT_KEYS 1 #endif +//------------------------------------------------------------------------------ + +/** Config: RIPPLE_TRACK_MUTEXES + + Turns on a feature that enables tracking and diagnostics for mutex + and recursive mutex objects. This affects the type of lock used + by RippleMutex and RippleRecursiveMutex +*/ +#define RIPPLE_TRACK_MUTEXES 0 + +//------------------------------------------------------------------------------ + +// This is temporary and will disappear #define RIPPLE_USES_BEAST_SOCKETS 0 - -//#define BEAST_ASIO_HAS_BUFFEREDHANDSHAKE 0 -//#define BEAST_ASIO_HAS_FUTURE_RETURNS 0 - #endif diff --git a/Builds/VisualStudio2012/RippleD.vcxproj b/Builds/VisualStudio2012/RippleD.vcxproj index d3d3b080a2..43b3e6d94c 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj +++ b/Builds/VisualStudio2012/RippleD.vcxproj @@ -1507,7 +1507,6 @@ - diff --git a/Builds/VisualStudio2012/RippleD.vcxproj.filters b/Builds/VisualStudio2012/RippleD.vcxproj.filters index 048232b075..ae0d64488f 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2012/RippleD.vcxproj.filters @@ -1442,9 +1442,6 @@ [1] Ripple\ripple_app\node - - [1] Ripple\ripple_basics\utility - [1] Ripple\ripple_core\functional diff --git a/modules/ripple_app/consensus/ripple_LedgerConsensus.cpp b/modules/ripple_app/consensus/ripple_LedgerConsensus.cpp index d774c2678a..836af16990 100644 --- a/modules/ripple_app/consensus/ripple_LedgerConsensus.cpp +++ b/modules/ripple_app/consensus/ripple_LedgerConsensus.cpp @@ -1280,7 +1280,7 @@ void LedgerConsensus::accept (SHAMap::ref set, LoadEvent::pointer) WriteLog (lsINFO, LedgerConsensus) << "CNF newLCL " << newLCLHash; Ledger::pointer newOL = boost::make_shared (true, boost::ref (*newLCL)); - ScopedLock sl ( getApp().getLedgerMaster ().getLock ()); + LedgerMaster::ScopedLockType sl (getApp().getLedgerMaster ().peekMutex (), __FILE__, __LINE__); // Apply disputed transactions that didn't get in TransactionEngine engine (newOL); diff --git a/modules/ripple_app/data/ripple_DatabaseCon.h b/modules/ripple_app/data/ripple_DatabaseCon.h index e1b473a791..34c1a2576c 100644 --- a/modules/ripple_app/data/ripple_DatabaseCon.h +++ b/modules/ripple_app/data/ripple_DatabaseCon.h @@ -18,7 +18,7 @@ public: { return mDatabase; } - boost::recursive_mutex& getDBLock () + DeprecatedRecursiveMutex& getDBLock () { return mLock; } @@ -30,8 +30,7 @@ public: // VFALCO TODO change "protected" to "private" throughout the code private: Database* mDatabase; - // VFALCO TODO replace these with a single atomic counter. - boost::recursive_mutex mLock; + DeprecatedRecursiveMutex mLock; static int sCount; }; diff --git a/modules/ripple_app/data/ripple_SqliteDatabase.cpp b/modules/ripple_app/data/ripple_SqliteDatabase.cpp index 385f67d632..2724ffa4a7 100644 --- a/modules/ripple_app/data/ripple_SqliteDatabase.cpp +++ b/modules/ripple_app/data/ripple_SqliteDatabase.cpp @@ -37,6 +37,7 @@ SqliteStatement::~SqliteStatement () SqliteDatabase::SqliteDatabase (const char* host) : Database (host) + , m_walMutex (this, "SqliteDB", __FILE__, __LINE__) , m_thread ("sqlitedb") , mWalQ (NULL) , walRunning (false) @@ -62,7 +63,7 @@ void SqliteDatabase::connect () sqlite3* SqliteDatabase::getAuxConnection () { - boost::mutex::scoped_lock sl (walMutex); + ScopedLockType sl (m_walMutex, __FILE__, __LINE__); if (mAuxConnection == NULL) { @@ -286,7 +287,7 @@ void SqliteDatabase::doHook (const char* db, int pages) return; { - boost::mutex::scoped_lock sl (walMutex); + ScopedLockType sl (m_walMutex, __FILE__, __LINE__); if (walRunning) return; @@ -319,7 +320,7 @@ void SqliteDatabase::runWal () "): frames=" << log << ", written=" << ckpt; { - boost::mutex::scoped_lock sl (walMutex); + ScopedLockType sl (m_walMutex, __FILE__, __LINE__); walRunning = false; } } diff --git a/modules/ripple_app/data/ripple_SqliteDatabase.h b/modules/ripple_app/data/ripple_SqliteDatabase.h index e5e171825b..d28b301b96 100644 --- a/modules/ripple_app/data/ripple_SqliteDatabase.h +++ b/modules/ripple_app/data/ripple_SqliteDatabase.h @@ -59,6 +59,10 @@ public: int getKBUsedAll (); private: + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType m_walMutex; + ThreadWithCallQueue m_thread; sqlite3* mConnection; @@ -67,7 +71,6 @@ private: sqlite3_stmt* mCurrentStmt; bool mMoreRows; - boost::mutex walMutex; JobQueue* mWalQ; bool walRunning; }; diff --git a/modules/ripple_app/ledger/Ledger.cpp b/modules/ripple_app/ledger/Ledger.cpp index 755c76722f..f2ccc63dc1 100644 --- a/modules/ripple_app/ledger/Ledger.cpp +++ b/modules/ripple_app/ledger/Ledger.cpp @@ -6,6 +6,11 @@ SETUP_LOG (Ledger) +LedgerBase::LedgerBase () + : mLock (this, "Ledger", __FILE__, __LINE__) +{ +} + Ledger::Ledger (const RippleAddress& masterID, uint64 startAmount) : mTotCoins (startAmount) , mLedgerSeq (1) // First Ledger @@ -561,13 +566,13 @@ void Ledger::saveValidatedLedger (bool current) AcceptedLedger::pointer aLedger = AcceptedLedger::makeAcceptedLedger (shared_from_this ()); { - ScopedLock sl (getApp().getLedgerDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getLedgerDB ()->getDBLock ()); getApp().getLedgerDB ()->getDB ()->executeSQL (boost::str (deleteLedger % mLedgerSeq)); } { Database* db = getApp().getTxnDB ()->getDB (); - ScopedLock dbLock (getApp().getTxnDB ()->getDBLock ()); + DeprecatedScopedLock dbLock (getApp().getTxnDB ()->getDBLock ()); db->executeSQL ("BEGIN TRANSACTION;"); db->executeSQL (boost::str (deleteTrans1 % mLedgerSeq)); @@ -621,7 +626,7 @@ void Ledger::saveValidatedLedger (bool current) } { - ScopedLock sl (getApp().getLedgerDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getLedgerDB ()->getDBLock ()); getApp().getLedgerDB ()->getDB ()->executeSQL (boost::str (addLedger % getHash ().GetHex () % mLedgerSeq % mParentHash.GetHex () % @@ -630,7 +635,7 @@ void Ledger::saveValidatedLedger (bool current) } { // Clients can now trust the database for information about this ledger sequence - boost::mutex::scoped_lock sl (sPendingSaveLock); + StaticScopedLockType sl (sPendingSaveLock, __FILE__, __LINE__); sPendingSaves.erase(getLedgerSeq()); } } @@ -642,7 +647,7 @@ Ledger::pointer Ledger::loadByIndex (uint32 ledgerIndex) Ledger::pointer ledger; { Database* db = getApp().getLedgerDB ()->getDB (); - ScopedLock sl (getApp().getLedgerDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getLedgerDB ()->getDBLock ()); SqliteStatement pSt (db->getSqliteDB (), "SELECT " "LedgerHash,PrevHash,AccountSetHash,TransSetHash,TotalCoins," @@ -667,7 +672,7 @@ Ledger::pointer Ledger::loadByHash (uint256 const& ledgerHash) Ledger::pointer ledger; { Database* db = getApp().getLedgerDB ()->getDB (); - ScopedLock sl (getApp().getLedgerDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getLedgerDB ()->getDBLock ()); SqliteStatement pSt (db->getSqliteDB (), "SELECT " "LedgerHash,PrevHash,AccountSetHash,TransSetHash,TotalCoins," @@ -722,7 +727,7 @@ Ledger::pointer Ledger::getSQL (const std::string& sql) { Database* db = getApp().getLedgerDB ()->getDB (); - ScopedLock sl (getApp().getLedgerDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getLedgerDB ()->getDBLock ()); if (!db->executeSQL (sql) || !db->startIterRows ()) return Ledger::pointer (); @@ -841,7 +846,7 @@ uint256 Ledger::getHashByIndex (uint32 ledgerIndex) std::string hash; { Database* db = getApp().getLedgerDB ()->getDB (); - ScopedLock sl (getApp().getLedgerDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getLedgerDB ()->getDBLock ()); if (!db->executeSQL (sql) || !db->startIterRows ()) return ret; @@ -859,7 +864,7 @@ bool Ledger::getHashesByIndex (uint32 ledgerIndex, uint256& ledgerHash, uint256& #ifndef NO_SQLITE3_PREPARE DatabaseCon* con = getApp().getLedgerDB (); - ScopedLock sl (con->getDBLock ()); + DeprecatedScopedLock sl (con->getDBLock ()); SqliteStatement pSt (con->getDB ()->getSqliteDB (), "SELECT LedgerHash,PrevHash FROM Ledgers INDEXED BY SeqLedger Where LedgerSeq = ?;"); @@ -895,7 +900,7 @@ bool Ledger::getHashesByIndex (uint32 ledgerIndex, uint256& ledgerHash, uint256& std::string hash, prevHash; { Database* db = getApp().getLedgerDB ()->getDB (); - ScopedLock sl (getApp().getLedgerDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getLedgerDB ()->getDBLock ()); if (!db->executeSQL (sql) || !db->startIterRows ()) return false; @@ -926,7 +931,7 @@ std::map< uint32, std::pair > Ledger::getHashesByIndex (uint32 sql.append (";"); DatabaseCon* con = getApp().getLedgerDB (); - ScopedLock sl (con->getDBLock ()); + DeprecatedScopedLock sl (con->getDBLock ()); SqliteStatement pSt (con->getDB ()->getSqliteDB (), sql); @@ -964,7 +969,7 @@ Json::Value Ledger::getJson (int options) bool bFull = isSetBit (options, LEDGER_JSON_FULL); - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); ledger["seqNum"] = lexicalCastThrow (mLedgerSeq); // DEPRECATED @@ -1004,7 +1009,7 @@ Json::Value Ledger::getJson (int options) { Json::Value txns (Json::arrayValue); SHAMapTreeNode::TNType type; - ScopedLock l (mTransactionMap->Lock ()); + SHAMap::ScopedLockType l (mTransactionMap->peekMutex (), __FILE__, __LINE__); for (SHAMapItem::pointer item = mTransactionMap->peekFirstItem (type); !!item; item = mTransactionMap->peekNextItem (item->getTag (), type)) @@ -1046,7 +1051,7 @@ Json::Value Ledger::getJson (int options) if (mAccountStateMap && (bFull || isSetBit (options, LEDGER_JSON_DUMP_STATE))) { Json::Value state (Json::arrayValue); - ScopedLock l (mAccountStateMap->Lock ()); + SHAMap::ScopedLockType l (mAccountStateMap->peekMutex (), __FILE__, __LINE__); for (SHAMapItem::pointer item = mAccountStateMap->peekFirstItem (); !!item; item = mAccountStateMap->peekNextItem (item->getTag ())) @@ -1104,7 +1109,7 @@ void Ledger::setCloseTime (boost::posix_time::ptime ptm) // XXX Use shared locks where possible? LedgerStateParms Ledger::writeBack (LedgerStateParms parms, SLE::ref entry) { - ScopedLock l (mAccountStateMap->Lock ()); + SHAMap::ScopedLockType l (mAccountStateMap->peekMutex (), __FILE__, __LINE__); bool create = false; if (!mAccountStateMap->hasItem (entry->getIndex ())) @@ -1157,7 +1162,7 @@ SLE::pointer Ledger::getSLEi (uint256 const& uId) { uint256 hash; - ScopedLock sl (mAccountStateMap->Lock ()); + SHAMap::ScopedLockType sl (mAccountStateMap->peekMutex (), __FILE__, __LINE__); SHAMapItem::pointer node = mAccountStateMap->peekItem (uId, hash); @@ -1837,7 +1842,7 @@ bool Ledger::pendSaveValidated (bool isSynchronous, bool isCurrent) assert (isImmutable ()); { - boost::mutex::scoped_lock sl (sPendingSaveLock); + StaticScopedLockType sl (sPendingSaveLock, __FILE__, __LINE__); if (!sPendingSaves.insert(getLedgerSeq()).second) { WriteLog (lsDEBUG, Ledger) << "Pend save with seq in pending saves " << getLedgerSeq(); @@ -1865,7 +1870,7 @@ bool Ledger::pendSaveValidated (bool isSynchronous, bool isCurrent) std::set Ledger::getPendingSaves() { - boost::mutex::scoped_lock sl (sPendingSaveLock); + StaticScopedLockType sl (sPendingSaveLock, __FILE__, __LINE__); return sPendingSaves; } @@ -1988,5 +1993,5 @@ public: static LedgerTests ledgerTests; -boost::mutex Ledger::sPendingSaveLock; +Ledger::StaticLockType Ledger::sPendingSaveLock ("LedgerStatic", __FILE__, __LINE__); std::set Ledger::sPendingSaves; diff --git a/modules/ripple_app/ledger/Ledger.h b/modules/ripple_app/ledger/Ledger.h index d278c58a9e..2bce4768f3 100644 --- a/modules/ripple_app/ledger/Ledger.h +++ b/modules/ripple_app/ledger/Ledger.h @@ -31,6 +31,20 @@ enum LedgerStateParms class SqliteStatement; +class LedgerBase +{ +protected: + LedgerBase (); + + // VFALCO TODO eliminate the need for friends + friend class TransactionEngine; + friend class Transactor; + + typedef RippleRecursiveMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; +}; + // VFALCO TODO figure out exactly how this thing works. // It seems like some ledger database is stored as a global, static in the // class. But then what is the meaning of a Ledger object? Is this @@ -38,6 +52,7 @@ class SqliteStatement; // class Ledger : public boost::enable_shared_from_this + , public LedgerBase , public CountedObject , public Uncopyable { @@ -446,14 +461,10 @@ protected: void updateFees (); private: - // The basic Ledger structure, can be opened, closed, or synching - // VFALCO TODO eliminate the need for friends - friend class TransactionEngine; - friend class Transactor; - void initializeFees (); private: + // The basic Ledger structure, can be opened, closed, or synching uint256 mHash; uint256 mParentHash; uint256 mTransHash; @@ -473,10 +484,11 @@ private: SHAMap::pointer mTransactionMap; SHAMap::pointer mAccountStateMap; - mutable boost::recursive_mutex mLock; - + typedef RippleMutex StaticLockType; + typedef StaticLockType::ScopedLockType StaticScopedLockType; // ledgers not fully saved, validated ledger present but DB may not be correct yet - static boost::mutex sPendingSaveLock; + static StaticLockType sPendingSaveLock; + static std::set sPendingSaves; }; @@ -491,4 +503,3 @@ inline LedgerStateParms operator& (const LedgerStateParms& l1, const LedgerState } #endif -// vim:ts=4 diff --git a/modules/ripple_app/ledger/LedgerMaster.cpp b/modules/ripple_app/ledger/LedgerMaster.cpp index 357ba239b5..5047e95770 100644 --- a/modules/ripple_app/ledger/LedgerMaster.cpp +++ b/modules/ripple_app/ledger/LedgerMaster.cpp @@ -25,7 +25,7 @@ Ledger::ref LedgerMaster::getCurrentSnapshot () int LedgerMaster::getPublishedLedgerAge () { - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); if (!mPubLedger) { WriteLog (lsDEBUG, LedgerMaster) << "No published ledger"; @@ -42,7 +42,7 @@ int LedgerMaster::getPublishedLedgerAge () int LedgerMaster::getValidatedLedgerAge () { - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); if (!mValidLedger) { WriteLog (lsDEBUG, LedgerMaster) << "No validated ledger"; @@ -64,7 +64,7 @@ bool LedgerMaster::isCaughtUp(std::string& reason) reason = "No recently-published ledger"; return false; } - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); if (!mValidLedger || !mPubLedger) { reason = "No published ledger"; @@ -81,7 +81,7 @@ bool LedgerMaster::isCaughtUp(std::string& reason) void LedgerMaster::addHeldTransaction (Transaction::ref transaction) { // returns true if transaction was added - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); mHeldTransactions.push_back (transaction->getSTransaction ()); } @@ -92,7 +92,7 @@ void LedgerMaster::pushLedger (Ledger::pointer newLedger) WriteLog (lsINFO, LedgerMaster) << "PushLedger: " << newLedger->getHash (); { - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); if (mClosedLedger) { @@ -121,7 +121,7 @@ void LedgerMaster::pushLedger (Ledger::pointer newLCL, Ledger::pointer newOL) { - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); mClosedLedger = newLCL; mCurrentLedger = newOL; mEngine.setLedger (newOL); @@ -141,7 +141,7 @@ void LedgerMaster::switchLedgers (Ledger::pointer lastClosed, Ledger::pointer cu assert (lastClosed && current); { - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); mClosedLedger = lastClosed; mClosedLedger->setClosed (); mClosedLedger->setAccepted (); @@ -166,7 +166,7 @@ void LedgerMaster::forceValid (Ledger::pointer ledger) Ledger::pointer LedgerMaster::closeLedger (bool recover) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); Ledger::pointer closingLedger = mCurrentLedger; if (recover) @@ -213,7 +213,7 @@ TER LedgerMaster::doTransaction (SerializedTransaction::ref txn, TransactionEngi TER result; { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); result = mEngine.applyTransaction (*txn, params, didApply); ledger = mEngine.getLedger (); } @@ -224,20 +224,20 @@ TER LedgerMaster::doTransaction (SerializedTransaction::ref txn, TransactionEngi bool LedgerMaster::haveLedgerRange (uint32 from, uint32 to) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); uint32 prevMissing = mCompleteLedgers.prevMissing (to + 1); return (prevMissing == RangeSet::absent) || (prevMissing < from); } bool LedgerMaster::haveLedger (uint32 seq) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mCompleteLedgers.hasValue (seq); } bool LedgerMaster::getFullValidatedRange (uint32& minVal, uint32& maxVal) { // Ledgers we have all the nodes for - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (!mPubLedger) return false; @@ -259,7 +259,7 @@ bool LedgerMaster::getFullValidatedRange (uint32& minVal, uint32& maxVal) bool LedgerMaster::getValidatedRange (uint32& minVal, uint32& maxVal) { // Ledgers we have all the nodes for and are indexed - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (!mPubLedger) return false; @@ -323,7 +323,7 @@ void LedgerMaster::tryFill (Ledger::pointer ledger) while (seq > 0) { { - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); minHas = seq; --seq; @@ -339,7 +339,7 @@ void LedgerMaster::tryFill (Ledger::pointer ledger) return; { - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); mCompleteLedgers.setRange (minHas, maxHas); } maxHas = minHas; @@ -357,7 +357,7 @@ void LedgerMaster::tryFill (Ledger::pointer ledger) } { - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); mCompleteLedgers.setRange (minHas, maxHas); mFillInProgress = false; tryAdvance(); @@ -449,7 +449,7 @@ void LedgerMaster::setFullLedger (Ledger::pointer ledger, bool isSynchronous, bo ledger->setValidated(); mLedgerHistory.addLedger(ledger); - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); mCompleteLedgers.setValue (ledger->getLedgerSeq ()); @@ -496,7 +496,7 @@ void LedgerMaster::checkAccept (uint256 const& hash) void LedgerMaster::checkAccept (uint256 const& hash, uint32 seq) { // Can we advance the last fully-validated ledger? If so, can we publish? - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); if (mValidLedger && (seq <= mValidLedger->getLedgerSeq ())) return; @@ -570,7 +570,7 @@ void LedgerMaster::checkAccept (uint256 const& hash, uint32 seq) // Try to publish ledgers, acquire missing ledgers void LedgerMaster::advanceThread() { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); assert (mValidLedger && mAdvanceThread); bool progress; @@ -627,7 +627,7 @@ void LedgerMaster::advanceThread() setFullLedger(ledger, false, false); if (Ledger::getHashByIndex(ledger->getLedgerSeq() - 1) == ledger->getParentHash()) { // Previous ledger is in DB - sl.lock(); + sl.lock(__FILE__, __LINE__); mFillInProgress = true; getApp().getJobQueue().addJob(jtADVANCE, "tryFill", BIND_TYPE (&LedgerMaster::tryFill, this, ledger)); sl.unlock(); @@ -651,7 +651,7 @@ void LedgerMaster::advanceThread() WriteLog (lsFATAL, LedgerMaster) << "Pub:" << mPubLedger->getLedgerSeq() << " Val:" << mValidLedger->getLedgerSeq(); assert(false); } - sl.lock(); + sl.lock(__FILE__, __LINE__); if (mValidLedger->getLedgerSeq() != mPubLedger->getLedgerSeq()) { WriteLog (lsDEBUG, LedgerMaster) << "tryAdvance found last valid changed"; @@ -673,7 +673,7 @@ void LedgerMaster::advanceThread() setFullLedger(ledger, true, true); getApp().getOPs().pubLedger(ledger); - sl.lock(); + sl.lock(__FILE__, __LINE__); mPubLedger = ledger; progress = true; } @@ -693,7 +693,7 @@ void LedgerMaster::advanceThread() WriteLog (lsTRACE, LedgerMaster) << "advanceThread>"; } -std::list LedgerMaster::findNewLedgersToPublish(boost::recursive_mutex::scoped_lock& sl) +std::list LedgerMaster::findNewLedgersToPublish(ScopedLockType& sl) { std::list ret; @@ -775,7 +775,7 @@ std::list LedgerMaster::findNewLedgersToPublish(boost::recursiv } } - sl.lock(); + sl.lock(__FILE__, __LINE__); } WriteLog (lsTRACE, LedgerMaster) << "findNewLedgersToPublish> " << ret.size(); @@ -784,7 +784,7 @@ std::list LedgerMaster::findNewLedgersToPublish(boost::recursiv void LedgerMaster::tryAdvance() { - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); // Can't advance without at least one fully-valid ledger if (!mAdvanceThread && mValidLedger) @@ -834,7 +834,7 @@ void LedgerMaster::updatePaths () bool newOnly = true; { - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); if (!mPathLedger || (mPathLedger->getLedgerSeq() < mValidLedger->getLedgerSeq())) { // We have a new valid ledger since the last full pathfinding @@ -865,7 +865,7 @@ void LedgerMaster::updatePaths () void LedgerMaster::newPathRequest () { - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); mPathFindNewRequest = true; if (!mPathFindThread) diff --git a/modules/ripple_app/ledger/LedgerMaster.h b/modules/ripple_app/ledger/LedgerMaster.h index 2989b07817..754824b084 100644 --- a/modules/ripple_app/ledger/LedgerMaster.h +++ b/modules/ripple_app/ledger/LedgerMaster.h @@ -20,8 +20,12 @@ public: typedef FUNCTION_TYPE callback; public: + typedef RippleRecursiveMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LedgerMaster () - : mHeldTransactions (uint256 ()) + : mLock (this, "LedgerMaster", __FILE__, __LINE__) + , mHeldTransactions (uint256 ()) , mMinValidations (0) , mLastValidateSeq (0) , mAdvanceThread (false) @@ -37,9 +41,9 @@ public: uint32 getCurrentLedgerIndex (); - ScopedLock getLock () + LockType& peekMutex () { - return ScopedLock (mLock); + return mLock; } // The current ledger is the ledger we believe new transactions should go in @@ -95,7 +99,7 @@ public: std::string getCompleteLedgers () { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mCompleteLedgers.toString (); } @@ -124,7 +128,7 @@ public: if (ret) return ret; - boost::recursive_mutex::scoped_lock ml (mLock); + ScopedLockType ml (mLock, __FILE__, __LINE__); mCompleteLedgers.clearValue (index); return ret; } @@ -145,7 +149,7 @@ public: void setLedgerRangePresent (uint32 minV, uint32 maxV) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mCompleteLedgers.setRange (minV, maxV); } @@ -179,13 +183,14 @@ public: void checkAccept (uint256 const& hash); void checkAccept (uint256 const& hash, uint32 seq); - std::list findNewLedgersToPublish(boost::recursive_mutex::scoped_lock& sl); void tryAdvance (); void newPathRequest (); static bool shouldAcquire (uint32 currentLedgerID, uint32 ledgerHistory, uint32 targetLedger); private: + std::list findNewLedgersToPublish(ScopedLockType& sl); + void applyFutureTransactions (uint32 ledgerIndex); bool isValidTransaction (Transaction::ref trans); bool isTransactionOnFutureList (Transaction::ref trans); @@ -196,7 +201,7 @@ private: void updatePaths (); private: - boost::recursive_mutex mLock; + LockType mLock; TransactionEngine mEngine; diff --git a/modules/ripple_app/ledger/OrderBookDB.cpp b/modules/ripple_app/ledger/OrderBookDB.cpp index 8392ac23e8..15df605bd9 100644 --- a/modules/ripple_app/ledger/OrderBookDB.cpp +++ b/modules/ripple_app/ledger/OrderBookDB.cpp @@ -6,14 +6,16 @@ SETUP_LOG (OrderBookDB) -OrderBookDB::OrderBookDB () : mSeq (0) +OrderBookDB::OrderBookDB () + : mLock (this, "OrderBookDB", __FILE__, __LINE__) + , mSeq (0) { } void OrderBookDB::invalidate () { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mSeq = 0; } @@ -21,7 +23,7 @@ void OrderBookDB::setup (Ledger::ref ledger) { boost::unordered_set mSeen; - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (ledger->getLedgerSeq () == mSeq) return; @@ -73,7 +75,7 @@ void OrderBookDB::setup (Ledger::ref ledger) void OrderBookDB::getBooksByTakerPays (const uint160& issuerID, const uint160& currencyID, std::vector& bookRet) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); boost::unordered_map< currencyIssuer_t, std::vector >::const_iterator it = mSourceMap.find (currencyIssuer_ct (currencyID, issuerID)); @@ -87,7 +89,7 @@ void OrderBookDB::getBooksByTakerPays (const uint160& issuerID, const uint160& c void OrderBookDB::getBooksByTakerGets (const uint160& issuerID, const uint160& currencyID, std::vector& bookRet) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); boost::unordered_map< currencyIssuer_t, std::vector >::const_iterator it = mDestMap.find (currencyIssuer_ct (currencyID, issuerID)); @@ -100,7 +102,7 @@ void OrderBookDB::getBooksByTakerGets (const uint160& issuerID, const uint160& c BookListeners::pointer OrderBookDB::makeBookListeners (const uint160& currencyPays, const uint160& currencyGets, const uint160& issuerPays, const uint160& issuerGets) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); BookListeners::pointer ret = getBookListeners (currencyPays, currencyGets, issuerPays, issuerGets); if (!ret) @@ -116,7 +118,7 @@ BookListeners::pointer OrderBookDB::getBookListeners (const uint160& currencyPay const uint160& issuerPays, const uint160& issuerGets) { BookListeners::pointer ret; - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); std::map > > >::iterator it0 = mListeners.find (issuerPays); @@ -147,7 +149,7 @@ BookListeners::pointer OrderBookDB::getBookListeners (const uint160& currencyPay // We need to determine which streams a given meta effects void OrderBookDB::processTxn (Ledger::ref ledger, const AcceptedLedgerTx& alTx, Json::Value& jvObj) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (alTx.getResult () == tesSUCCESS) { @@ -205,16 +207,23 @@ void OrderBookDB::processTxn (Ledger::ref ledger, const AcceptedLedgerTx& alTx, } } } + +//------------------------------------------------------------------------------ + +BookListeners::BookListeners () + : mLock (this, "BookListeners", __FILE__, __LINE__) +{ +} void BookListeners::addSubscriber (InfoSub::ref sub) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mListeners[sub->getSeq ()] = sub; } void BookListeners::removeSubscriber (uint64 seq) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mListeners.erase (seq); } @@ -223,7 +232,7 @@ void BookListeners::publish (Json::Value& jvObj) Json::FastWriter jfwWriter; std::string sObj = jfwWriter.write (jvObj); - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); NetworkOPs::SubMapType::const_iterator it = mListeners.begin (); while (it != mListeners.end ()) diff --git a/modules/ripple_app/ledger/OrderBookDB.h b/modules/ripple_app/ledger/OrderBookDB.h index 467c80546d..7787e2685b 100644 --- a/modules/ripple_app/ledger/OrderBookDB.h +++ b/modules/ripple_app/ledger/OrderBookDB.h @@ -25,13 +25,16 @@ class BookListeners public: typedef boost::shared_ptr pointer; + BookListeners (); void addSubscriber (InfoSub::ref sub); void removeSubscriber (uint64 sub); void publish (Json::Value& jvObj); private: + typedef RippleRecursiveMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; boost::unordered_map mListeners; - boost::recursive_mutex mLock; }; class OrderBookDB : LeakChecked @@ -58,13 +61,16 @@ public: private: boost::unordered_map< currencyIssuer_t, std::vector > mSourceMap; // by ci/ii + typedef RippleRecursiveMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; + boost::unordered_map< currencyIssuer_t, std::vector > mDestMap; // by co/io // issuerPays, issuerGets, currencyPays, currencyGets std::map > > > mListeners; uint32 mSeq; - boost::recursive_mutex mLock; }; diff --git a/modules/ripple_app/ledger/ripple_AcceptedLedger.cpp b/modules/ripple_app/ledger/ripple_AcceptedLedger.cpp index ec58d019ad..44b2be2954 100644 --- a/modules/ripple_app/ledger/ripple_AcceptedLedger.cpp +++ b/modules/ripple_app/ledger/ripple_AcceptedLedger.cpp @@ -4,7 +4,7 @@ */ //============================================================================== -TaggedCache AcceptedLedger::s_cache ("AcceptedLedger", 4, 60); +TaggedCacheType AcceptedLedger::s_cache ("AcceptedLedger", 4, 60); AcceptedLedger::AcceptedLedger (Ledger::ref ledger) : mLedger (ledger) { diff --git a/modules/ripple_app/ledger/ripple_AcceptedLedger.h b/modules/ripple_app/ledger/ripple_AcceptedLedger.h index 17a7878e1f..5f39fee976 100644 --- a/modules/ripple_app/ledger/ripple_AcceptedLedger.h +++ b/modules/ripple_app/ledger/ripple_AcceptedLedger.h @@ -70,7 +70,7 @@ private: void insert (AcceptedLedgerTx::ref); private: - static TaggedCache s_cache; + static TaggedCacheType s_cache; Ledger::pointer mLedger; map_t mMap; diff --git a/modules/ripple_app/ledger/ripple_InboundLedger.cpp b/modules/ripple_app/ledger/ripple_InboundLedger.cpp index 942556e2f4..4db7bad58b 100644 --- a/modules/ripple_app/ledger/ripple_InboundLedger.cpp +++ b/modules/ripple_app/ledger/ripple_InboundLedger.cpp @@ -30,7 +30,7 @@ InboundLedger::InboundLedger (uint256 const& hash, uint32 seq) bool InboundLedger::checkLocal () { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (!isDone () && tryLocal()) { @@ -141,7 +141,7 @@ bool InboundLedger::tryLocal () return mComplete; } -void InboundLedger::onTimer (bool wasProgress, boost::recursive_mutex::scoped_lock&) +void InboundLedger::onTimer (bool wasProgress, ScopedLockType&) { mRecentTXNodes.clear (); mRecentASNodes.clear (); @@ -257,7 +257,7 @@ void InboundLedger::done () std::vector< FUNCTION_TYPE > triggers; { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); triggers.swap (mOnComplete); } @@ -277,7 +277,7 @@ void InboundLedger::done () bool InboundLedger::addOnComplete (FUNCTION_TYPE trigger) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (isDone ()) return false; @@ -288,7 +288,7 @@ bool InboundLedger::addOnComplete (FUNCTION_TYPE void InboundLedger::trigger (Peer::ref peer) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (isDone ()) { @@ -362,7 +362,7 @@ void InboundLedger::trigger (Peer::ref peer) } PackedMessage::pointer packet = boost::make_shared (tmBH, protocol::mtGET_OBJECTS); { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); for (boost::unordered_map::iterator it = mPeers.begin (), end = mPeers.end (); it != end; ++it) @@ -594,7 +594,7 @@ bool InboundLedger::takeBase (const std::string& data) // data must not have has #ifdef LA_DEBUG WriteLog (lsTRACE, InboundLedger) << "got base acquiring ledger " << mHash; #endif - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (mComplete || mFailed || mHaveBase) return true; @@ -634,7 +634,7 @@ bool InboundLedger::takeBase (const std::string& data) // data must not have has bool InboundLedger::takeTxNode (const std::list& nodeIDs, const std::list< Blob >& data, SHAMapAddNode& san) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (!mHaveBase) return false; @@ -685,7 +685,7 @@ bool InboundLedger::takeAsNode (const std::list& nodeIDs, WriteLog (lsTRACE, InboundLedger) << "got ASdata (" << nodeIDs.size () << ") acquiring ledger " << mHash; CondLog (nodeIDs.size () == 1, lsTRACE, InboundLedger) << "got AS node: " << nodeIDs.front (); - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (!mHaveBase) { @@ -738,7 +738,7 @@ bool InboundLedger::takeAsNode (const std::list& nodeIDs, bool InboundLedger::takeAsRootNode (Blob const& data, SHAMapAddNode& san) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (mFailed || mHaveState) return true; @@ -753,7 +753,7 @@ bool InboundLedger::takeAsRootNode (Blob const& data, SHAMapAddNode& san) bool InboundLedger::takeTxRootNode (Blob const& data, SHAMapAddNode& san) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (mFailed || mHaveState) return true; @@ -803,7 +803,7 @@ Json::Value InboundLedger::getJson (int) { Json::Value ret (Json::objectValue); - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); ret["hash"] = mHash.GetHex (); diff --git a/modules/ripple_app/ledger/ripple_InboundLedger.h b/modules/ripple_app/ledger/ripple_InboundLedger.h index bc34aee047..1895777df8 100644 --- a/modules/ripple_app/ledger/ripple_InboundLedger.h +++ b/modules/ripple_app/ledger/ripple_InboundLedger.h @@ -82,7 +82,7 @@ public: private: void done (); - void onTimer (bool progress, boost::recursive_mutex::scoped_lock& peerSetLock); + void onTimer (bool progress, ScopedLockType& peerSetLock); void newPeer (Peer::ref peer) { diff --git a/modules/ripple_app/ledger/ripple_InboundLedgers.cpp b/modules/ripple_app/ledger/ripple_InboundLedgers.cpp index 14213e1de5..f66d29a1fa 100644 --- a/modules/ripple_app/ledger/ripple_InboundLedgers.cpp +++ b/modules/ripple_app/ledger/ripple_InboundLedgers.cpp @@ -6,13 +6,19 @@ typedef std::pair u256_acq_pair; +InboundLedgers::InboundLedgers () + : mLock (this, "InboundLedger", __FILE__, __LINE__) + , mRecentFailures ("LedgerAcquireRecentFailures", 0, kReacquireIntervalSeconds) +{ +} + InboundLedger::pointer InboundLedgers::findCreate (uint256 const& hash, uint32 seq, bool couldBeNew) { assert (hash.isNonZero ()); InboundLedger::pointer ret; { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); boost::unordered_map::iterator it = mLedgers.find (hash); if (it != mLedgers.end ()) @@ -54,7 +60,7 @@ InboundLedger::pointer InboundLedgers::find (uint256 const& hash) InboundLedger::pointer ret; { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); boost::unordered_map::iterator it = mLedgers.find (hash); if (it != mLedgers.end ()) @@ -70,7 +76,7 @@ bool InboundLedgers::hasLedger (uint256 const& hash) { assert (hash.isNonZero ()); - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mLedgers.find (hash) != mLedgers.end (); } @@ -78,7 +84,7 @@ void InboundLedgers::dropLedger (uint256 const& hash) { assert (hash.isNonZero ()); - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mLedgers.erase (hash); } @@ -227,7 +233,7 @@ void InboundLedgers::sweep () std::vector stuffToSweep; std::size_t total; { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); MapType::iterator it (mLedgers.begin ()); total = mLedgers.size (); stuffToSweep.reserve (total); @@ -266,7 +272,7 @@ int InboundLedgers::getFetchCount (int& timeoutCount) std::vector inboundLedgers; { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); inboundLedgers.reserve(mLedgers.size()); BOOST_FOREACH (const u256_acq_pair & it, mLedgers) @@ -290,7 +296,7 @@ void InboundLedgers::gotFetchPack (Job&) { std::vector acquires; { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); acquires.reserve (mLedgers.size ()); BOOST_FOREACH (const u256_acq_pair & it, mLedgers) @@ -308,7 +314,7 @@ void InboundLedgers::gotFetchPack (Job&) void InboundLedgers::clearFailures () { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mRecentFailures.clear(); mLedgers.clear(); @@ -320,7 +326,7 @@ Json::Value InboundLedgers::getInfo() std::vector acquires; { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); acquires.reserve (mLedgers.size ()); BOOST_FOREACH (const u256_acq_pair & it, mLedgers) diff --git a/modules/ripple_app/ledger/ripple_InboundLedgers.h b/modules/ripple_app/ledger/ripple_InboundLedgers.h index 4735aae91e..6bada5c076 100644 --- a/modules/ripple_app/ledger/ripple_InboundLedgers.h +++ b/modules/ripple_app/ledger/ripple_InboundLedgers.h @@ -19,10 +19,7 @@ public: // How long before we try again to acquire the same ledger static const int kReacquireIntervalSeconds = 300; - InboundLedgers () - : mRecentFailures ("LedgerAcquireRecentFailures", 0, kReacquireIntervalSeconds) - { - } + InboundLedgers (); // VFALCO TODO Should this be called findOrAdd ? // @@ -66,7 +63,10 @@ public: private: typedef boost::unordered_map MapType; - boost::mutex mLock; + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; + MapType mLedgers; KeyCache mRecentFailures; }; diff --git a/modules/ripple_app/ledger/ripple_LedgerHistory.cpp b/modules/ripple_app/ledger/ripple_LedgerHistory.cpp index 53167bd46c..d0287dcc06 100644 --- a/modules/ripple_app/ledger/ripple_LedgerHistory.cpp +++ b/modules/ripple_app/ledger/ripple_LedgerHistory.cpp @@ -26,7 +26,7 @@ void LedgerHistory::addLedger (Ledger::pointer ledger) assert (ledger && ledger->isImmutable ()); assert (ledger->peekAccountStateMap ()->getHash ().isNonZero ()); - boost::recursive_mutex::scoped_lock sl (mLedgersByHash.peekMutex ()); + TaggedCache::ScopedLockType sl (mLedgersByHash.peekMutex (), __FILE__, __LINE__); mLedgersByHash.canonicalize (ledger->getHash(), ledger, true); if (ledger->isValidated()) @@ -35,7 +35,7 @@ void LedgerHistory::addLedger (Ledger::pointer ledger) uint256 LedgerHistory::getLedgerHash (uint32 index) { - boost::recursive_mutex::scoped_lock sl (mLedgersByHash.peekMutex ()); + TaggedCache::ScopedLockType sl (mLedgersByHash.peekMutex (), __FILE__, __LINE__); std::map::iterator it (mLedgersByIndex.find (index)); if (it != mLedgersByIndex.end ()) @@ -47,7 +47,7 @@ uint256 LedgerHistory::getLedgerHash (uint32 index) Ledger::pointer LedgerHistory::getLedgerBySeq (uint32 index) { - boost::recursive_mutex::scoped_lock sl (mLedgersByHash.peekMutex ()); + TaggedCache::ScopedLockType sl (mLedgersByHash.peekMutex (), __FILE__, __LINE__); std::map::iterator it (mLedgersByIndex.find (index)); if (it != mLedgersByIndex.end ()) @@ -66,7 +66,7 @@ Ledger::pointer LedgerHistory::getLedgerBySeq (uint32 index) assert (ret->getLedgerSeq () == index); - sl.lock (); + sl.lock (__FILE__, __LINE__); assert (ret->isImmutable ()); mLedgersByHash.canonicalize (ret->getHash (), ret); mLedgersByIndex[ret->getLedgerSeq ()] = ret->getHash (); @@ -114,7 +114,7 @@ Ledger::pointer LedgerHistory::canonicalizeLedger (Ledger::pointer ledger, bool } // save input ledger in map if not in map, otherwise return corresponding map ledger - boost::recursive_mutex::scoped_lock sl (mLedgersByHash.peekMutex ()); + TaggedCache::ScopedLockType sl (mLedgersByHash.peekMutex (), __FILE__, __LINE__); mLedgersByHash.canonicalize (h, ledger); if (ledger->isValidated ()) diff --git a/modules/ripple_app/ledger/ripple_LedgerHistory.h b/modules/ripple_app/ledger/ripple_LedgerHistory.h index 26f87bcf8f..df448a6d9e 100644 --- a/modules/ripple_app/ledger/ripple_LedgerHistory.h +++ b/modules/ripple_app/ledger/ripple_LedgerHistory.h @@ -37,7 +37,7 @@ public: } private: - TaggedCache mLedgersByHash; + TaggedCacheType mLedgersByHash; // Maps ledger indexes to the corresponding hash. std::map mLedgersByIndex; // validated ledgers diff --git a/modules/ripple_app/main/ripple_Application.cpp b/modules/ripple_app/main/ripple_Application.cpp index ee96c6514a..469420e42a 100644 --- a/modules/ripple_app/main/ripple_Application.cpp +++ b/modules/ripple_app/main/ripple_Application.cpp @@ -152,6 +152,7 @@ public: // : SharedSingleton (SingletonLifetime::neverDestroyed) #endif + , mMasterLock (this, "MasterLock", __FILE__, __LINE__) , m_mainService ("io", (getConfig ().NODE_SIZE >= 2) ? 2 : 1, (getConfig ().NODE_SIZE >= 2) ? 1 : 0) @@ -265,7 +266,7 @@ public: return mJobQueue; } - MasterLockType& getMasterLock () + Application::LockType& getMasterLock () { return mMasterLock; } @@ -642,6 +643,8 @@ private: bool loadOldLedger (const std::string&, bool); private: + Application::LockType mMasterLock; + IoServiceThread m_mainService; IoServiceThread m_auxService; @@ -649,8 +652,6 @@ private: //boost::asio::io_service mAuxService; //boost::asio::io_service::work mIOWork; - MasterLockType mMasterLock; - LocalCredentials m_localCredentials; LedgerMaster mLedgerMaster; InboundLedgers m_inboundLedgers; diff --git a/modules/ripple_app/main/ripple_Application.h b/modules/ripple_app/main/ripple_Application.h index 59a2f62a2b..1b60883b85 100644 --- a/modules/ripple_app/main/ripple_Application.h +++ b/modules/ripple_app/main/ripple_Application.h @@ -32,8 +32,8 @@ class LocalCredentials; class DatabaseCon; -typedef TaggedCache NodeCache; -typedef TaggedCache SLECache; +typedef TaggedCacheType NodeCache; +typedef TaggedCacheType SLECache; class Application { @@ -49,92 +49,10 @@ public: other things */ -#if 1 - class ScopedLockType; - - class MasterLockType - { - public: - MasterLockType () - : m_fileName ("") - , m_lineNumber (0) - { - } - - // Note that these are not exactly thread safe. - - char const* getFileName () const noexcept - { - return m_fileName.get (); - } - - int getLineNumber () const noexcept - { - return m_lineNumber.get (); - } - - private: - friend class ScopedLockType; - - void setOwner (char const* fileName, int lineNumber) - { - m_fileName.set (fileName); - m_lineNumber.set (lineNumber); - } - - void resetOwner () - { - m_fileName.set (""); - m_lineNumber.set (0); - } - - boost::recursive_mutex m_mutex; - Atomic m_fileName; - Atomic m_lineNumber; - }; - - class ScopedLockType - { - public: - explicit ScopedLockType (MasterLockType& mutex, - char const* fileName, - int lineNumber) - : m_mutex (mutex) - , m_lock (mutex.m_mutex) - { - mutex.setOwner (fileName, lineNumber); - } - - ~ScopedLockType () - { - if (m_lock.owns_lock ()) - m_mutex.resetOwner (); - } - - void unlock () - { - if (m_lock.owns_lock ()) - m_mutex.resetOwner (); - - m_lock.unlock (); - } - - private: - MasterLockType& m_mutex; - boost::recursive_mutex::scoped_lock m_lock; - }; - -#else - typedef boost::recursive_mutex MasterLockType; - - typedef boost::recursive_mutex::scoped_lock ScopedLockType; - -#endif - - virtual MasterLockType& getMasterLock () = 0; - - + typedef RippleRecursiveMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + virtual LockType& getMasterLock () = 0; public: struct State diff --git a/modules/ripple_app/main/ripple_LoadManager.cpp b/modules/ripple_app/main/ripple_LoadManager.cpp index 4b97611f1c..46189eff26 100644 --- a/modules/ripple_app/main/ripple_LoadManager.cpp +++ b/modules/ripple_app/main/ripple_LoadManager.cpp @@ -60,7 +60,8 @@ private: public: LoadManager () - : m_thread ("loadmgr") + : mLock (this, "LoadManager", __FILE__, __LINE__) + , m_thread ("loadmgr") , m_logThread ("loadmgr_log") , mCreditRate (100) , mCreditLimit (500) @@ -148,7 +149,7 @@ private: bool shouldWarn (LoadSource& source) const { { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); int now = UptimeTimer::getInstance ().getElapsedSeconds (); canonicalize (source, now); @@ -165,7 +166,7 @@ private: bool shouldCutoff (LoadSource& source) const { { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); int now = UptimeTimer::getInstance ().getElapsedSeconds (); canonicalize (source, now); @@ -196,7 +197,7 @@ private: // We do it this way in case we want to add exponential decay later int now = UptimeTimer::getInstance ().getElapsedSeconds (); - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); canonicalize (source, now); source.mBalance += credits; @@ -238,7 +239,7 @@ private: void resetDeadlockDetector () { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mDeadLock = UptimeTimer::getInstance ().getElapsedSeconds (); } @@ -251,10 +252,16 @@ private: { WriteLog (lsWARNING, LoadManager) << "Server stalled for " << dlTime << " seconds."; - char const* fileName = getApp ().getMasterLock ().getFileName (); - int lineNumber = getApp ().getMasterLock ().getLineNumber (); - - WriteLog (lsWARNING, LoadManager) << "Master lock owned by " << File (fileName).getFileName ().toStdString () << ", line " << lineNumber; +#if RIPPLE_TRACK_MUTEXES + StringArray report; + TrackedMutex::generateGlobalBlockedReport (report); + if (report.size () > 0) + { + report.insert (0, String::empty); + report.insert (-1, String::empty); + Log::print (report); + } +#endif } private: @@ -262,49 +269,49 @@ private: /* int getCreditRate () const { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mCreditRate; } int getCreditLimit () const { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mCreditLimit; } int getDebitWarn () const { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mDebitWarn; } int getDebitLimit () const { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mDebitLimit; } void setCreditRate (int r) { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mCreditRate = r; } void setCreditLimit (int r) { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mCreditLimit = r; } void setDebitWarn (int r) { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mDebitWarn = r; } void setDebitLimit (int r) { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mDebitLimit = r; } */ @@ -328,7 +335,7 @@ private: { { // VFALCO NOTE What is this lock protecting? - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); // VFALCO NOTE I think this is to reduce calls to the operating system // for retrieving the current time. @@ -346,10 +353,11 @@ private: // VFALCO NOTE I think that "armed" refers to the deadlock detector // - if (mArmed && (timeSpentDeadlocked >= 10)) + int const reportingIntervalSeconds = 10; + if (mArmed && (timeSpentDeadlocked >= reportingIntervalSeconds)) { // Report the deadlocked condition every 10 seconds - if ((timeSpentDeadlocked % 10) == 0) + if ((timeSpentDeadlocked % reportingIntervalSeconds) == 0) { // VFALCO TODO Replace this with a dedicated thread with call queue. // @@ -401,6 +409,10 @@ private: } private: + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; + beast::InterruptibleThread m_thread; beast::ThreadWithCallQueue m_logThread; @@ -413,8 +425,6 @@ private: int mDeadLock; // Detect server deadlocks - mutable boost::mutex mLock; // VFALCO TODO Replace with juce::Mutex and remove the mutable attribute - std::vector mCosts; }; diff --git a/modules/ripple_app/main/ripple_LocalCredentials.cpp b/modules/ripple_app/main/ripple_LocalCredentials.cpp index 8bff975913..297a982255 100644 --- a/modules/ripple_app/main/ripple_LocalCredentials.cpp +++ b/modules/ripple_app/main/ripple_LocalCredentials.cpp @@ -34,7 +34,7 @@ bool LocalCredentials::nodeIdentityLoad () { Database* db = getApp().getWalletDB ()->getDB (); - ScopedLock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); bool bSuccess = false; if (db->executeSQL ("SELECT * FROM NodeIdentity;") && db->startIterRows ()) @@ -105,7 +105,7 @@ bool LocalCredentials::nodeIdentityCreate () // Database* db = getApp().getWalletDB ()->getDB (); - ScopedLock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); db->executeSQL (str (boost::format ("INSERT INTO NodeIdentity (PublicKey,PrivateKey,Dh512,Dh1024) VALUES ('%s','%s',%s,%s);") % naNodePublic.humanNodePublic () % naNodePrivate.humanNodePrivate () @@ -123,7 +123,7 @@ bool LocalCredentials::dataDelete (const std::string& strKey) { Database* db = getApp().getRpcDB ()->getDB (); - ScopedLock sl (getApp().getRpcDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getRpcDB ()->getDBLock ()); return db->executeSQL (str (boost::format ("DELETE FROM RPCData WHERE Key=%s;") % sqlEscape (strKey))); @@ -133,7 +133,7 @@ bool LocalCredentials::dataFetch (const std::string& strKey, std::string& strVal { Database* db = getApp().getRpcDB ()->getDB (); - ScopedLock sl (getApp().getRpcDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getRpcDB ()->getDBLock ()); bool bSuccess = false; @@ -155,7 +155,7 @@ bool LocalCredentials::dataStore (const std::string& strKey, const std::string& { Database* db = getApp().getRpcDB ()->getDB (); - ScopedLock sl (getApp().getRpcDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getRpcDB ()->getDBLock ()); bool bSuccess = false; diff --git a/modules/ripple_app/misc/NetworkOPs.cpp b/modules/ripple_app/misc/NetworkOPs.cpp index 261a54be5e..48bfeae8d3 100644 --- a/modules/ripple_app/misc/NetworkOPs.cpp +++ b/modules/ripple_app/misc/NetworkOPs.cpp @@ -18,7 +18,8 @@ SETUP_LOG (NetworkOPs) // there's a functional network. NetworkOPs::NetworkOPs (LedgerMaster* pLedgerMaster) - : mMode (omDISCONNECTED) + : mLock (this, "NetOPs", __FILE__, __LINE__) + , mMode (omDISCONNECTED) , mNeedNetworkLedger (false) , mProposing (false) , mValidating (false) @@ -1124,7 +1125,7 @@ void NetworkOPs::pubServer () // list into a local array while holding the lock then release the // lock and call send on everyone. // - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (!mSubServer.empty ()) { @@ -1263,7 +1264,7 @@ NetworkOPs::getAccountTxs (const RippleAddress& account, int32 minLedger, int32 { Database* db = getApp().getTxnDB ()->getDB (); - ScopedLock sl (getApp().getTxnDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getTxnDB ()->getDBLock ()); SQL_FOREACH (db, sql) { @@ -1309,7 +1310,7 @@ std::vector NetworkOPs::getAccountTxsB ( { Database* db = getApp().getTxnDB ()->getDB (); - ScopedLock sl (getApp().getTxnDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getTxnDB ()->getDBLock ()); SQL_FOREACH (db, sql) { @@ -1356,7 +1357,7 @@ NetworkOPs::countAccountTxs (const RippleAddress& account, int32 minLedger, int3 minLedger, maxLedger, false, 0, -1, true, true, true); Database* db = getApp().getTxnDB ()->getDB (); - ScopedLock sl (getApp().getTxnDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getTxnDB ()->getDBLock ()); SQL_FOREACH (db, sql) { ret = db->getInt ("TransactionCount"); @@ -1376,7 +1377,7 @@ NetworkOPs::getLedgerAffectedAccounts (uint32 ledgerSeq) RippleAddress acct; { Database* db = getApp().getTxnDB ()->getDB (); - ScopedLock sl (getApp().getTxnDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getTxnDB ()->getDBLock ()); SQL_FOREACH (db, sql) { if (acct.setAccountID (db->getStrBinary ("Account"))) @@ -1592,7 +1593,7 @@ void NetworkOPs::pubProposedTransaction (Ledger::ref lpCurrent, SerializedTransa Json::Value jvObj = transJson (*stTxn, terResult, false, lpCurrent); { - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); NetworkOPs::SubMapType::const_iterator it = mSubRTTransactions.begin (); while (it != mSubRTTransactions.end ()) @@ -1622,7 +1623,7 @@ void NetworkOPs::pubLedger (Ledger::ref accepted) Ledger::ref lpAccepted = alpAccepted->getLedger (); { - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (!mSubLedger.empty ()) { @@ -1726,7 +1727,7 @@ void NetworkOPs::pubValidatedTransaction (Ledger::ref alAccepted, const Accepted std::string sObj = w.write (jvObj); { - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); NetworkOPs::SubMapType::const_iterator it = mSubTransactions.begin (); @@ -1769,7 +1770,7 @@ void NetworkOPs::pubAccountTransaction (Ledger::ref lpCurrent, const AcceptedLed int iAccepted = 0; { - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (!bAccepted && mSubRTAccount.empty ()) return; @@ -1859,7 +1860,7 @@ void NetworkOPs::subAccount (InfoSub::ref isrListener, const boost::unordered_se isrListener->insertSubAccountInfo (naAccountID, uLedgerIndex); } - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); BOOST_FOREACH (const RippleAddress & naAccountID, vnaAccountIDs) { @@ -1891,7 +1892,7 @@ void NetworkOPs::unsubAccount (uint64 uSeq, const boost::unordered_setdeleteSubAccountInfo(naAccountID); // } - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); BOOST_FOREACH (const RippleAddress & naAccountID, vnaAccountIDs) { @@ -1997,14 +1998,14 @@ bool NetworkOPs::subLedger (InfoSub::ref isrListener, Json::Value& jvResult) if ((mMode >= omSYNCING) && !isNeedNetworkLedger ()) jvResult["validated_ledgers"] = getApp().getLedgerMaster ().getCompleteLedgers (); - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mSubLedger.emplace (isrListener->getSeq (), isrListener).second; } // <-- bool: true=erased, false=was not there bool NetworkOPs::unsubLedger (uint64 uSeq) { - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return !!mSubLedger.erase (uSeq); } @@ -2025,48 +2026,48 @@ bool NetworkOPs::subServer (InfoSub::ref isrListener, Json::Value& jvResult) jvResult["load_base"] = getApp().getFeeTrack ().getLoadBase (); jvResult["load_factor"] = getApp().getFeeTrack ().getLoadFactor (); - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mSubServer.emplace (isrListener->getSeq (), isrListener).second; } // <-- bool: true=erased, false=was not there bool NetworkOPs::unsubServer (uint64 uSeq) { - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return !!mSubServer.erase (uSeq); } // <-- bool: true=added, false=already there bool NetworkOPs::subTransactions (InfoSub::ref isrListener) { - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mSubTransactions.emplace (isrListener->getSeq (), isrListener).second; } // <-- bool: true=erased, false=was not there bool NetworkOPs::unsubTransactions (uint64 uSeq) { - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return !!mSubTransactions.erase (uSeq); } // <-- bool: true=added, false=already there bool NetworkOPs::subRTTransactions (InfoSub::ref isrListener) { - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mSubTransactions.emplace (isrListener->getSeq (), isrListener).second; } // <-- bool: true=erased, false=was not there bool NetworkOPs::unsubRTTransactions (uint64 uSeq) { - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return !!mSubTransactions.erase (uSeq); } InfoSub::pointer NetworkOPs::findRpcSub (const std::string& strUrl) { - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); subRpcMapType::iterator it = mRpcSubMap.find (strUrl); @@ -2078,7 +2079,7 @@ InfoSub::pointer NetworkOPs::findRpcSub (const std::string& strUrl) InfoSub::pointer NetworkOPs::addRpcSub (const std::string& strUrl, InfoSub::ref rspEntry) { - boost::recursive_mutex::scoped_lock sl (mMonitorLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mRpcSubMap.emplace (strUrl, rspEntry); diff --git a/modules/ripple_app/misc/NetworkOPs.h b/modules/ripple_app/misc/NetworkOPs.h index 52e88404fd..f14979f062 100644 --- a/modules/ripple_app/misc/NetworkOPs.h +++ b/modules/ripple_app/misc/NetworkOPs.h @@ -394,6 +394,11 @@ private: typedef boost::unordered_map subRpcMapType; + // XXX Split into more locks. + typedef RippleRecursiveMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; + OperatingMode mMode; bool mNeedNetworkLedger; bool mProposing, mValidating; @@ -420,8 +425,6 @@ private: // Recent positions taken std::map > mRecentPositions; - // XXX Split into more locks. - boost::recursive_mutex mMonitorLock; SubInfoMapType mSubAccount; SubInfoMapType mSubRTAccount; @@ -432,7 +435,7 @@ private: SubMapType mSubTransactions; // all accepted transactions SubMapType mSubRTTransactions; // all proposed and accepted transactions - TaggedCache< uint256, Blob , UptimeTimerAdapter > mFetchPack; + TaggedCacheType< uint256, Blob , UptimeTimerAdapter > mFetchPack; uint32 mFetchSeq; uint32 mLastLoadBase; diff --git a/modules/ripple_app/misc/ripple_Features.cpp b/modules/ripple_app/misc/ripple_Features.cpp index 924c7b656e..4a621ae827 100644 --- a/modules/ripple_app/misc/ripple_Features.cpp +++ b/modules/ripple_app/misc/ripple_Features.cpp @@ -19,7 +19,10 @@ protected: typedef std::pair featureIt_t; typedef boost::unordered_set featureList_t; - boost::mutex mMutex; + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; + featureMap_t mFeatureMap; int mMajorityTime; // Seconds a feature must hold a majority int mMajorityFraction; // 256 = 100% @@ -33,9 +36,9 @@ protected: public: Features (uint32 majorityTime, int majorityFraction) - : mMajorityTime (majorityTime), mMajorityFraction (majorityFraction), mFirstReport (0), mLastReport (0) + : mLock (this, "Features", __FILE__, __LINE__) + , mMajorityTime (majorityTime), mMajorityFraction (majorityFraction), mFirstReport (0), mLastReport (0) { - ; } void addInitialFeatures (); @@ -94,7 +97,7 @@ FeatureState* Features::getCreateFeature (uint256 const& featureHash, bool creat query.append (featureHash.GetHex ()); query.append ("';"); - ScopedLock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); Database* db = getApp().getWalletDB ()->getDB (); if (db->executeSQL (query) && db->startIterRows ()) @@ -149,7 +152,7 @@ FeatureState* Features::addKnownFeature (const char* featureID, const char* frie bool Features::vetoFeature (uint256 const& feature) { - boost::mutex::scoped_lock sl (mMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); FeatureState* s = getCreateFeature (feature, true); if (s->mVetoed) @@ -161,7 +164,7 @@ bool Features::vetoFeature (uint256 const& feature) bool Features::unVetoFeature (uint256 const& feature) { - boost::mutex::scoped_lock sl (mMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); FeatureState* s = getCreateFeature (feature, false); if (!s || !s->mVetoed) @@ -173,7 +176,7 @@ bool Features::unVetoFeature (uint256 const& feature) bool Features::enableFeature (uint256 const& feature) { - boost::mutex::scoped_lock sl (mMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); FeatureState* s = getCreateFeature (feature, true); if (s->mEnabled) @@ -185,7 +188,7 @@ bool Features::enableFeature (uint256 const& feature) bool Features::disableFeature (uint256 const& feature) { - boost::mutex::scoped_lock sl (mMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); FeatureState* s = getCreateFeature (feature, false); if (!s || !s->mEnabled) @@ -197,14 +200,14 @@ bool Features::disableFeature (uint256 const& feature) bool Features::isFeatureEnabled (uint256 const& feature) { - boost::mutex::scoped_lock sl (mMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); FeatureState* s = getCreateFeature (feature, false); return s && s->mEnabled; } bool Features::isFeatureSupported (uint256 const& feature) { - boost::mutex::scoped_lock sl (mMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); FeatureState* s = getCreateFeature (feature, false); return s && s->mSupported; } @@ -212,7 +215,7 @@ bool Features::isFeatureSupported (uint256 const& feature) Features::featureList_t Features::getVetoedFeatures () { featureList_t ret; - boost::mutex::scoped_lock sl (mMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); BOOST_FOREACH (const featureIt_t & it, mFeatureMap) { if (it.second.mVetoed) @@ -224,7 +227,7 @@ Features::featureList_t Features::getVetoedFeatures () Features::featureList_t Features::getEnabledFeatures () { featureList_t ret; - boost::mutex::scoped_lock sl (mMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); BOOST_FOREACH (const featureIt_t & it, mFeatureMap) { if (it.second.mEnabled) @@ -252,7 +255,7 @@ bool Features::shouldEnable (uint32 closeTime, const FeatureState& fs) Features::featureList_t Features::getFeaturesToEnable (uint32 closeTime) { featureList_t ret; - boost::mutex::scoped_lock sl (mMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (mLastReport != 0) { @@ -269,7 +272,7 @@ Features::featureList_t Features::getFeaturesToEnable (uint32 closeTime) Features::featureList_t Features::getDesiredFeatures () { featureList_t ret; - boost::mutex::scoped_lock sl (mMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); BOOST_FOREACH (const featureIt_t & it, mFeatureMap) { if (it.second.mSupported && !it.second.mEnabled && !it.second.mVetoed) @@ -287,7 +290,7 @@ void Features::reportValidations (const FeatureSet& set) typedef std::map::value_type u256_int_pair; - boost::mutex::scoped_lock sl (mMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (mFirstReport == 0) mFirstReport = set.mCloseTime; @@ -327,7 +330,7 @@ void Features::reportValidations (const FeatureSet& set) if (!changedFeatures.empty ()) { - ScopedLock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); Database* db = getApp().getWalletDB ()->getDB (); db->executeSQL ("BEGIN TRANSACTION;"); @@ -348,7 +351,7 @@ void Features::reportValidations (const FeatureSet& set) void Features::setEnabledFeatures (const std::vector& features) { - boost::mutex::scoped_lock sl (mMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); BOOST_FOREACH (featureIt_t & it, mFeatureMap) { it.second.mEnabled = false; @@ -361,7 +364,7 @@ void Features::setEnabledFeatures (const std::vector& features) void Features::setSupportedFeatures (const std::vector& features) { - boost::mutex::scoped_lock sl (mMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); BOOST_FOREACH (featureIt_t & it, mFeatureMap) { it.second.mSupported = false; @@ -420,7 +423,7 @@ Json::Value Features::getJson (int) { Json::Value ret (Json::objectValue); { - boost::mutex::scoped_lock sl (mMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); BOOST_FOREACH (const featureIt_t & it, mFeatureMap) { setJson (ret[it.first.GetHex ()] = Json::objectValue, it.second); @@ -477,7 +480,7 @@ void Features::setJson (Json::Value& v, const FeatureState& fs) Json::Value Features::getJson (uint256 const& feature) { Json::Value ret = Json::objectValue; - boost::mutex::scoped_lock sl (mMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); setJson (ret[feature.GetHex ()] = Json::objectValue, *getCreateFeature (feature, true)); return ret; } diff --git a/modules/ripple_app/misc/ripple_HashRouter.cpp b/modules/ripple_app/misc/ripple_HashRouter.cpp index c11c824e1e..670f915fa1 100644 --- a/modules/ripple_app/misc/ripple_HashRouter.cpp +++ b/modules/ripple_app/misc/ripple_HashRouter.cpp @@ -68,7 +68,8 @@ private: public: explicit HashRouter (int holdTime) - : mHoldTime (holdTime) + : mLock (this, "HashRouter", __FILE__, __LINE__) + , mHoldTime (holdTime) { } @@ -87,7 +88,9 @@ private: Entry& findCreateEntry (uint256 const& , bool& created); - boost::mutex mSuppressionMutex; + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; // Stores all suppressed hashes and their expiration time boost::unordered_map mSuppressionMap; @@ -131,7 +134,7 @@ HashRouter::Entry& HashRouter::findCreateEntry (uint256 const& index, bool& crea bool HashRouter::addSuppression (uint256 const& index) { - boost::mutex::scoped_lock sl (mSuppressionMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); bool created; findCreateEntry (index, created); @@ -140,7 +143,7 @@ bool HashRouter::addSuppression (uint256 const& index) HashRouter::Entry HashRouter::getEntry (uint256 const& index) { - boost::mutex::scoped_lock sl (mSuppressionMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); bool created; return findCreateEntry (index, created); @@ -148,7 +151,7 @@ HashRouter::Entry HashRouter::getEntry (uint256 const& index) bool HashRouter::addSuppressionPeer (uint256 const& index, uint64 peer) { - boost::mutex::scoped_lock sl (mSuppressionMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); bool created; findCreateEntry (index, created).addPeer (peer); @@ -157,7 +160,7 @@ bool HashRouter::addSuppressionPeer (uint256 const& index, uint64 peer) bool HashRouter::addSuppressionPeer (uint256 const& index, uint64 peer, int& flags) { - boost::mutex::scoped_lock sl (mSuppressionMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); bool created; Entry& s = findCreateEntry (index, created); @@ -168,7 +171,7 @@ bool HashRouter::addSuppressionPeer (uint256 const& index, uint64 peer, int& fla int HashRouter::getFlags (uint256 const& index) { - boost::mutex::scoped_lock sl (mSuppressionMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); bool created; return findCreateEntry (index, created).getFlags (); @@ -176,7 +179,7 @@ int HashRouter::getFlags (uint256 const& index) bool HashRouter::addSuppressionFlags (uint256 const& index, int flag) { - boost::mutex::scoped_lock sl (mSuppressionMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); bool created; findCreateEntry (index, created).setFlag (flag); @@ -192,7 +195,7 @@ bool HashRouter::setFlag (uint256 const& index, int flag) // return: true = changed, false = unchanged assert (flag != 0); - boost::mutex::scoped_lock sl (mSuppressionMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); bool created; Entry& s = findCreateEntry (index, created); @@ -206,7 +209,7 @@ bool HashRouter::setFlag (uint256 const& index, int flag) bool HashRouter::swapSet (uint256 const& index, std::set& peers, int flag) { - boost::mutex::scoped_lock sl (mSuppressionMutex); + ScopedLockType sl (mLock, __FILE__, __LINE__); bool created; Entry& s = findCreateEntry (index, created); diff --git a/modules/ripple_app/misc/ripple_InfoSub.cpp b/modules/ripple_app/misc/ripple_InfoSub.cpp index cc60ea7850..f31469a037 100644 --- a/modules/ripple_app/misc/ripple_InfoSub.cpp +++ b/modules/ripple_app/misc/ripple_InfoSub.cpp @@ -16,13 +16,12 @@ // there's a functional network. // VFALCO TODO Figure out how to clean up these globals -uint64 InfoSub::sSeq = 0; -boost::mutex InfoSub::sSeqLock; InfoSub::InfoSub () + : mLock (this, "InfoSub", __FILE__, __LINE__) { - boost::mutex::scoped_lock sl (sSeqLock); - mSeq = ++sSeq; + static Atomic s_seq_id; + mSeq = ++s_seq_id; } InfoSub::~InfoSub () @@ -52,7 +51,7 @@ void InfoSub::onSendEmpty () void InfoSub::insertSubAccountInfo (RippleAddress addr, uint32 uLedgerIndex) { - boost::mutex::scoped_lock sl (mLockInfo); + ScopedLockType sl (mLock, __FILE__, __LINE__); mSubAccountInfo.insert (addr); } diff --git a/modules/ripple_app/misc/ripple_InfoSub.h b/modules/ripple_app/misc/ripple_InfoSub.h index 2aa6fa464b..a4b1b5eb43 100644 --- a/modules/ripple_app/misc/ripple_InfoSub.h +++ b/modules/ripple_app/misc/ripple_InfoSub.h @@ -48,14 +48,11 @@ public: boost::shared_ptr const& getPathRequest (); protected: - // VFALCO TODO make accessor for this member - boost::mutex mLockInfo; + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; private: - // VFALCO TODO Move these globals to class instance - static uint64 sSeq; - static boost::mutex sSeqLock; - boost::unordered_set mSubAccountInfo; boost::unordered_set mSubAccountTransaction; boost::shared_ptr mPathRequest; diff --git a/modules/ripple_app/misc/ripple_ProofOfWorkFactory.cpp b/modules/ripple_app/misc/ripple_ProofOfWorkFactory.cpp index 0c0f596670..54e6acbcf1 100644 --- a/modules/ripple_app/misc/ripple_ProofOfWorkFactory.cpp +++ b/modules/ripple_app/misc/ripple_ProofOfWorkFactory.cpp @@ -4,7 +4,9 @@ */ //============================================================================== -ProofOfWorkFactory::ProofOfWorkFactory () : mValidTime (180) +ProofOfWorkFactory::ProofOfWorkFactory () + : mLock (this, "PoWFactory", __FILE__, __LINE__) + , mValidTime (180) { setDifficulty (1); RandomNumbers::getInstance ().fillBytes (mSecret.begin (), mSecret.size ()); @@ -20,7 +22,7 @@ ProofOfWork ProofOfWorkFactory::getProof () uint256 challenge; RandomNumbers::getInstance ().fillBytes (challenge.begin (), challenge.size ()); - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); std::string s = boost::str (boost::format (f) % challenge.GetHex () % mTarget.GetHex () % mIterations % now); std::string c = mSecret.GetHex () + s; @@ -70,7 +72,7 @@ POWResult ProofOfWorkFactory::checkProof (const std::string& token, uint256 cons int iterations = lexicalCast (fields[2]); { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if ((t * 4) > (now + mValidTime)) { @@ -95,7 +97,7 @@ POWResult ProofOfWorkFactory::checkProof (const std::string& token, uint256 cons } { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (!mSolvedChallenges.insert (powMap_vt (now, challenge)).second) { @@ -111,7 +113,7 @@ void ProofOfWorkFactory::sweep () { time_t expire = time (NULL) - mValidTime; - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); do { @@ -132,7 +134,7 @@ void ProofOfWorkFactory::loadHigh () { time_t now = time (NULL); - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (mLastDifficultyChange == now) return; @@ -148,7 +150,7 @@ void ProofOfWorkFactory::loadLow () { time_t now = time (NULL); - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (mLastDifficultyChange == now) return; @@ -229,7 +231,7 @@ void ProofOfWorkFactory::setDifficulty (int i) assert ((i >= 0) && (i <= ProofOfWork::sMaxDifficulty)); time_t now = time (NULL); - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mPowEntry = i; mIterations = PowEntries[i].iterations; mTarget.SetHex (PowEntries[i].target); diff --git a/modules/ripple_app/misc/ripple_ProofOfWorkFactory.h b/modules/ripple_app/misc/ripple_ProofOfWorkFactory.h index 23837718be..c82b2cfb0f 100644 --- a/modules/ripple_app/misc/ripple_ProofOfWorkFactory.h +++ b/modules/ripple_app/misc/ripple_ProofOfWorkFactory.h @@ -40,6 +40,10 @@ public: static int getPowEntry (uint256 const& target, int iterations); private: + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; + uint256 mSecret; int mIterations; uint256 mTarget; @@ -48,7 +52,6 @@ private: int mPowEntry; powMap_t mSolvedChallenges; - boost::mutex mLock; }; #endif diff --git a/modules/ripple_app/misc/ripple_Validations.cpp b/modules/ripple_app/misc/ripple_Validations.cpp index 016c305a11..c6347fd973 100644 --- a/modules/ripple_app/misc/ripple_Validations.cpp +++ b/modules/ripple_app/misc/ripple_Validations.cpp @@ -14,8 +14,12 @@ typedef boost::shared_ptr VSpointer; class Validations : public IValidations { private: - boost::mutex mValidationLock; - TaggedCache mValidations; + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + typedef LockType::ScopedUnlockType ScopedUnlockType; + LockType mLock; + + TaggedCacheType mValidations; boost::unordered_map mCurrentValidations; std::vector mStaleValidations; @@ -41,7 +45,9 @@ private: } public: - Validations () : mValidations ("Validations", 128, 600), mWriting (false) + Validations () + : mLock (this, "Validations", __FILE__, __LINE__) + , mValidations ("Validations", 128, 600), mWriting (false) { mStaleValidations.reserve (512); } @@ -75,7 +81,7 @@ private: uint160 node = signer.getNodeID (); { - boost::mutex::scoped_lock sl (mValidationLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (!findCreateSet (hash)->insert (std::make_pair (node, val)).second) return false; @@ -119,7 +125,7 @@ private: ValidationSet getValidations (uint256 const& ledger) { { - boost::mutex::scoped_lock sl (mValidationLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); VSpointer set = findSet (ledger); if (set) @@ -131,7 +137,7 @@ private: void getValidationCount (uint256 const& ledger, bool currentOnly, int& trusted, int& untrusted) { trusted = untrusted = 0; - boost::mutex::scoped_lock sl (mValidationLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); VSpointer set = findSet (ledger); if (set) @@ -166,7 +172,7 @@ private: void getValidationTypes (uint256 const& ledger, int& full, int& partial) { full = partial = 0; - boost::mutex::scoped_lock sl (mValidationLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); VSpointer set = findSet (ledger); if (set) @@ -190,7 +196,7 @@ private: int getTrustedValidationCount (uint256 const& ledger) { int trusted = 0; - boost::mutex::scoped_lock sl (mValidationLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); VSpointer set = findSet (ledger); if (set) @@ -210,7 +216,7 @@ private: int trusted = 0; fee = 0; - boost::mutex::scoped_lock sl (mValidationLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); VSpointer set = findSet (ledger); if (set) @@ -239,7 +245,7 @@ private: { // Number of trusted nodes that have moved past this ledger int count = 0; - boost::mutex::scoped_lock sl (mValidationLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); BOOST_FOREACH (u160_val_pair & it, mCurrentValidations) { if (it.second->isTrusted () && it.second->isPreviousHash (ledger)) @@ -254,7 +260,7 @@ private: int goodNodes = overLoaded ? 1 : 0; int badNodes = overLoaded ? 0 : 1; { - boost::mutex::scoped_lock sl (mValidationLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); BOOST_FOREACH (u160_val_pair & it, mCurrentValidations) { if (it.second->isTrusted ()) @@ -275,7 +281,7 @@ private: std::list ret; - boost::mutex::scoped_lock sl (mValidationLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); boost::unordered_map::iterator it = mCurrentValidations.begin (); while (it != mCurrentValidations.end ()) @@ -312,7 +318,7 @@ private: boost::unordered_map ret; - boost::mutex::scoped_lock sl (mValidationLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); boost::unordered_map::iterator it = mCurrentValidations.begin (); while (it != mCurrentValidations.end ()) @@ -359,7 +365,7 @@ private: bool anyNew = false; WriteLog (lsINFO, Validations) << "Flushing validations"; - boost::mutex::scoped_lock sl (mValidationLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); BOOST_FOREACH (u160_val_pair & it, mCurrentValidations) { if (it.second) @@ -374,9 +380,8 @@ private: while (mWriting) { - sl.unlock (); + ScopedUnlockType sul (mLock, __FILE__, __LINE__); boost::this_thread::sleep (boost::posix_time::milliseconds (100)); - sl.lock (); } WriteLog (lsDEBUG, Validations) << "Validations flushed"; @@ -398,7 +403,7 @@ private: boost::format insVal ("INSERT INTO Validations " "(LedgerHash,NodePubKey,SignTime,RawData) VALUES ('%s','%s','%u',%s);"); - boost::mutex::scoped_lock sl (mValidationLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); assert (mWriting); while (!mStaleValidations.empty ()) @@ -406,24 +411,26 @@ private: std::vector vector; vector.reserve (512); mStaleValidations.swap (vector); - sl.unlock (); - { - Database* db = getApp().getLedgerDB ()->getDB (); - ScopedLock dbl (getApp().getLedgerDB ()->getDBLock ()); - Serializer s (1024); - db->executeSQL ("BEGIN TRANSACTION;"); - BOOST_FOREACH (SerializedValidation::ref it, vector) + { + ScopedUnlockType sul (mLock, __FILE__, __LINE__); { - s.erase (); - it->add (s); - db->executeSQL (boost::str (insVal % it->getLedgerHash ().GetHex () - % it->getSignerPublic ().humanNodePublic () % it->getSignTime () - % sqlEscape (s.peekData ()))); + Database* db = getApp().getLedgerDB ()->getDB (); + DeprecatedScopedLock dbl (getApp().getLedgerDB ()->getDBLock ()); + + Serializer s (1024); + db->executeSQL ("BEGIN TRANSACTION;"); + BOOST_FOREACH (SerializedValidation::ref it, vector) + { + s.erase (); + it->add (s); + db->executeSQL (boost::str (insVal % it->getLedgerHash ().GetHex () + % it->getSignerPublic ().humanNodePublic () % it->getSignTime () + % sqlEscape (s.peekData ()))); + } + db->executeSQL ("END TRANSACTION;"); } - db->executeSQL ("END TRANSACTION;"); } - sl.lock (); } mWriting = false; @@ -431,7 +438,7 @@ private: void sweep () { - boost::mutex::scoped_lock sl (mValidationLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mValidations.sweep (); } }; diff --git a/modules/ripple_app/network/WSConnection.h b/modules/ripple_app/network/WSConnection.h index 02c7f49df5..dd60bbfa1b 100644 --- a/modules/ripple_app/network/WSConnection.h +++ b/modules/ripple_app/network/WSConnection.h @@ -11,6 +11,12 @@ // This is for logging struct WSConnectionLog; +// Helps with naming the lock +struct WSConnectionBase +{ + +}; + template class WSServerHandler; // @@ -19,7 +25,8 @@ class WSServerHandler; // template class WSConnection - : public InfoSub + : public WSConnectionBase + , public InfoSub , public boost::enable_shared_from_this< WSConnection > , public CountedObject > { @@ -37,7 +44,8 @@ public: // mConnection(connection_ptr()) { ; } WSConnection (WSServerHandler* wshpHandler, const connection_ptr& cpConnection) - : mHandler (wshpHandler), mConnection (cpConnection), mNetwork (getApp().getOPs ()), + : mRcvQueueLock (static_cast(this), "WSConn", __FILE__, __LINE__) + , mHandler (wshpHandler), mConnection (cpConnection), mNetwork (getApp().getOPs ()), mRemoteIP (cpConnection->get_socket ().lowest_layer ().remote_endpoint ().address ().to_string ()), mLoadSource (mRemoteIP), mPingTimer (cpConnection->get_io_service ()), mPinged (false), mRcvQueueRunning (false), mDead (false) @@ -52,7 +60,7 @@ public: mPingTimer.cancel (); mConnection.reset (); - boost::recursive_mutex::scoped_lock sl (mRcvQueueLock); + ScopedLockType sl (mRcvQueueLock, __FILE__, __LINE__); mDead = true; } @@ -217,7 +225,7 @@ public: void rcvMessage (message_ptr msg, bool& msgRejected, bool& runQueue) { - boost::recursive_mutex::scoped_lock sl (mRcvQueueLock); + ScopedLockType sl (mRcvQueueLock, __FILE__, __LINE__); if (mDead) { @@ -248,7 +256,7 @@ public: message_ptr getMessage () { - boost::recursive_mutex::scoped_lock sl (mRcvQueueLock); + ScopedLockType sl (mRcvQueueLock, __FILE__, __LINE__); if (mDead || mRcvQueue.empty ()) { @@ -264,6 +272,8 @@ public: private: typedef void (WSConnection::*doFuncPtr) (Json::Value& jvResult, Json::Value& jvRequest); + LockType mRcvQueueLock; + WSServerHandler* mHandler; weak_connection_ptr mConnection; NetworkOPs& mNetwork; @@ -273,7 +283,6 @@ private: boost::asio::deadline_timer mPingTimer; bool mPinged; - boost::recursive_mutex mRcvQueueLock; std::queue mRcvQueue; bool mRcvQueueRunning; bool mDead; diff --git a/modules/ripple_app/network/WSDoor.cpp b/modules/ripple_app/network/WSDoor.cpp index 7f1ebf1347..4acb9c3c53 100644 --- a/modules/ripple_app/network/WSDoor.cpp +++ b/modules/ripple_app/network/WSDoor.cpp @@ -24,6 +24,7 @@ SETUP_LOG (WSDoor) WSDoor::WSDoor (std::string const& strIp, int iPort, bool bPublic) : Thread ("websocket") + , m_endpointLock (this, "WSDoor", __FILE__, __LINE__) , mPublic (bPublic) , mIp (strIp) , mPort (iPort) @@ -34,7 +35,7 @@ WSDoor::WSDoor (std::string const& strIp, int iPort, bool bPublic) WSDoor::~WSDoor () { { - CriticalSection::ScopedLockType lock (m_endpointLock); + ScopedLockType lock (m_endpointLock, __FILE__, __LINE__); if (m_endpoint != nullptr) m_endpoint->stop (); @@ -65,7 +66,7 @@ void WSDoor::run () websocketpp::server_autotls::handler::ptr handler (new WSServerHandler (mCtx, mPublic)); { - CriticalSection::ScopedLockType lock (m_endpointLock); + ScopedLockType lock (m_endpointLock, __FILE__, __LINE__); m_endpoint = new websocketpp::server_autotls (handler); } @@ -105,7 +106,7 @@ void WSDoor::run () void WSDoor::stop () { { - CriticalSection::ScopedLockType lock (m_endpointLock); + ScopedLockType lock (m_endpointLock, __FILE__, __LINE__); if (m_endpoint != nullptr) m_endpoint->stop (); diff --git a/modules/ripple_app/network/WSDoor.h b/modules/ripple_app/network/WSDoor.h index 39f64d0d37..135ad577ad 100644 --- a/modules/ripple_app/network/WSDoor.h +++ b/modules/ripple_app/network/WSDoor.h @@ -20,8 +20,11 @@ private: void run (); private: + typedef RippleRecursiveMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType m_endpointLock; + ScopedPointer m_endpoint; - CriticalSection m_endpointLock; bool mPublic; std::string mIp; int mPort; diff --git a/modules/ripple_app/network/ripple_WSHandler.h b/modules/ripple_app/network/ripple_WSHandler.h index e6d2c11ee8..56a1f1b7c7 100644 --- a/modules/ripple_app/network/ripple_WSHandler.h +++ b/modules/ripple_app/network/ripple_WSHandler.h @@ -16,12 +16,18 @@ class WSConnection; struct WSServerHandlerLog; +// This tag helps with mutex tracking +struct WSServerHandlerBase +{ +}; + // A single instance of this object is made. // This instance dispatches all events. There is no per connection persistence. template class WSServerHandler - : public endpoint_type::handler + : public WSServerHandlerBase + , public endpoint_type::handler , LeakChecked > { public: @@ -35,17 +41,25 @@ public: crTooSlow = 4000, // Client is too slow. }; +protected: + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; + private: boost::shared_ptr mCtx; protected: - boost::mutex mMapLock; + // For each connection maintain an associated object to track subscriptions. boost::unordered_map > > mMap; bool mPublic; public: - WSServerHandler (boost::shared_ptr spCtx, bool bPublic) : mCtx (spCtx), mPublic (bPublic) + WSServerHandler (boost::shared_ptr spCtx, bool bPublic) + : mLock (static_cast (this), "WSServerHandler", __FILE__, __LINE__) + , mCtx (spCtx) + , mPublic (bPublic) { if (getConfig ().WEBSOCKET_SECURE != 0) { @@ -118,7 +132,7 @@ public: { wsc_ptr ptr; { - boost::mutex::scoped_lock sl (mMapLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); typename boost::unordered_map::iterator it = mMap.find (cpClient); if (it == mMap.end ()) @@ -141,7 +155,7 @@ public: { wsc_ptr ptr; { - boost::mutex::scoped_lock sl (mMapLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); typename boost::unordered_map::iterator it = mMap.find (cpClient); if (it == mMap.end ()) @@ -155,7 +169,7 @@ public: void on_open (connection_ptr cpClient) { - boost::mutex::scoped_lock sl (mMapLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); try { @@ -170,7 +184,7 @@ public: { wsc_ptr ptr; { - boost::mutex::scoped_lock sl (mMapLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); typename boost::unordered_map::iterator it = mMap.find (cpClient); if (it == mMap.end ()) @@ -186,7 +200,7 @@ public: // we cannot destroy the connection while holding the map lock or we deadlock with pubLedger wsc_ptr ptr; { - boost::mutex::scoped_lock sl (mMapLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); typename boost::unordered_map::iterator it = mMap.find (cpClient); if (it == mMap.end ()) @@ -206,7 +220,7 @@ public: { wsc_ptr ptr; { - boost::mutex::scoped_lock sl (mMapLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); typename boost::unordered_map::iterator it = mMap.find (cpClient); if (it == mMap.end ()) @@ -240,7 +254,7 @@ public: { wsc_ptr ptr; { - boost::mutex::scoped_lock sl (mMapLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); typename boost::unordered_map::iterator it = mMap.find (cpClient); if (it == mMap.end ()) diff --git a/modules/ripple_app/node/ripple_NodeStore.cpp b/modules/ripple_app/node/ripple_NodeStore.cpp index 04b976da05..1d4c89058a 100644 --- a/modules/ripple_app/node/ripple_NodeStore.cpp +++ b/modules/ripple_app/node/ripple_NodeStore.cpp @@ -508,7 +508,7 @@ private: ScopedPointer m_fastBackend; // VFALCO NOTE What are these things for? We need comments. - TaggedCache m_cache; + TaggedCacheType m_cache; KeyCache m_negativeCache; }; diff --git a/modules/ripple_app/node/ripple_SqliteBackendFactory.cpp b/modules/ripple_app/node/ripple_SqliteBackendFactory.cpp index 178cd1355c..3064073571 100644 --- a/modules/ripple_app/node/ripple_SqliteBackendFactory.cpp +++ b/modules/ripple_app/node/ripple_SqliteBackendFactory.cpp @@ -64,7 +64,7 @@ public: pObject->reset (); { - ScopedLock sl (m_db->getDBLock()); + DeprecatedScopedLock sl (m_db->getDBLock()); uint256 const hash (uint256::fromVoid (key)); @@ -108,7 +108,7 @@ public: { // VFALCO TODO Rewrite this to use Beast::db - ScopedLock sl (m_db->getDBLock()); + DeprecatedScopedLock sl (m_db->getDBLock()); static SqliteStatement pStB (m_db->getDB()->getSqliteDB(), "BEGIN TRANSACTION;"); static SqliteStatement pStE (m_db->getDB()->getSqliteDB(), "END TRANSACTION;"); diff --git a/modules/ripple_app/paths/ripple_PathRequest.cpp b/modules/ripple_app/paths/ripple_PathRequest.cpp index 0ff8d05f9b..e00151df00 100644 --- a/modules/ripple_app/paths/ripple_PathRequest.cpp +++ b/modules/ripple_app/paths/ripple_PathRequest.cpp @@ -7,11 +7,12 @@ SETUP_LOG (PathRequest) // VFALCO TODO Move these globals into a PathRequests collection inteface -boost::recursive_mutex PathRequest::sLock; +PathRequest::StaticLockType PathRequest::sLock ("PathRequest", __FILE__, __LINE__); std::set PathRequest::sRequests; PathRequest::PathRequest (const boost::shared_ptr& subscriber) - : wpSubscriber (subscriber) + : mLock (this, "PathRequest", __FILE__, __LINE__) + , wpSubscriber (subscriber) , jvStatus (Json::objectValue) , bValid (false) , bNew (true) @@ -20,19 +21,19 @@ PathRequest::PathRequest (const boost::shared_ptr& subscriber) bool PathRequest::isValid () { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return bValid; } bool PathRequest::isNew () { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return bNew; } bool PathRequest::isValid (Ledger::ref lrLedger) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); bValid = raSrcAccount.isSet () && raDstAccount.isSet () && saDstAmount.isPositive (); if (bValid) @@ -93,7 +94,7 @@ Json::Value PathRequest::doCreate (Ledger::ref lrLedger, const Json::Value& valu bool mValid; { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (parseJson (value, true) != PFR_PJ_INVALID) { @@ -115,7 +116,7 @@ Json::Value PathRequest::doCreate (Ledger::ref lrLedger, const Json::Value& valu " -> " << raDstAccount.humanAccountID (); WriteLog (lsINFO, PathRequest) << "Deliver: " << saDstAmount.getFullText (); - boost::recursive_mutex::scoped_lock sl (sLock); + StaticScopedLockType sl (sLock, __FILE__, __LINE__); sRequests.insert (shared_from_this ()); } @@ -216,19 +217,19 @@ int PathRequest::parseJson (const Json::Value& jvParams, bool complete) } Json::Value PathRequest::doClose (const Json::Value&) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return jvStatus; } Json::Value PathRequest::doStatus (const Json::Value&) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return jvStatus; } bool PathRequest::doUpdate (RippleLineCache::ref cache, bool fast) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); jvStatus = Json::objectValue; if (!isValid (cache->getLedger ())) @@ -318,7 +319,7 @@ void PathRequest::updateAll (Ledger::ref ledger, bool newOnly) std::set requests; { - boost::recursive_mutex::scoped_lock sl (sLock); + StaticScopedLockType sl (sLock, __FILE__, __LINE__); requests = sRequests; } @@ -344,7 +345,7 @@ void PathRequest::updateAll (Ledger::ref ledger, bool newOnly) { Json::Value update; { - boost::recursive_mutex::scoped_lock sl (pRequest->mLock); + ScopedLockType sl (pRequest->mLock, __FILE__, __LINE__); pRequest->doUpdate (cache, false); update = pRequest->jvStatus; } @@ -357,7 +358,7 @@ void PathRequest::updateAll (Ledger::ref ledger, bool newOnly) if (remove) { - boost::recursive_mutex::scoped_lock sl (sLock); + StaticScopedLockType sl (sLock, __FILE__, __LINE__); sRequests.erase (wRequest); } } diff --git a/modules/ripple_app/paths/ripple_PathRequest.h b/modules/ripple_app/paths/ripple_PathRequest.h index 1f988049c7..1575bed472 100644 --- a/modules/ripple_app/paths/ripple_PathRequest.h +++ b/modules/ripple_app/paths/ripple_PathRequest.h @@ -44,7 +44,13 @@ public: static void updateAll (const boost::shared_ptr& ledger, bool newOnly); private: - boost::recursive_mutex mLock; + void setValid (); + int parseJson (const Json::Value&, bool complete); + + typedef RippleRecursiveMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; + boost::weak_ptr wpSubscriber; // Who this request came from Json::Value jvId; Json::Value jvStatus; // Last result @@ -61,10 +67,10 @@ private: // Track all requests static std::set sRequests; - static boost::recursive_mutex sLock; - void setValid (); - int parseJson (const Json::Value&, bool complete); + typedef RippleRecursiveMutex StaticLockType; + typedef LockType::ScopedLockType StaticScopedLockType; + static StaticLockType sLock; }; #endif diff --git a/modules/ripple_app/paths/ripple_RippleLineCache.cpp b/modules/ripple_app/paths/ripple_RippleLineCache.cpp index 49f258a972..68f4fee80b 100644 --- a/modules/ripple_app/paths/ripple_RippleLineCache.cpp +++ b/modules/ripple_app/paths/ripple_RippleLineCache.cpp @@ -4,9 +4,15 @@ */ //============================================================================== +RippleLineCache::RippleLineCache (Ledger::ref l) + : mLock (this, "RippleLineCache", __FILE__, __LINE__) + , mLedger (l) +{ +} + AccountItems& RippleLineCache::getRippleLines (const uint160& accountID) { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); boost::unordered_map ::iterator it = mRLMap.find (accountID); diff --git a/modules/ripple_app/paths/ripple_RippleLineCache.h b/modules/ripple_app/paths/ripple_RippleLineCache.h index a23525310b..e08f93e080 100644 --- a/modules/ripple_app/paths/ripple_RippleLineCache.h +++ b/modules/ripple_app/paths/ripple_RippleLineCache.h @@ -14,10 +14,7 @@ public: typedef boost::shared_ptr pointer; typedef pointer const& ref; - explicit RippleLineCache (Ledger::ref l) - : mLedger (l) - { - } + explicit RippleLineCache (Ledger::ref l); Ledger::ref getLedger () // VFALCO TODO const? { @@ -27,8 +24,10 @@ public: AccountItems& getRippleLines (const uint160& accountID); private: - boost::mutex mLock; - + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; + Ledger::pointer mLedger; boost::unordered_map mRLMap; diff --git a/modules/ripple_app/peers/ripple_PeerSet.cpp b/modules/ripple_app/peers/ripple_PeerSet.cpp index 15e9ef6ae0..92038efa81 100644 --- a/modules/ripple_app/peers/ripple_PeerSet.cpp +++ b/modules/ripple_app/peers/ripple_PeerSet.cpp @@ -7,7 +7,8 @@ class InboundLedger; PeerSet::PeerSet (uint256 const& hash, int interval, bool txnData) - : mHash (hash) + : mLock (this, "PeerSet", __FILE__, __LINE__) + , mHash (hash) , mTimerInterval (interval) , mTimeouts (0) , mComplete (false) @@ -22,7 +23,7 @@ PeerSet::PeerSet (uint256 const& hash, int interval, bool txnData) bool PeerSet::peerHas (Peer::ref ptr) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (!mPeers.insert (std::make_pair (ptr->getPeerId (), 0)).second) return false; @@ -33,7 +34,7 @@ bool PeerSet::peerHas (Peer::ref ptr) void PeerSet::badPeer (Peer::ref ptr) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mPeers.erase (ptr->getPeerId ()); } @@ -45,7 +46,7 @@ void PeerSet::setTimer () void PeerSet::invokeOnTimer () { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (isDone ()) return; @@ -100,7 +101,7 @@ void PeerSet::TimerJobEntry (Job&, boost::shared_ptr ptr) bool PeerSet::isActive () { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return !isDone (); } @@ -114,7 +115,7 @@ void PeerSet::sendRequest (const protocol::TMGetLedger& tmGL, Peer::ref peer) void PeerSet::sendRequest (const protocol::TMGetLedger& tmGL) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (mPeers.empty ()) return; diff --git a/modules/ripple_app/peers/ripple_PeerSet.h b/modules/ripple_app/peers/ripple_PeerSet.h index a7155d380f..1b65a2eca3 100644 --- a/modules/ripple_app/peers/ripple_PeerSet.h +++ b/modules/ripple_app/peers/ripple_PeerSet.h @@ -67,11 +67,14 @@ private: // VFALCO TODO try to make some of these private protected: + typedef RippleRecursiveMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + PeerSet (uint256 const& hash, int interval, bool txnData); virtual ~PeerSet () { } virtual void newPeer (Peer::ref) = 0; - virtual void onTimer (bool progress, boost::recursive_mutex::scoped_lock&) = 0; + virtual void onTimer (bool progress, ScopedLockType&) = 0; virtual boost::weak_ptr pmDowncast () = 0; void setComplete () @@ -88,6 +91,8 @@ protected: void sendRequest (const protocol::TMGetLedger& message, Peer::ref peer); protected: + LockType mLock; + uint256 mHash; int mTimerInterval; int mTimeouts; @@ -99,7 +104,6 @@ protected: int mLastProgress; - boost::recursive_mutex mLock; // VFALCO TODO move the responsibility for the timer to a higher level boost::asio::deadline_timer mTimer; diff --git a/modules/ripple_app/peers/ripple_Peers.cpp b/modules/ripple_app/peers/ripple_Peers.cpp index 3e0bc2fc46..cec9a9169e 100644 --- a/modules/ripple_app/peers/ripple_Peers.cpp +++ b/modules/ripple_app/peers/ripple_Peers.cpp @@ -17,7 +17,8 @@ public: }; explicit Peers (boost::asio::io_service& io_service) - : mLastPeer (0) + : mPeerLock (this, "Peers", __FILE__, __LINE__) + , mLastPeer (0) , mPhase (0) , mScanTimer (io_service) , mPolicyTimer (io_service) @@ -81,7 +82,10 @@ public: void makeConfigured (); private: - boost::recursive_mutex mPeerLock; + typedef RippleRecursiveMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mPeerLock; + uint64 mLastPeer; int mPhase; @@ -164,7 +168,7 @@ bool Peers::getTopNAddrs (int n, std::vector& addrs) { // XXX Filter out other local addresses (like ipv6) Database* db = getApp().getWalletDB ()->getDB (); - ScopedLock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); SQL_FOREACH (db, str (boost::format ("SELECT IpPort FROM PeerIps LIMIT %d") % n)) { @@ -189,7 +193,7 @@ bool Peers::savePeer (const std::string& strIp, int iPort, char code) std::string ipAndPort = sqlEscape (str (boost::format ("%s %d") % strIp % iPort)); - ScopedLock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); std::string sql = str (boost::format ("SELECT COUNT(*) FROM PeerIps WHERE IpPort=%s;") % ipAndPort); if (db->executeSQL (sql) && db->startIterRows ()) @@ -223,7 +227,7 @@ bool Peers::savePeer (const std::string& strIp, int iPort, char code) Peer::pointer Peers::getPeerById (const uint64& id) { - boost::recursive_mutex::scoped_lock sl (mPeerLock); + ScopedLockType sl (mPeerLock, __FILE__, __LINE__); const boost::unordered_map::iterator& it = mPeerIdMap.find (id); if (it == mPeerIdMap.end ()) @@ -234,7 +238,7 @@ Peer::pointer Peers::getPeerById (const uint64& id) bool Peers::hasPeer (const uint64& id) { - boost::recursive_mutex::scoped_lock sl (mPeerLock); + ScopedLockType sl (mPeerLock, __FILE__, __LINE__); return mPeerIdMap.find (id) != mPeerIdMap.end (); } @@ -249,7 +253,7 @@ bool Peers::peerAvailable (std::string& strIp, int& iPort) // Convert mIpMap (list of open connections) to a vector of " ". { - boost::recursive_mutex::scoped_lock sl (mPeerLock); + ScopedLockType sl (mPeerLock, __FILE__, __LINE__); vstrIpPort.reserve (mIpMap.size ()); @@ -266,7 +270,7 @@ bool Peers::peerAvailable (std::string& strIp, int& iPort) std::string strIpPort; { - ScopedLock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); if (db->executeSQL (str (boost::format ("SELECT IpPort FROM PeerIps WHERE ScanNext IS NULL AND IpPort NOT IN (%s) LIMIT 1;") % strJoin (vstrIpPort.begin (), vstrIpPort.end (), ","))) @@ -432,7 +436,7 @@ void Peers::connectTo (const std::string& strIp, int iPort) { { Database* db = getApp().getWalletDB ()->getDB (); - ScopedLock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); db->executeSQL (str (boost::format ("REPLACE INTO PeerIps (IpPort,Score,Source,ScanNext) values (%s,%d,'%c',0);") % sqlEscape (str (boost::format ("%s %d") % strIp % iPort)) @@ -453,7 +457,7 @@ Peer::pointer Peers::peerConnect (const std::string& strIp, int iPort) { - boost::recursive_mutex::scoped_lock sl (mPeerLock); + ScopedLockType sl (mPeerLock, __FILE__, __LINE__); if (mIpMap.find (pipPeer) == mIpMap.end ()) { @@ -496,7 +500,7 @@ Json::Value Peers::getPeersJson () int Peers::getPeerCount () { - boost::recursive_mutex::scoped_lock sl (mPeerLock); + ScopedLockType sl (mPeerLock, __FILE__, __LINE__); return mConnectedMap.size (); } @@ -505,7 +509,7 @@ std::vector Peers::getPeerVector () { std::vector ret; - boost::recursive_mutex::scoped_lock sl (mPeerLock); + ScopedLockType sl (mPeerLock, __FILE__, __LINE__); ret.reserve (mConnectedMap.size ()); @@ -520,7 +524,7 @@ std::vector Peers::getPeerVector () uint64 Peers::assignPeerId () { - boost::recursive_mutex::scoped_lock sl (mPeerLock); + ScopedLockType sl (mPeerLock, __FILE__, __LINE__); return ++mLastPeer; } @@ -539,7 +543,7 @@ bool Peers::peerConnected (Peer::ref peer, const RippleAddress& naPeer, } else { - boost::recursive_mutex::scoped_lock sl (mPeerLock); + ScopedLockType sl (mPeerLock, __FILE__, __LINE__); const boost::unordered_map::iterator& itCm = mConnectedMap.find (naPeer); if (itCm == mConnectedMap.end ()) @@ -590,7 +594,7 @@ bool Peers::peerConnected (Peer::ref peer, const RippleAddress& naPeer, // We maintain a map of public key to peer for connected and verified peers. Maintain it. void Peers::peerDisconnected (Peer::ref peer, const RippleAddress& naPeer) { - boost::recursive_mutex::scoped_lock sl (mPeerLock); + ScopedLockType sl (mPeerLock, __FILE__, __LINE__); if (naPeer.isValid ()) { @@ -633,7 +637,7 @@ bool Peers::peerScanSet (const std::string& strIp, int iPort) std::string strIpPort = str (boost::format ("%s %d") % strIp % iPort); bool bScanDirty = false; - ScopedLock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); Database* db = getApp().getWalletDB ()->getDB (); if (db->executeSQL (str (boost::format ("SELECT ScanNext FROM PeerIps WHERE IpPort=%s;") @@ -695,7 +699,7 @@ void Peers::peerClosed (Peer::ref peer, const std::string& strIp, int iPort) // Determine if closed peer was redundant. bool bRedundant = true; { - boost::recursive_mutex::scoped_lock sl (mPeerLock); + ScopedLockType sl (mPeerLock, __FILE__, __LINE__); const boost::unordered_map::iterator& itIp = mIpMap.find (ipPeer); if (itIp == mIpMap.end ()) @@ -752,7 +756,7 @@ void Peers::peerVerified (Peer::ref peer) else { // Talking with a different peer. - ScopedLock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); Database* db = getApp().getWalletDB ()->getDB (); db->executeSQL (boost::str (boost::format ("UPDATE PeerIps SET ScanNext=NULL,ScanInterval=0 WHERE IpPort=%s;") @@ -820,7 +824,7 @@ void Peers::scanRefresh () int iInterval; { - ScopedLock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); Database* db = getApp().getWalletDB ()->getDB (); if (db->executeSQL ("SELECT * FROM PeerIps INDEXED BY PeerScanIndex WHERE ScanNext NOT NULL ORDER BY ScanNext LIMIT 1;") @@ -866,7 +870,7 @@ void Peers::scanRefresh () iInterval *= 2; { - ScopedLock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); Database* db = getApp().getWalletDB ()->getDB (); db->executeSQL (boost::str (boost::format ("UPDATE PeerIps SET ScanNext=%d,ScanInterval=%d WHERE IpPort=%s;") diff --git a/modules/ripple_app/peers/ripple_UniqueNodeList.cpp b/modules/ripple_app/peers/ripple_UniqueNodeList.cpp index 21997d2412..399152bc35 100644 --- a/modules/ripple_app/peers/ripple_UniqueNodeList.cpp +++ b/modules/ripple_app/peers/ripple_UniqueNodeList.cpp @@ -90,7 +90,9 @@ private: public: UniqueNodeListImp () - : m_scoreTimer (this) + : mFetchLock (this, "Fetch", __FILE__, __LINE__) + , mUNLLock (this, "UNL", __FILE__, __LINE__) + , m_scoreTimer (this) , mFetchActive (0) , m_fetchTimer (this) { @@ -233,7 +235,7 @@ public: { { Database* db = getApp().getWalletDB ()->getDB (); - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); db->executeSQL (str (boost::format ("DELETE FROM SeedNodes WHERE PublicKey=%s") % sqlEscape (naNodePublic.humanNodePublic ()))); db->executeSQL (str (boost::format ("DELETE FROM TrustedNodes WHERE PublicKey=%s") % sqlEscape (naNodePublic.humanNodePublic ()))); @@ -242,7 +244,7 @@ public: // YYY Only dirty on successful delete. fetchDirty (); - boost::recursive_mutex::scoped_lock sl (mUNLLock); + ScopedUNLLockType sl (mUNLLock, __FILE__, __LINE__); mUNL.erase (naNodePublic.humanNodePublic ()); } @@ -255,7 +257,7 @@ public: { Database* db = getApp().getWalletDB ()->getDB (); - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); db->executeSQL (str (boost::format ("DELETE FROM SeedDomains WHERE Domain=%s") % sqlEscape (strDomain))); } @@ -271,7 +273,7 @@ public: { Database* db = getApp().getWalletDB ()->getDB (); - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); // XXX Check results. db->executeSQL ("DELETE FROM SeedDomains"); @@ -293,7 +295,7 @@ public: bool nodeInUNL (const RippleAddress& naNodePublic) { - boost::recursive_mutex::scoped_lock sl (mUNLLock); + ScopedUNLLockType sl (mUNLLock, __FILE__, __LINE__); return mUNL.end () != mUNL.find (naNodePublic.humanNodePublic ()); } @@ -302,7 +304,7 @@ public: bool nodeInCluster (const RippleAddress& naNodePublic) { - boost::recursive_mutex::scoped_lock sl (mUNLLock); + ScopedUNLLockType sl (mUNLLock, __FILE__, __LINE__); return m_clusterNodes.end () != m_clusterNodes.find (naNodePublic); } @@ -310,7 +312,7 @@ public: bool nodeInCluster (const RippleAddress& naNodePublic, std::string& name) { - boost::recursive_mutex::scoped_lock sl (mUNLLock); + ScopedUNLLockType sl (mUNLLock, __FILE__, __LINE__); std::map::iterator it = m_clusterNodes.find (naNodePublic); if (it == m_clusterNodes.end ()) @@ -324,7 +326,7 @@ public: bool nodeUpdate (const RippleAddress& naNodePublic, ClusterNodeStatus const& cnsStatus) { - boost::recursive_mutex::scoped_lock sl (mUNLLock); + ScopedUNLLockType sl (mUNLLock, __FILE__, __LINE__); return m_clusterNodes[naNodePublic].update(cnsStatus); } @@ -334,7 +336,7 @@ public: { std::map ret; { - boost::recursive_mutex::scoped_lock sl (mUNLLock); + ScopedUNLLockType sl (mUNLLock, __FILE__, __LINE__); ret = m_clusterNodes; } return ret; @@ -347,7 +349,7 @@ public: int thresh = getApp().getOPs().getNetworkTimeNC() - 120; uint32 a = 0, b = 0; - boost::recursive_mutex::scoped_lock sl (mUNLLock); + ScopedUNLLockType sl (mUNLLock, __FILE__, __LINE__); { for (std::map::iterator it = m_clusterNodes.begin(), end = m_clusterNodes.end(); it != end; ++it) @@ -376,7 +378,7 @@ public: void addClusterStatus (Json::Value& obj) { - boost::recursive_mutex::scoped_lock sl (mUNLLock); + ScopedUNLLockType sl (mUNLLock, __FILE__, __LINE__); if (m_clusterNodes.size() > 1) // nodes other than us { int now = getApp().getOPs().getNetworkTimeNC(); @@ -412,7 +414,7 @@ public: Database* db = getApp().getWalletDB ()->getDB (); { - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); if (db->executeSQL (str (boost::format ("SELECT COUNT(*) AS Count FROM SeedDomains WHERE Source='%s' OR Source='%c';") % vsManual % vsValidator)) && db->startIterRows ()) iDomains = db->getInt ("Count"); @@ -485,7 +487,7 @@ public: if (!vstrValues.empty ()) { - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); db->executeSQL (str (boost::format ("REPLACE INTO PeerIps (IpPort,Source) VALUES %s;") % strJoin (vstrValues.begin (), vstrValues.end (), ","))); @@ -574,7 +576,7 @@ public: Json::Value ret (Json::arrayValue); - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); SQL_FOREACH (db, "SELECT * FROM TrustedNodes;") { Json::Value node (Json::objectValue); @@ -637,7 +639,7 @@ private: // Load information about when we last updated. bool miscLoad () { - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); Database* db = getApp().getWalletDB ()->getDB (); if (!db->executeSQL ("SELECT * FROM Misc WHERE Magic=1;")) return false; @@ -660,7 +662,7 @@ private: bool miscSave () { Database* db = getApp().getWalletDB ()->getDB (); - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); db->executeSQL (str (boost::format ("REPLACE INTO Misc (Magic,FetchUpdated,ScoreUpdated) VALUES (1,%d,%d);") % iToSeconds (mtpFetchUpdated) @@ -690,8 +692,8 @@ private: } Database* db = getApp().getWalletDB ()->getDB (); - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); - boost::recursive_mutex::scoped_lock slUNL (mUNLLock); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); + ScopedUNLLockType slUNL (mUNLLock, __FILE__, __LINE__); mUNL.clear (); @@ -791,7 +793,7 @@ private: // For each entry in SeedDomains with a PublicKey: // - Add an entry in umPulicIdx, umDomainIdx, and vsnNodes. { - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); SQL_FOREACH (db, "SELECT Domain,PublicKey,Source FROM SeedDomains;") { @@ -844,7 +846,7 @@ private: // For each entry in SeedNodes: // - Add an entry in umPulicIdx, umDomainIdx, and vsnNodes. { - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); SQL_FOREACH (db, "SELECT PublicKey,Source FROM SeedNodes;") { @@ -908,7 +910,7 @@ private: std::string& strValidator = sn.strValidator; std::vector& viReferrals = sn.viReferrals; - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); SQL_FOREACH (db, boost::str (boost::format ("SELECT Referral FROM ValidatorReferrals WHERE Validator=%s ORDER BY Entry;") % sqlEscape (strValidator))) @@ -989,7 +991,7 @@ private: } // Persist validator scores. - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); db->executeSQL ("BEGIN;"); db->executeSQL ("UPDATE TrustedNodes SET Score = 0 WHERE Score != 0;"); @@ -1040,7 +1042,7 @@ private: } { - boost::recursive_mutex::scoped_lock sl (mUNLLock); + ScopedUNLLockType sl (mUNLLock, __FILE__, __LINE__); // XXX Should limit to scores above a certain minimum and limit to a certain number. mUNL.swap (usUNL); @@ -1306,7 +1308,7 @@ private: bool bFull; { - boost::mutex::scoped_lock sl (mFetchLock); + ScopedFetchLockType sl (mFetchLock, __FILE__, __LINE__); bFull = mFetchActive == NODE_FETCH_JOBS; } @@ -1318,7 +1320,7 @@ private: boost::posix_time::ptime tpNext; boost::posix_time::ptime tpNow; - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); Database* db = getApp().getWalletDB ()->getDB (); if (db->executeSQL ("SELECT Domain,Next FROM SeedDomains INDEXED BY SeedDomainNext ORDER BY Next LIMIT 1;") @@ -1337,7 +1339,7 @@ private: if (!strDomain.empty ()) { - boost::mutex::scoped_lock sl (mFetchLock); + ScopedFetchLockType sl (mFetchLock, __FILE__, __LINE__); bFull = mFetchActive == NODE_FETCH_JOBS; @@ -1410,7 +1412,7 @@ private: void fetchFinish () { { - boost::mutex::scoped_lock sl (mFetchLock); + ScopedFetchLockType sl (mFetchLock, __FILE__, __LINE__); mFetchActive--; } @@ -1582,7 +1584,7 @@ private: // Remove all current Validator's entries in IpReferrals { - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); db->executeSQL (str (boost::format ("DELETE FROM IpReferrals WHERE Validator=%s;") % strEscNodePublic)); // XXX Check result. } @@ -1625,7 +1627,7 @@ private: { vstrValues.resize (iValues); - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); db->executeSQL (str (boost::format ("INSERT INTO IpReferrals (Validator,Entry,IP,Port) VALUES %s;") % strJoin (vstrValues.begin (), vstrValues.end (), ","))); // XXX Check result. @@ -1656,7 +1658,7 @@ private: // Remove all current Validator's entries in ValidatorReferrals { - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); db->executeSQL (str (boost::format ("DELETE FROM ValidatorReferrals WHERE Validator='%s';") % strNodePublic)); // XXX Check result. @@ -1728,7 +1730,7 @@ private: std::string strSql = str (boost::format ("INSERT INTO ValidatorReferrals (Validator,Entry,Referral) VALUES %s;") % strJoin (vstrValues.begin (), vstrValues.end (), ",")); - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); db->executeSQL (strSql); // XXX Check result. @@ -1780,7 +1782,7 @@ private: std::string strSql = boost::str (boost::format ("SELECT * FROM SeedDomains WHERE Domain=%s;") % sqlEscape (strDomain)); - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); bResult = db->executeSQL (strSql) && db->startIterRows (); @@ -1854,7 +1856,7 @@ private: % sqlEscape (sdSource.strComment) ); - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); if (!db->executeSQL (strSql)) { @@ -1881,7 +1883,7 @@ private: std::string strSql = str (boost::format ("SELECT * FROM SeedNodes WHERE PublicKey='%s';") % naNodePublic.humanNodePublic ()); - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); bResult = db->executeSQL (strSql) && db->startIterRows (); @@ -1957,7 +1959,7 @@ private: ); { - boost::recursive_mutex::scoped_lock sl (getApp().getWalletDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getWalletDB ()->getDBLock ()); if (!db->executeSQL (strSql)) { @@ -2034,12 +2036,19 @@ private: //-------------------------------------------------------------------------- private: + typedef RippleMutex FetchLockType; + typedef FetchLockType::ScopedLockType ScopedFetchLockType; + FetchLockType mFetchLock; + + typedef RippleRecursiveMutex UNLLockType; + typedef UNLLockType::ScopedLockType ScopedUNLLockType; + UNLLockType mUNLLock; + // VFALCO TODO Replace ptime with beast::Time // Misc persistent information boost::posix_time::ptime mtpScoreUpdated; boost::posix_time::ptime mtpFetchUpdated; - boost::recursive_mutex mUNLLock; // XXX Make this faster, make this the contents vector unsigned char or raw public key. // XXX Contents needs to based on score. boost::unordered_set mUNL; @@ -2048,7 +2057,6 @@ private: boost::posix_time::ptime mtpScoreStart; // Time currently started scoring. DeadlineTimer m_scoreTimer; // Timer to start scoring. - boost::mutex mFetchLock; int mFetchActive; // Count of active fetches. boost::posix_time::ptime mtpFetchNext; // Time of to start next fetch. diff --git a/modules/ripple_app/rpc/RPCHandler.cpp b/modules/ripple_app/rpc/RPCHandler.cpp index 340acbc5d6..82595ffdcd 100644 --- a/modules/ripple_app/rpc/RPCHandler.cpp +++ b/modules/ripple_app/rpc/RPCHandler.cpp @@ -1818,7 +1818,7 @@ Json::Value RPCHandler::doTxHistory (Json::Value params, LoadType* loadType, App { Database* db = getApp().getTxnDB ()->getDB (); - ScopedLock sl (getApp().getTxnDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getTxnDB ()->getDBLock ()); SQL_FOREACH (db, sql) { diff --git a/modules/ripple_app/rpc/RPCSub.cpp b/modules/ripple_app/rpc/RPCSub.cpp index ef7db62c1f..ed972f917d 100644 --- a/modules/ripple_app/rpc/RPCSub.cpp +++ b/modules/ripple_app/rpc/RPCSub.cpp @@ -46,7 +46,7 @@ void RPCSub::sendThread () { { // Obtain the lock to manipulate the queue and change sending. - boost::mutex::scoped_lock sl (mLockInfo); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (mDeque.empty ()) { @@ -93,7 +93,7 @@ void RPCSub::sendThread () void RPCSub::send (const Json::Value& jvObj, bool broadcast) { - boost::mutex::scoped_lock sl (mLockInfo); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (RPC_EVENT_QUEUE_MAX == mDeque.size ()) { diff --git a/modules/ripple_app/rpc/RPCSub.h b/modules/ripple_app/rpc/RPCSub.h index 4f822ed12e..b0414e4c75 100644 --- a/modules/ripple_app/rpc/RPCSub.h +++ b/modules/ripple_app/rpc/RPCSub.h @@ -30,14 +30,14 @@ public: void setUsername (const std::string& strUsername) { - boost::mutex::scoped_lock sl (mLockInfo); + ScopedLockType sl (mLock, __FILE__, __LINE__); mUsername = strUsername; } void setPassword (const std::string& strPassword) { - boost::mutex::scoped_lock sl (mLockInfo); + ScopedLockType sl (mLock, __FILE__, __LINE__); mPassword = strPassword; } diff --git a/modules/ripple_app/shamap/ripple_SHAMap.cpp b/modules/ripple_app/shamap/ripple_SHAMap.cpp index 43bc4881d8..5ab9d05fc9 100644 --- a/modules/ripple_app/shamap/ripple_SHAMap.cpp +++ b/modules/ripple_app/shamap/ripple_SHAMap.cpp @@ -53,7 +53,12 @@ std::size_t hash_value (const SHAMapNode& mn) } -SHAMap::SHAMap (SHAMapType t, uint32 seq) : mSeq (seq), mLedgerSeq (0), mState (smsModifying), mType (t) +SHAMap::SHAMap (SHAMapType t, uint32 seq) + : mLock (this, "SHAMap", __FILE__, __LINE__) + , mSeq (seq) + , mLedgerSeq (0) + , mState (smsModifying) + , mType (t) { if (t == smtSTATE) mTNByID.rehash (STATE_MAP_BUCKETS); @@ -63,7 +68,12 @@ SHAMap::SHAMap (SHAMapType t, uint32 seq) : mSeq (seq), mLedgerSeq (0), mState ( mTNByID[*root] = root; } -SHAMap::SHAMap (SHAMapType t, uint256 const& hash) : mSeq (1), mLedgerSeq (0), mState (smsSynching), mType (t) +SHAMap::SHAMap (SHAMapType t, uint256 const& hash) + : mLock (this, "SHAMap", __FILE__, __LINE__) + , mSeq (1) + , mLedgerSeq (0) + , mState (smsSynching) + , mType (t) { // FIXME: Need to acquire root node if (t == smtSTATE) @@ -78,7 +88,7 @@ SHAMap::pointer SHAMap::snapShot (bool isMutable) { // Return a new SHAMap that is an immutable snapshot of this one // Initially nodes are shared, but CoW is forced on both ledgers - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); SHAMap::pointer ret = boost::make_shared (mType); SHAMap& newMap = *ret; newMap.mSeq = ++mSeq; @@ -447,7 +457,7 @@ static const SHAMapItem::pointer no_item; SHAMapItem::pointer SHAMap::peekFirstItem () { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); SHAMapTreeNode* node = firstBelow (root.get ()); if (!node) @@ -458,7 +468,7 @@ SHAMapItem::pointer SHAMap::peekFirstItem () SHAMapItem::pointer SHAMap::peekFirstItem (SHAMapTreeNode::TNType& type) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); SHAMapTreeNode* node = firstBelow (root.get ()); if (!node) @@ -470,7 +480,7 @@ SHAMapItem::pointer SHAMap::peekFirstItem (SHAMapTreeNode::TNType& type) SHAMapItem::pointer SHAMap::peekLastItem () { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); SHAMapTreeNode* node = lastBelow (root.get ()); if (!node) @@ -489,7 +499,7 @@ SHAMapItem::pointer SHAMap::peekNextItem (uint256 const& id) SHAMapItem::pointer SHAMap::peekNextItem (uint256 const& id, SHAMapTreeNode::TNType& type) { // Get a pointer to the next item in the tree after a given item - item need not be in tree - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); std::stack stack = getStack (id, true); @@ -529,7 +539,7 @@ SHAMapItem::pointer SHAMap::peekNextItem (uint256 const& id, SHAMapTreeNode::TNT // Get a pointer to the previous item in the tree after a given item - item need not be in tree SHAMapItem::pointer SHAMap::peekPrevItem (uint256 const& id) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); std::stack stack = getStack (id, true); @@ -567,7 +577,7 @@ SHAMapItem::pointer SHAMap::peekPrevItem (uint256 const& id) SHAMapItem::pointer SHAMap::peekItem (uint256 const& id) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); SHAMapTreeNode* leaf = walkToPointer (id); if (!leaf) @@ -578,7 +588,7 @@ SHAMapItem::pointer SHAMap::peekItem (uint256 const& id) SHAMapItem::pointer SHAMap::peekItem (uint256 const& id, SHAMapTreeNode::TNType& type) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); SHAMapTreeNode* leaf = walkToPointer (id); if (!leaf) @@ -590,7 +600,7 @@ SHAMapItem::pointer SHAMap::peekItem (uint256 const& id, SHAMapTreeNode::TNType& SHAMapItem::pointer SHAMap::peekItem (uint256 const& id, uint256& hash) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); SHAMapTreeNode* leaf = walkToPointer (id); if (!leaf) @@ -604,7 +614,7 @@ SHAMapItem::pointer SHAMap::peekItem (uint256 const& id, uint256& hash) bool SHAMap::hasItem (uint256 const& id) { // does the tree have an item with this ID - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); SHAMapTreeNode* leaf = walkToPointer (id); return (leaf != NULL); @@ -613,7 +623,7 @@ bool SHAMap::hasItem (uint256 const& id) bool SHAMap::delItem (uint256 const& id) { // delete the item with this ID - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); assert (mState != smsImmutable); std::stack stack = getStack (id, true); @@ -694,7 +704,7 @@ bool SHAMap::addGiveItem (SHAMapItem::ref item, bool isTransaction, bool hasMeta SHAMapTreeNode::TNType type = !isTransaction ? SHAMapTreeNode::tnACCOUNT_STATE : (hasMeta ? SHAMapTreeNode::tnTRANSACTION_MD : SHAMapTreeNode::tnTRANSACTION_NM); - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); assert (mState != smsImmutable); std::stack stack = getStack (tag, true); @@ -792,7 +802,7 @@ bool SHAMap::updateGiveItem (SHAMapItem::ref item, bool isTransaction, bool hasM // can't change the tag but can change the hash uint256 tag = item->getTag (); - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); assert (mState != smsImmutable); std::stack stack = getStack (tag, true); @@ -975,7 +985,7 @@ int SHAMap::flushDirty (DirtyMap& map, int maxNodes, NodeObjectType t, uint32 se boost::shared_ptr SHAMap::disarmDirty () { // stop saving dirty nodes - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); boost::shared_ptr ret; ret.swap (mDirtyNodes); @@ -1040,7 +1050,7 @@ bool SHAMap::getPath (uint256 const& index, std::vector< Blob >& nodes, SHANodeF // Return the path of nodes to the specified index in the specified format // Return value: true = node present, false = node not present - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); SHAMapTreeNode* inNode = root.get (); while (!inNode->isLeaf ()) @@ -1070,7 +1080,7 @@ bool SHAMap::getPath (uint256 const& index, std::vector< Blob >& nodes, SHANodeF void SHAMap::dropCache () { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); assert (mState == smsImmutable); mTNByID.clear (); @@ -1090,7 +1100,7 @@ void SHAMap::dropBelow (SHAMapTreeNode* d) void SHAMap::dump (bool hash) { WriteLog (lsINFO, SHAMap) << " MAP Contains"; - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); for (boost::unordered_map::iterator it = mTNByID.begin (); it != mTNByID.end (); ++it) diff --git a/modules/ripple_app/shamap/ripple_SHAMap.h b/modules/ripple_app/shamap/ripple_SHAMap.h index e873080493..1095bf651e 100644 --- a/modules/ripple_app/shamap/ripple_SHAMap.h +++ b/modules/ripple_app/shamap/ripple_SHAMap.h @@ -29,6 +29,9 @@ public: typedef std::map Delta; typedef boost::unordered_map DirtyMap; + typedef RippleRecursiveMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + public: // build new map explicit SHAMap (SHAMapType t, uint32 seq = 1); @@ -53,9 +56,9 @@ public: } // hold the map stable across operations - ScopedLock Lock () const + LockType const& peekMutex () const { - return ScopedLock (mLock); + return mLock; } bool hasNode (const SHAMapNode & id); @@ -222,9 +225,14 @@ private: Delta & differences, int & maxCount); private: +#if 1 + LockType mLock; +#else + mutable LockType mLock; +#endif + uint32 mSeq; uint32 mLedgerSeq; // sequence number of ledger this is part of - mutable boost::recursive_mutex mLock; boost::unordered_map mTNByID; boost::shared_ptr mDirtyNodes; diff --git a/modules/ripple_app/shamap/ripple_SHAMapDelta.cpp b/modules/ripple_app/shamap/ripple_SHAMapDelta.cpp index 26f62b4d9e..f1204c4ca3 100644 --- a/modules/ripple_app/shamap/ripple_SHAMapDelta.cpp +++ b/modules/ripple_app/shamap/ripple_SHAMapDelta.cpp @@ -125,7 +125,7 @@ bool SHAMap::compare (SHAMap::ref otherMap, Delta& differences, int maxCount) std::stack nodeStack; // track nodes we've pushed - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (getHash () == otherMap->getHash ()) return true; @@ -223,7 +223,7 @@ void SHAMap::walkMap (std::vector& missingNodes, int maxMissi { std::stack nodeStack; - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (!root->isInner ()) // root is only node, and we have it return; diff --git a/modules/ripple_app/shamap/ripple_SHAMapSync.cpp b/modules/ripple_app/shamap/ripple_SHAMapSync.cpp index 02a59f77ae..6a4a574f61 100644 --- a/modules/ripple_app/shamap/ripple_SHAMapSync.cpp +++ b/modules/ripple_app/shamap/ripple_SHAMapSync.cpp @@ -13,7 +13,7 @@ KeyCache SHAMap::fullBelowCache ("fullBelowCache", void SHAMap::getMissingNodes (std::vector& nodeIDs, std::vector& hashes, int max, SHAMapSyncFilter* filter) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); assert (root->isValid ()); @@ -89,7 +89,7 @@ void SHAMap::getMissingNodes (std::vector& nodeIDs, std::vector SHAMap::getNeededHashes (int max, SHAMapSyncFilter* filter) { std::vector ret; - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); assert (root->isValid ()); @@ -159,7 +159,7 @@ bool SHAMap::getNodeFat (const SHAMapNode& wanted, std::vector& node std::list& rawNodes, bool fatRoot, bool fatLeaves) { // Gets a node and some of its children - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); SHAMapTreeNode* node = getNodePointer(wanted); @@ -214,7 +214,7 @@ bool SHAMap::getNodeFat (const SHAMapNode& wanted, std::vector& node bool SHAMap::getRootNode (Serializer& s, SHANodeFormat format) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); root->addRaw (s, format); return true; } @@ -222,7 +222,7 @@ bool SHAMap::getRootNode (Serializer& s, SHANodeFormat format) SHAMapAddNode SHAMap::addRootNode (Blob const& rootNode, SHANodeFormat format, SHAMapSyncFilter* filter) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); // we already have a root node if (root->getNodeHash ().isNonZero ()) @@ -263,7 +263,7 @@ SHAMapAddNode SHAMap::addRootNode (Blob const& rootNode, SHANodeFormat format, SHAMapAddNode SHAMap::addRootNode (uint256 const& hash, Blob const& rootNode, SHANodeFormat format, SHAMapSyncFilter* filter) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); // we already have a root node if (root->getNodeHash ().isNonZero ()) @@ -309,7 +309,7 @@ SHAMapAddNode SHAMap::addKnownNode (const SHAMapNode& node, Blob const& rawNode, return SHAMapAddNode::okay (); } - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (checkCacheNode (node)) // Do we already have this node? return SHAMapAddNode::okay (); @@ -373,7 +373,7 @@ bool SHAMap::deepCompare (SHAMap& other) { // Intended for debug/test only std::stack stack; - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); stack.push (root); @@ -500,16 +500,15 @@ std::list SHAMap::getFetchPack (SHAMap* have, bool inc void SHAMap::getFetchPack (SHAMap* have, bool includeLeaves, int max, FUNCTION_TYPE func) { - boost::recursive_mutex::scoped_lock ul1 (mLock); + ScopedLockType ul1 (mLock, __FILE__, __LINE__); - boost::shared_ptr< boost::unique_lock > ul2; + ScopedPointer ul2; if (have) { - ul2 = boost::make_shared< boost::unique_lock > - (boost::ref (have->mLock), boost::try_to_lock); + ul2 = new LockType::ScopedTryLockType (have->mLock, __FILE__, __LINE__); - if (! (*ul2)) + if (! ul2->owns_lock ()) { WriteLog (lsINFO, SHAMap) << "Unable to create pack due to lock"; return; @@ -582,7 +581,7 @@ void SHAMap::getFetchPack (SHAMap* have, bool includeLeaves, int max, std::list SHAMap::getTrustedPath (uint256 const& index) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); std::stack stack = SHAMap::getStack (index, false); if (stack.empty () || !stack.top ()->isLeaf ()) diff --git a/modules/ripple_app/tx/Transaction.cpp b/modules/ripple_app/tx/Transaction.cpp index 2ac415ec8d..b5cd024d45 100644 --- a/modules/ripple_app/tx/Transaction.cpp +++ b/modules/ripple_app/tx/Transaction.cpp @@ -193,7 +193,7 @@ Transaction::pointer Transaction::transactionFromSQL (const std::string& sql) rawTxn.resize (txSize); { - ScopedLock sl (getApp().getTxnDB ()->getDBLock ()); + DeprecatedScopedLock sl (getApp().getTxnDB ()->getDBLock ()); Database* db = getApp().getTxnDB ()->getDB (); if (!db->executeSQL (sql, true) || !db->startIterRows ()) diff --git a/modules/ripple_app/tx/TransactionMaster.h b/modules/ripple_app/tx/TransactionMaster.h index 1c66356318..d9605417f2 100644 --- a/modules/ripple_app/tx/TransactionMaster.h +++ b/modules/ripple_app/tx/TransactionMaster.h @@ -24,7 +24,7 @@ public: void sweep (void); private: - TaggedCache mCache; + TaggedCacheType mCache; }; #endif diff --git a/modules/ripple_app/tx/TransactionQueue.cpp b/modules/ripple_app/tx/TransactionQueue.cpp index 4c2cbe2cd5..635ab1ae2f 100644 --- a/modules/ripple_app/tx/TransactionQueue.cpp +++ b/modules/ripple_app/tx/TransactionQueue.cpp @@ -4,6 +4,12 @@ */ //============================================================================== +TXQueue::TXQueue () + : mLock (this, "TXQueue", __FILE__, __LINE__) + , mRunning (false) +{ +} + void TXQEntry::addCallbacks (const TXQEntry& otherEntry) { BOOST_FOREACH (const stCallback & callback, otherEntry.mCallbacks) @@ -19,7 +25,7 @@ void TXQEntry::doCallbacks (TER result) bool TXQueue::addEntryForSigCheck (TXQEntry::ref entry) { // we always dispatch a thread to check the signature - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (!mTxMap.insert (valueType (entry->getID (), entry)).second) { @@ -34,7 +40,7 @@ bool TXQueue::addEntryForSigCheck (TXQEntry::ref entry) bool TXQueue::addEntryForExecution (TXQEntry::ref entry) { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); entry->mSigChecked = true; @@ -60,7 +66,7 @@ TXQEntry::pointer TXQueue::removeEntry (uint256 const& id) { TXQEntry::pointer ret; - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mapType::left_map::iterator it = mTxMap.left.find (id); @@ -75,7 +81,7 @@ TXQEntry::pointer TXQueue::removeEntry (uint256 const& id) void TXQueue::getJob (TXQEntry::pointer& job) { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); assert (mRunning); if (job) @@ -95,7 +101,7 @@ void TXQueue::getJob (TXQEntry::pointer& job) bool TXQueue::stopProcessing (TXQEntry::ref finishedJob) { // returns true if a new thread must be dispatched - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); assert (mRunning); mTxMap.left.erase (finishedJob->getID ()); diff --git a/modules/ripple_app/tx/TransactionQueue.h b/modules/ripple_app/tx/TransactionQueue.h index 15da038261..12e887e663 100644 --- a/modules/ripple_app/tx/TransactionQueue.h +++ b/modules/ripple_app/tx/TransactionQueue.h @@ -56,10 +56,7 @@ private: class TXQueue : LeakChecked { public: - TXQueue () : mRunning (false) - { - ; - } + TXQueue (); // Return: true = must dispatch signature checker thread bool addEntryForSigCheck (TXQEntry::ref); @@ -80,9 +77,12 @@ private: typedef boost::bimap mapType; typedef mapType::value_type valueType; + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; + mapType mTxMap; bool mRunning; - boost::mutex mLock; }; #endif diff --git a/modules/ripple_app/tx/Transactor.cpp b/modules/ripple_app/tx/Transactor.cpp index 5bff92b2c1..a9ddbddfd4 100644 --- a/modules/ripple_app/tx/Transactor.cpp +++ b/modules/ripple_app/tx/Transactor.cpp @@ -208,7 +208,7 @@ TER Transactor::apply () if (terResult != tesSUCCESS) return (terResult); - boost::recursive_mutex::scoped_lock sl (mEngine->getLedger ()->mLock); + Ledger::ScopedLockType sl (mEngine->getLedger ()->mLock, __FILE__, __LINE__); mTxnAccount = mEngine->entryCache (ltACCOUNT_ROOT, Ledger::getAccountRootIndex (mTxnAccountID)); calculateFee (); diff --git a/modules/ripple_app/tx/ripple_TransactionAcquire.cpp b/modules/ripple_app/tx/ripple_TransactionAcquire.cpp index 9202a5dc23..cf240f1b8f 100644 --- a/modules/ripple_app/tx/ripple_TransactionAcquire.cpp +++ b/modules/ripple_app/tx/ripple_TransactionAcquire.cpp @@ -48,7 +48,7 @@ void TransactionAcquire::done () getApp().getIOService ().post (BIND_TYPE (&TACompletionHandler, mHash, map)); } -void TransactionAcquire::onTimer (bool progress, boost::recursive_mutex::scoped_lock& psl) +void TransactionAcquire::onTimer (bool progress, ScopedLockType& psl) { bool aggressive = false; @@ -66,7 +66,7 @@ void TransactionAcquire::onTimer (bool progress, boost::recursive_mutex::scoped_ aggressive = true; } } - psl.lock(); + psl.lock(__FILE__, __LINE__); if (!aggressive) { diff --git a/modules/ripple_app/tx/ripple_TransactionAcquire.h b/modules/ripple_app/tx/ripple_TransactionAcquire.h index dcfa7a81b4..6ba751ab1a 100644 --- a/modules/ripple_app/tx/ripple_TransactionAcquire.h +++ b/modules/ripple_app/tx/ripple_TransactionAcquire.h @@ -38,7 +38,7 @@ private: SHAMap::pointer mMap; bool mHaveRoot; - void onTimer (bool progress, boost::recursive_mutex::scoped_lock& peerSetLock); + void onTimer (bool progress, ScopedLockType& peerSetLock); void newPeer (Peer::ref peer) { trigger (peer); diff --git a/modules/ripple_basics/containers/ripple_KeyCache.h b/modules/ripple_basics/containers/ripple_KeyCache.h index da996805d8..6d2dbe6562 100644 --- a/modules/ripple_basics/containers/ripple_KeyCache.h +++ b/modules/ripple_basics/containers/ripple_KeyCache.h @@ -7,6 +7,11 @@ #ifndef RIPPLE_KEYCACHE_H_INCLUDED #define RIPPLE_KEYCACHE_H_INCLUDED +// This tag is for helping track the locks +struct KeyCacheBase +{ +}; + /** Maintains a cache of keys with no associated data. The cache has a target size and an expiration time. When cached items become @@ -22,7 +27,7 @@ @ingroup ripple_basics */ template -class KeyCache +class KeyCache : public KeyCacheBase { public: /** Provides a type for the key. @@ -37,7 +42,9 @@ public: KeyCache (const std::string& name, int size = 0, int age = 120) - : mName (name) + : mLock (static_cast (this), String ("KeyCache") + + "('" + name + "')", __FILE__, __LINE__) + , mName (name) , mTargetSize (size) , mTargetAge (age) { @@ -48,7 +55,7 @@ public: */ unsigned int getSize () { - boost::mutex::scoped_lock sl (mNCLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mCache.size (); } @@ -56,7 +63,7 @@ public: */ unsigned int getTargetSize () { - boost::mutex::scoped_lock sl (mNCLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mTargetSize; } @@ -64,7 +71,7 @@ public: */ unsigned int getTargetAge () { - boost::mutex::scoped_lock sl (mNCLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mTargetAge; } @@ -75,7 +82,7 @@ public: */ void setTargets (int size, int age) { - boost::mutex::scoped_lock sl (mNCLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mTargetSize = size; mTargetAge = age; assert ((mTargetSize >= 0) && (mTargetAge > 2)); @@ -96,7 +103,7 @@ public: */ bool isPresent (const key_type& key, bool refresh = true) { - boost::mutex::scoped_lock sl (mNCLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); map_iterator it = mCache.find (key); @@ -116,7 +123,7 @@ public: */ bool del (const key_type& key) { - boost::mutex::scoped_lock sl (mNCLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); map_iterator it = mCache.find (key); @@ -134,7 +141,7 @@ public: */ bool add (const key_type& key) { - boost::mutex::scoped_lock sl (mNCLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); map_iterator it = mCache.find (key); @@ -152,7 +159,7 @@ public: */ void clear () { - boost::mutex::scoped_lock sl (mNCLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mCache.clear (); } @@ -161,7 +168,7 @@ public: void sweep () { int now = Timer::getElapsedSeconds (); - boost::mutex::scoped_lock sl (mNCLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); int target; @@ -196,16 +203,17 @@ public: } protected: - /** Provides a type for the underlying map. - */ + /** Provides a type for the underlying map. */ typedef boost::unordered_map map_type; - - /** The type of the iterator used for traversals. - */ + /** The type of the iterator used for traversals. */ typedef typename map_type::iterator map_iterator; + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; + std::string const mName; - boost::mutex mNCLock; + map_type mCache; unsigned int mTargetSize, mTargetAge; }; diff --git a/modules/ripple_basics/containers/ripple_TaggedCache.h b/modules/ripple_basics/containers/ripple_TaggedCache.h index ca29bda999..c15e02193d 100644 --- a/modules/ripple_basics/containers/ripple_TaggedCache.h +++ b/modules/ripple_basics/containers/ripple_TaggedCache.h @@ -20,6 +20,14 @@ struct TaggedCacheLog; +// Common base +class TaggedCache +{ +public: + typedef RippleRecursiveMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; +}; + /** Combination cache/map container. NOTE: @@ -29,7 +37,7 @@ struct TaggedCacheLog; static int Timer::getElapsedSeconds (); */ template -class TaggedCache +class TaggedCacheType : public TaggedCache { public: typedef c_Key key_type; @@ -38,8 +46,12 @@ public: typedef boost::shared_ptr data_ptr; public: - TaggedCache (const char* name, int size, int age) - : mName (name) + typedef TaggedCache::LockType LockType; + typedef TaggedCache::ScopedLockType ScopedLockType; + + TaggedCacheType (const char* name, int size, int age) + : mLock (static_cast (this), "TaggedCache", __FILE__, __LINE__) + , mName (name) , mTargetSize (size) , mTargetAge (age) , mCacheCount (0) @@ -71,7 +83,7 @@ public: bool found = false; // If present, make current in cache - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); cache_iterator cit = mCache.find (key); @@ -134,7 +146,7 @@ public: boost::shared_ptr fetch (const key_type& key); bool retrieve (const key_type& key, c_Data& data); - boost::recursive_mutex& peekMutex () + LockType& peekMutex () { return mLock; } @@ -177,7 +189,7 @@ private: typedef boost::unordered_map cache_type; typedef typename cache_type::iterator cache_iterator; - mutable boost::recursive_mutex mLock; + mutable LockType mLock; std::string mName; // Used for logging int mTargetSize; // Desired number of cache entries (0 = ignore) @@ -190,16 +202,16 @@ private: }; template -int TaggedCache::getTargetSize () const +int TaggedCacheType::getTargetSize () const { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mTargetSize; } template -void TaggedCache::setTargetSize (int s) +void TaggedCacheType::setTargetSize (int s) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mTargetSize = s; if (s > 0) @@ -209,59 +221,59 @@ void TaggedCache::setTargetSize (int s) } template -int TaggedCache::getTargetAge () const +int TaggedCacheType::getTargetAge () const { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mTargetAge; } template -void TaggedCache::setTargetAge (int s) +void TaggedCacheType::setTargetAge (int s) { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mTargetAge = s; WriteLog (lsDEBUG, TaggedCacheLog) << mName << " target age set to " << s; } template -int TaggedCache::getCacheSize () +int TaggedCacheType::getCacheSize () { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mCacheCount; } template -int TaggedCache::getTrackSize () +int TaggedCacheType::getTrackSize () { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mCache.size (); } template -float TaggedCache::getHitRate () +float TaggedCacheType::getHitRate () { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return (static_cast (mHits) * 100) / (1.0f + mHits + mMisses); } template -void TaggedCache::clearStats () +void TaggedCacheType::clearStats () { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mHits = 0; mMisses = 0; } template -void TaggedCache::clear () +void TaggedCacheType::clear () { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mCache.clear (); mCacheCount = 0; } template -void TaggedCache::sweep () +void TaggedCacheType::sweep () { int cacheRemovals = 0; int mapRemovals = 0; @@ -273,7 +285,7 @@ void TaggedCache::sweep () std::vector stuffToSweep; { - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); int const now = Timer::getElapsedSeconds (); int target = now - mTargetAge; @@ -349,10 +361,10 @@ void TaggedCache::sweep () } template -bool TaggedCache::del (const key_type& key, bool valid) +bool TaggedCacheType::del (const key_type& key, bool valid) { // Remove from cache, if !valid, remove from map too. Returns true if removed from cache - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); cache_iterator cit = mCache.find (key); @@ -378,11 +390,11 @@ bool TaggedCache::del (const key_type& key, bool valid) // VFALCO NOTE What does it mean to canonicalize the data? template -bool TaggedCache::canonicalize (const key_type& key, boost::shared_ptr& data, bool replace) +bool TaggedCacheType::canonicalize (const key_type& key, boost::shared_ptr& data, bool replace) { // Return canonical value, store if needed, refresh in cache // Return values: true=we had the data already - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); cache_iterator cit = mCache.find (key); @@ -436,10 +448,10 @@ bool TaggedCache::canonicalize (const key_type& key, boost } template -boost::shared_ptr TaggedCache::fetch (const key_type& key) +boost::shared_ptr TaggedCacheType::fetch (const key_type& key) { // fetch us a shared pointer to the stored data object - boost::recursive_mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); cache_iterator cit = mCache.find (key); @@ -473,14 +485,14 @@ boost::shared_ptr TaggedCache::fetch (const key_ty } template -bool TaggedCache::store (const key_type& key, const c_Data& data) +bool TaggedCacheType::store (const key_type& key, const c_Data& data) { data_ptr d = boost::make_shared (boost::cref (data)); return canonicalize (key, d); } template -bool TaggedCache::retrieve (const key_type& key, c_Data& data) +bool TaggedCacheType::retrieve (const key_type& key, c_Data& data) { // retrieve the value of the stored data data_ptr entry = fetch (key); diff --git a/modules/ripple_basics/ripple_basics.h b/modules/ripple_basics/ripple_basics.h index 564e645350..d49bf98a1c 100644 --- a/modules/ripple_basics/ripple_basics.h +++ b/modules/ripple_basics/ripple_basics.h @@ -31,6 +31,10 @@ #include "beast/modules/beast_crypto/beast_crypto.h" +#ifndef RIPPLE_TRACK_MUTEXES +# define RIPPLE_TRACK_MUTEXES 0 +#endif + //------------------------------------------------------------------------------ // From @@ -75,17 +79,17 @@ namespace ripple using namespace beast; +#include "types/ripple_BasicTypes.h" + #include "utility/ripple_LogFile.h" #include "utility/ripple_Log.h" // Needed by others -#include "types/ripple_BasicTypes.h" #include "utility/ripple_ByteOrder.h" #include "utility/ripple_CountedObject.h" #include "utility/ripple_DiffieHellmanUtil.h" #include "utility/ripple_IniFile.h" #include "utility/ripple_PlatformMacros.h" #include "utility/ripple_RandomNumbers.h" -#include "utility/ripple_ScopedLock.h" #include "utility/ripple_StringUtilities.h" #include "utility/ripple_Sustain.h" #include "utility/ripple_ThreadName.h" diff --git a/modules/ripple_basics/types/ripple_BasicTypes.h b/modules/ripple_basics/types/ripple_BasicTypes.h index 44748aa30c..4a46276ab5 100644 --- a/modules/ripple_basics/types/ripple_BasicTypes.h +++ b/modules/ripple_basics/types/ripple_BasicTypes.h @@ -13,4 +13,18 @@ */ typedef std::vector Blob; +/** Synchronization primitives. + This lets us switch between tracked and untracked mutexes. +*/ +#if RIPPLE_TRACK_MUTEXES +typedef TrackedMutexType RippleMutex; +typedef TrackedMutexType RippleRecursiveMutex; +#else +typedef UntrackedMutexType RippleMutex; +typedef UntrackedMutexType RippleRecursiveMutex; +#endif + +typedef boost::recursive_mutex DeprecatedRecursiveMutex; +typedef DeprecatedRecursiveMutex::scoped_lock DeprecatedScopedLock; + #endif diff --git a/modules/ripple_basics/utility/ripple_Log.cpp b/modules/ripple_basics/utility/ripple_Log.cpp index 06e71dd6f0..78cdcb0546 100644 --- a/modules/ripple_basics/utility/ripple_Log.cpp +++ b/modules/ripple_basics/utility/ripple_Log.cpp @@ -5,7 +5,7 @@ //============================================================================== LogFile Log::s_logFile; -boost::recursive_mutex Log::s_lock; +Log::StaticLockType Log::s_lock ("Log", __FILE__, __LINE__); LogSeverity Log::sMinSeverity = lsINFO; //------------------------------------------------------------------------------ @@ -121,14 +121,14 @@ Log::~Log () void Log::print (std::string const& text, bool toStdErr) { - boost::recursive_mutex::scoped_lock sl (s_lock); + StaticScopedLockType sl (s_lock, __FILE__, __LINE__); // Does nothing if not open. s_logFile.writeln (text); if (toStdErr) { -#if BEAST_MSVC +#if 0 //BEAST_MSVC if (beast_isRunningUnderDebugger ()) { // Send it to the attached debugger's Output window @@ -143,9 +143,18 @@ void Log::print (std::string const& text, bool toStdErr) } } +void Log::print (StringArray const& strings, bool toStdErr) +{ + StaticScopedLockType sl (s_lock, __FILE__, __LINE__); + + for (int i = 0; i < strings.size (); ++i) + print (strings [i].toStdString (), toStdErr); + +} + std::string Log::rotateLog () { - boost::recursive_mutex::scoped_lock sl (s_lock); + StaticScopedLockType sl (s_lock, __FILE__, __LINE__); bool const wasOpened = s_logFile.closeAndReopen (); @@ -161,7 +170,7 @@ std::string Log::rotateLog () void Log::setMinSeverity (LogSeverity s, bool all) { - boost::recursive_mutex::scoped_lock sl (s_lock); + StaticScopedLockType sl (s_lock, __FILE__, __LINE__); sMinSeverity = s; @@ -171,7 +180,7 @@ void Log::setMinSeverity (LogSeverity s, bool all) LogSeverity Log::getMinSeverity () { - boost::recursive_mutex::scoped_lock sl (s_lock); + StaticScopedLockType sl (s_lock, __FILE__, __LINE__); return sMinSeverity; } diff --git a/modules/ripple_basics/utility/ripple_Log.h b/modules/ripple_basics/utility/ripple_Log.h index 13c44ed155..7b21b1b46e 100644 --- a/modules/ripple_basics/utility/ripple_Log.h +++ b/modules/ripple_basics/utility/ripple_Log.h @@ -144,6 +144,8 @@ public: static void print (std::string const& text, bool toStdErr = true); + static void print (StringArray const& strings, bool toStdErr = true); + /** Output stream for logging This is a convenient replacement for writing to `std::cerr`. @@ -196,8 +198,11 @@ private: // Singleton variables // + typedef RippleRecursiveMutex StaticLockType; + typedef StaticLockType::ScopedLockType StaticScopedLockType; + static StaticLockType s_lock; + static LogFile s_logFile; - static boost::recursive_mutex s_lock; static LogSeverity sMinSeverity; mutable std::ostringstream oss; diff --git a/modules/ripple_basics/utility/ripple_ScopedLock.h b/modules/ripple_basics/utility/ripple_ScopedLock.h deleted file mode 100644 index a38a539251..0000000000 --- a/modules/ripple_basics/utility/ripple_ScopedLock.h +++ /dev/null @@ -1,85 +0,0 @@ -//------------------------------------------------------------------------------ -/* - Copyright (c) 2011-2013, OpenCoin, Inc. -*/ -//============================================================================== - -#ifndef RIPPLE_SCOPEDLOCK_H -#define RIPPLE_SCOPEDLOCK_H - -typedef boost::recursive_mutex::scoped_lock ScopedLock; - -// A lock holder that can be returned and copied by value -// When the last reference goes away, the lock is released - -// VFALCO TODO replace these with a more generic template, and not use boost -// -class SharedScopedLock -{ -protected: - mutable boost::shared_ptr mHolder; - -public: - SharedScopedLock (boost::recursive_mutex& mutex) : - mHolder (boost::make_shared (boost::ref (mutex))) - { - ; - } - - void lock () const - { - mHolder->lock (); - } - void unlock () const - { - mHolder->unlock (); - } -}; - -// A class that unlocks on construction and locks on destruction -/* -class ScopedUnlock -{ -protected: - bool mUnlocked; - boost::recursive_mutex& mMutex; - -public: - // VFALCO TODO get rid of this unlock parameter to restore sanity - ScopedUnlock (boost::recursive_mutex& mutex, bool unlock = true) : mUnlocked (unlock), mMutex (mutex) - { - if (unlock) - mMutex.unlock (); - } - - ~ScopedUnlock () - { - if (mUnlocked) - mMutex.lock (); - } - - void lock () - { - if (mUnlocked) - { - mMutex.lock (); - mUnlocked = false; - } - } - - void unlock () - { - if (!mUnlocked) - { - mUnlocked = true; - mMutex.unlock (); - } - } - -private: - ScopedUnlock (const ScopedUnlock&); // no implementation - ScopedUnlock& operator= (const ScopedUnlock&); // no implementation -}; -*/ - -#endif diff --git a/modules/ripple_core/functional/ripple_JobQueue.cpp b/modules/ripple_core/functional/ripple_JobQueue.cpp index 88d5ee3452..627abeecbf 100644 --- a/modules/ripple_core/functional/ripple_JobQueue.cpp +++ b/modules/ripple_core/functional/ripple_JobQueue.cpp @@ -25,7 +25,8 @@ JobQueue::Count::Count (JobType type_) noexcept SETUP_LOG (JobQueue) JobQueue::JobQueue () - : m_workers (*this, "JobQueue", 0) + : mLock (this, "JobQueue", __FILE__, __LINE__) + , m_workers (*this, "JobQueue", 0) , mLastJob (0) { // Initialize the job counts. @@ -62,7 +63,7 @@ void JobQueue::addJob (JobType type, const std::string& name, const FUNCTION_TYP { assert (type != jtINVALID); - ScopedLockType lock (mJobLock); + ScopedLockType lock (mLock, __FILE__, __LINE__); // FIXME: Workaround incorrect client shutdown ordering // do not add jobs to a queue with no threads @@ -78,7 +79,7 @@ void JobQueue::addJob (JobType type, const std::string& name, const FUNCTION_TYP int JobQueue::getJobCount (JobType t) { - ScopedLockType lock (mJobLock); + ScopedLockType lock (mLock, __FILE__, __LINE__); JobCounts::const_iterator c = mJobCounts.find (t); @@ -87,7 +88,7 @@ int JobQueue::getJobCount (JobType t) int JobQueue::getJobCountTotal (JobType t) { - ScopedLockType lock (mJobLock); + ScopedLockType lock (mLock, __FILE__, __LINE__); JobCounts::const_iterator c = mJobCounts.find (t); @@ -99,7 +100,7 @@ int JobQueue::getJobCountGE (JobType t) // return the number of jobs at this priority level or greater int ret = 0; - ScopedLockType lock (mJobLock); + ScopedLockType lock (mLock, __FILE__, __LINE__); typedef JobCounts::value_type jt_int_pair; @@ -117,7 +118,7 @@ std::vector< std::pair > > JobQueue::getJobCounts ( // return all jobs at all priority levels std::vector< std::pair > > ret; - ScopedLockType lock (mJobLock); + ScopedLockType lock (mLock, __FILE__, __LINE__); ret.reserve (mJobCounts.size ()); @@ -136,7 +137,7 @@ Json::Value JobQueue::getJson (int) { Json::Value ret (Json::objectValue); - ScopedLockType lock (mJobLock); + ScopedLockType lock (mLock, __FILE__, __LINE__); ret["threads"] = m_workers.getNumberOfThreads (); @@ -201,7 +202,7 @@ bool JobQueue::isOverloaded () { int count = 0; - ScopedLockType lock (mJobLock); + ScopedLockType lock (mLock, __FILE__, __LINE__); for (int i = 0; i < NUM_JOB_TYPES; ++i) if (mJobLoads[i].isOver ()) @@ -360,7 +361,7 @@ void JobQueue::finishJob (Job const& job) JobType const type = job.getType (); { - ScopedLockType lock (mJobLock); + ScopedLockType lock (mLock, __FILE__, __LINE__); check_precondition (mJobSet.find (job) == mJobSet.end ()); check_precondition (type != jtINVALID); @@ -398,7 +399,7 @@ void JobQueue::processTask () Job job; { - ScopedLockType lock (mJobLock); + ScopedLockType lock (mLock, __FILE__, __LINE__); getNextJob (job, lock); } diff --git a/modules/ripple_core/functional/ripple_JobQueue.h b/modules/ripple_core/functional/ripple_JobQueue.h index f8f228fccb..69b581e92f 100644 --- a/modules/ripple_core/functional/ripple_JobQueue.h +++ b/modules/ripple_core/functional/ripple_JobQueue.h @@ -68,8 +68,10 @@ public: Json::Value getJson (int c = 0); private: - typedef boost::mutex JobLockType; - typedef JobLockType::scoped_lock ScopedLockType; + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; + typedef std::set JobSet; void queueJob (Job const& job, ScopedLockType&); @@ -82,7 +84,6 @@ private: private: Workers m_workers; - JobLockType mJobLock; uint64 mLastJob; JobSet mJobSet; LoadMonitor mJobLoads [NUM_JOB_TYPES]; diff --git a/modules/ripple_core/functional/ripple_LoadFeeTrack.h b/modules/ripple_core/functional/ripple_LoadFeeTrack.h index d65d296cd8..d5c3cba369 100644 --- a/modules/ripple_core/functional/ripple_LoadFeeTrack.h +++ b/modules/ripple_core/functional/ripple_LoadFeeTrack.h @@ -14,7 +14,8 @@ class LoadFeeTrack : public ILoadFeeTrack { public: LoadFeeTrack () - : mLocalTxnLoadFee (lftNormalFee) + : mLock (this, "LoadFeeTrack", __FILE__, __LINE__) + , mLocalTxnLoadFee (lftNormalFee) , mRemoteTxnLoadFee (lftNormalFee) , mClusterTxnLoadFee (lftNormalFee) , raiseCount (0) @@ -41,7 +42,7 @@ public: feeFactor = uRemFee; { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); fee = mulDiv (fee, feeFactor, lftNormalFee); } @@ -61,13 +62,13 @@ public: uint32 getRemoteFee () { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mRemoteTxnLoadFee; } uint32 getLocalFee () { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mLocalTxnLoadFee; } @@ -78,19 +79,19 @@ public: uint32 getLoadFactor () { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return std::max(mClusterTxnLoadFee, std::max (mLocalTxnLoadFee, mRemoteTxnLoadFee)); } void setClusterFee (uint32 fee) { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mClusterTxnLoadFee = fee; } uint32 getClusterFee () { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return mClusterTxnLoadFee; } @@ -102,7 +103,7 @@ public: // NOTE This applies to all the locking in this class. // // - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return (raiseCount != 0) || (mLocalTxnLoadFee != lftNormalFee); } @@ -114,19 +115,19 @@ public: // NOTE This applies to all the locking in this class. // // - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); return (raiseCount != 0) || (mLocalTxnLoadFee != lftNormalFee) || (mClusterTxnLoadFee != lftNormalFee); } void setRemoteFee (uint32 f) { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mRemoteTxnLoadFee = f; } bool raiseLocalFee () { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if (++raiseCount < 2) return false; @@ -150,7 +151,7 @@ public: bool lowerLocalFee () { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); uint32 origFee = mLocalTxnLoadFee; raiseCount = 0; @@ -171,7 +172,7 @@ public: Json::Value j (Json::objectValue); { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); // base_fee = The cost to send a "reference" transaction under no load, in millionths of a Ripple j["base_fee"] = Json::Value::UInt (baseFee); @@ -205,12 +206,14 @@ private: static const int lftFeeDecFraction = 4; // decrease fee by 1/4 static const int lftFeeMax = lftNormalFee * 1000000; + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; + uint32 mLocalTxnLoadFee; // Scale factor, lftNormalFee = normal fee uint32 mRemoteTxnLoadFee; // Scale factor, lftNormalFee = normal fee uint32 mClusterTxnLoadFee; // Scale factor, lftNormalFee = normal fee int raiseCount; - - boost::mutex mLock; }; #endif diff --git a/modules/ripple_core/functional/ripple_LoadMonitor.cpp b/modules/ripple_core/functional/ripple_LoadMonitor.cpp index 061e7119ee..913c8795ed 100644 --- a/modules/ripple_core/functional/ripple_LoadMonitor.cpp +++ b/modules/ripple_core/functional/ripple_LoadMonitor.cpp @@ -7,7 +7,8 @@ SETUP_LOG (LoadMonitor) LoadMonitor::LoadMonitor () - : mCounts (0) + : mLock (this, "LoadMonitor", __FILE__, __LINE__) + , mCounts (0) , mLatencyEvents (0) , mLatencyMSAvg (0) , mLatencyMSPeak (0) @@ -66,7 +67,7 @@ void LoadMonitor::update () void LoadMonitor::addCount () { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); update (); ++mCounts; @@ -78,7 +79,7 @@ void LoadMonitor::addLatency (int latency) if (latency == 1) latency = 0; - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); update (); @@ -105,7 +106,7 @@ void LoadMonitor::addCountAndLatency (const std::string& name, int latency) if (latency == 1) latency = 0; - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); update (); ++mCounts; @@ -134,7 +135,7 @@ bool LoadMonitor::isOverTarget (uint64 avg, uint64 peak) bool LoadMonitor::isOver () { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); update (); @@ -146,7 +147,7 @@ bool LoadMonitor::isOver () void LoadMonitor::getCountAndLatency (uint64& count, uint64& latencyAvg, uint64& latencyPeak, bool& isOver) { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); update (); diff --git a/modules/ripple_core/functional/ripple_LoadMonitor.h b/modules/ripple_core/functional/ripple_LoadMonitor.h index f66da5a6e5..a70ac9713c 100644 --- a/modules/ripple_core/functional/ripple_LoadMonitor.h +++ b/modules/ripple_core/functional/ripple_LoadMonitor.h @@ -34,7 +34,10 @@ public: private: void update (); - boost::mutex mLock; + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; + uint64 mCounts; int mLatencyEvents; uint64 mLatencyMSAvg; diff --git a/modules/ripple_data/protocol/ripple_FieldNames.cpp b/modules/ripple_data/protocol/ripple_FieldNames.cpp index 0459e1f49c..a0365ff66b 100644 --- a/modules/ripple_data/protocol/ripple_FieldNames.cpp +++ b/modules/ripple_data/protocol/ripple_FieldNames.cpp @@ -6,9 +6,16 @@ // These must stay at the top of this file std::map SField::codeToField; -boost::mutex SField::mapMutex; int SField::num = 0; + +// Solve construction issues for objects with static storage duration. +SField::StaticLockType& SField::getMutex () +{ + static StaticLockType mutex ("SField", __FILE__, __LINE__); + return mutex; +} + SField sfInvalid (-1), sfGeneric (0); SField sfLedgerEntry (STI_LEDGERENTRY, 1, "LedgerEntry"); SField sfTransaction (STI_TRANSACTION, 1, "Transaction"); @@ -56,7 +63,7 @@ SField::ref SField::getField (int code) if ((type <= 0) || (field <= 0)) return sfInvalid; - boost::mutex::scoped_lock sl (mapMutex); + StaticScopedLockType sl (getMutex (), __FILE__, __LINE__); std::map::iterator it = codeToField.find (code); @@ -115,7 +122,7 @@ std::string SField::getName () const SField::ref SField::getField (const std::string& fieldName) { // OPTIMIZEME me with a map. CHECKME this is case sensitive - boost::mutex::scoped_lock sl (mapMutex); + StaticScopedLockType sl (getMutex (), __FILE__, __LINE__); typedef std::map::value_type int_sfref_pair; BOOST_FOREACH (const int_sfref_pair & fieldPair, codeToField) { @@ -127,7 +134,7 @@ SField::ref SField::getField (const std::string& fieldName) SField::~SField () { - boost::mutex::scoped_lock sl (mapMutex); + StaticScopedLockType sl (getMutex (), __FILE__, __LINE__); std::map::iterator it = codeToField.find (fieldCode); if ((it != codeToField.end ()) && (it->second == this)) diff --git a/modules/ripple_data/protocol/ripple_FieldNames.h b/modules/ripple_data/protocol/ripple_FieldNames.h index 918632288a..69c2dc5f30 100644 --- a/modules/ripple_data/protocol/ripple_FieldNames.h +++ b/modules/ripple_data/protocol/ripple_FieldNames.h @@ -67,7 +67,7 @@ public: , fieldMeta (sMD_Default) , signingField (true) { - boost::mutex::scoped_lock sl (mapMutex); + StaticScopedLockType sl (getMutex (), __FILE__, __LINE__); codeToField[fieldCode] = this; @@ -82,7 +82,7 @@ public: , fieldMeta (sMD_Default) , signingField (true) { - boost::mutex::scoped_lock sl (mapMutex); + StaticScopedLockType sl (getMutex (), __FILE__, __LINE__); codeToField[fieldCode] = this; @@ -96,7 +96,7 @@ public: , fieldMeta (sMD_Never) , signingField (true) { - boost::mutex::scoped_lock sl (mapMutex); + StaticScopedLockType sl (getMutex (), __FILE__, __LINE__); fieldNum = ++num; } @@ -196,7 +196,13 @@ public: // VFALCO TODO make these private protected: static std::map codeToField; - static boost::mutex mapMutex; + + typedef RippleMutex StaticLockType; + typedef StaticLockType::ScopedLockType StaticScopedLockType; + + static StaticLockType& getMutex (); + + // VFALCO NOTE can this be replaced with an atomic int???! static int num; SField (SerializedTypeID id, int val); diff --git a/modules/ripple_data/protocol/ripple_RippleAddress.cpp b/modules/ripple_data/protocol/ripple_RippleAddress.cpp index 12595eb3de..29249c2138 100644 --- a/modules/ripple_data/protocol/ripple_RippleAddress.cpp +++ b/modules/ripple_data/protocol/ripple_RippleAddress.cpp @@ -288,7 +288,10 @@ uint160 RippleAddress::getAccountID () const } } -static boost::mutex rncLock; +typedef RippleMutex StaticLockType; +typedef StaticLockType::ScopedLockType StaticScopedLockType; +static StaticLockType s_lock ("RippleAddress", __FILE__, __LINE__); + static boost::unordered_map< Blob , std::string > rncMap; std::string RippleAddress::humanAccountID () const @@ -300,7 +303,7 @@ std::string RippleAddress::humanAccountID () const case VER_ACCOUNT_ID: { - boost::mutex::scoped_lock sl (rncLock); + StaticScopedLockType sl (s_lock, __FILE__, __LINE__); boost::unordered_map< Blob , std::string >::iterator it = rncMap.find (vchData); if (it != rncMap.end ()) diff --git a/modules/ripple_net/basics/ripple_SNTPClient.cpp b/modules/ripple_net/basics/ripple_SNTPClient.cpp index 67ffb04952..17217ace7b 100644 --- a/modules/ripple_net/basics/ripple_SNTPClient.cpp +++ b/modules/ripple_net/basics/ripple_SNTPClient.cpp @@ -41,8 +41,14 @@ static uint8_t SNTPQueryData[48] = #define NTP_OFF_XMITTS_FRAC 11 -SNTPClient::SNTPClient (boost::asio::io_service& service) : mSocket (service), mTimer (service), mResolver (service), - mOffset (0), mLastOffsetUpdate ((time_t) - 1), mReceiveBuffer (256) +SNTPClient::SNTPClient (boost::asio::io_service& service) + : mLock (this, "SNTPClient", __FILE__, __LINE__) + , mSocket (service) + , mTimer (service) + , mResolver (service) + , mOffset (0) + , mLastOffsetUpdate ((time_t) - 1) + , mReceiveBuffer (256) { mSocket.open (boost::asio::ip::udp::v4 ()); mSocket.async_receive_from (boost::asio::buffer (mReceiveBuffer, 256), mReceiveEndpoint, @@ -66,7 +72,7 @@ void SNTPClient::resolveComplete (const boost::system::error_code& error, boost: if (sel != boost::asio::ip::udp::resolver::iterator ()) { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); SNTPQuery& query = mQueries[*sel]; time_t now = time (NULL); @@ -93,7 +99,7 @@ void SNTPClient::receivePacket (const boost::system::error_code& error, std::siz { if (!error) { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); #ifdef SNTP_DEBUG WriteLog (lsTRACE, SNTPClient) << "SNTP: Packet from " << mReceiveEndpoint; #endif @@ -194,7 +200,7 @@ void SNTPClient::timerEntry (const boost::system::error_code& error) void SNTPClient::addServer (const std::string& server) { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); mServers.push_back (std::make_pair (server, (time_t) - 1)); } @@ -221,7 +227,7 @@ void SNTPClient::queryAll () bool SNTPClient::getOffset (int& offset) { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); if ((mLastOffsetUpdate == (time_t) - 1) || ((mLastOffsetUpdate + NTP_TIMESTAMP_VALID) < time (NULL))) return false; @@ -232,7 +238,7 @@ bool SNTPClient::getOffset (int& offset) bool SNTPClient::doQuery () { - boost::mutex::scoped_lock sl (mLock); + ScopedLockType sl (mLock, __FILE__, __LINE__); std::vector< std::pair >::iterator best = mServers.end (); for (std::vector< std::pair >::iterator it = mServers.begin (), end = best; diff --git a/modules/ripple_net/basics/ripple_SNTPClient.h b/modules/ripple_net/basics/ripple_SNTPClient.h index 87e03c31cc..732ccf7507 100644 --- a/modules/ripple_net/basics/ripple_SNTPClient.h +++ b/modules/ripple_net/basics/ripple_SNTPClient.h @@ -46,8 +46,11 @@ private: void processReply (); private: + typedef RippleMutex LockType; + typedef LockType::ScopedLockType ScopedLockType; + LockType mLock; + std::map mQueries; - boost::mutex mLock; boost::asio::ip::udp::socket mSocket; boost::asio::deadline_timer mTimer;