From 6aca65ff76d41a6fd2480d178febb4e56c539bbe Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 28 Nov 2012 15:27:20 -0800 Subject: [PATCH] Get the shared pointers out of the scoped lock stuff. We don't need it. --- src/cpp/ripple/Application.h | 2 +- src/cpp/ripple/HashedObject.cpp | 6 +++--- src/cpp/ripple/Ledger.cpp | 2 +- src/cpp/ripple/LedgerConsensus.cpp | 2 +- src/cpp/ripple/NetworkOPs.cpp | 4 ++-- src/cpp/ripple/RPCHandler.cpp | 2 +- src/cpp/ripple/ScopedLock.h | 6 ++++-- src/cpp/ripple/Transaction.cpp | 2 +- 8 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/cpp/ripple/Application.h b/src/cpp/ripple/Application.h index 343d592637..a7518299e4 100644 --- a/src/cpp/ripple/Application.h +++ b/src/cpp/ripple/Application.h @@ -35,7 +35,7 @@ public: DatabaseCon(const std::string& name, const char *initString[], int countInit); ~DatabaseCon(); Database* getDB() { return mDatabase; } - ScopedLock getDBLock() { return ScopedLock(mLock); } + boost::recursive_mutex& getDBLock() { return mLock; } }; class Application diff --git a/src/cpp/ripple/HashedObject.cpp b/src/cpp/ripple/HashedObject.cpp index 7765574ad6..d64e33a644 100644 --- a/src/cpp/ripple/HashedObject.cpp +++ b/src/cpp/ripple/HashedObject.cpp @@ -53,7 +53,7 @@ bool HashedObjectStore::store(HashedObjectType type, uint32 index, void HashedObjectStore::waitWrite() { - boost::unique_lock sl(mWriteMutex); + boost::mutex::scoped_lock sl(mWriteMutex); while (mWritePending) mWriteCondition.wait(sl); } @@ -67,7 +67,7 @@ void HashedObjectStore::bulkWrite() set.reserve(128); { - boost::unique_lock sl(mWriteMutex); + boost::mutex::scoped_lock sl(mWriteMutex); mWriteSet.swap(set); assert(mWriteSet.empty()); if (set.empty()) @@ -85,7 +85,7 @@ void HashedObjectStore::bulkWrite() Database* db = theApp->getHashNodeDB()->getDB(); { - ScopedLock sl = theApp->getHashNodeDB()->getDBLock(); + ScopedLock sl( theApp->getHashNodeDB()->getDBLock()); db->executeSQL("BEGIN TRANSACTION;"); diff --git a/src/cpp/ripple/Ledger.cpp b/src/cpp/ripple/Ledger.cpp index 334f561549..1f1b2e565b 100644 --- a/src/cpp/ripple/Ledger.cpp +++ b/src/cpp/ripple/Ledger.cpp @@ -369,7 +369,7 @@ void Ledger::saveAcceptedLedger(bool fromConsensus) SHAMap& txSet = *peekTransactionMap(); Database *db = theApp->getTxnDB()->getDB(); - ScopedLock dbLock = theApp->getTxnDB()->getDBLock(); + ScopedLock dbLock(theApp->getTxnDB()->getDBLock()); db->executeSQL("BEGIN TRANSACTION;"); SHAMapTreeNode::TNType type; for (SHAMapItem::pointer item = txSet.peekFirstItem(type); !!item; diff --git a/src/cpp/ripple/LedgerConsensus.cpp b/src/cpp/ripple/LedgerConsensus.cpp index ef32c11531..e3e867d90a 100644 --- a/src/cpp/ripple/LedgerConsensus.cpp +++ b/src/cpp/ripple/LedgerConsensus.cpp @@ -1251,7 +1251,7 @@ void LedgerConsensus::accept(SHAMap::ref set, LoadEvent::pointer) cLog(lsINFO) << "CNF newLCL " << newLCLHash; Ledger::pointer newOL = boost::make_shared(true, boost::ref(*newLCL)); - ScopedLock sl = theApp->getLedgerMaster().getLock(); + ScopedLock sl( theApp->getLedgerMaster().getLock()); // Apply disputed transactions that didn't get in TransactionEngine engine(newOL); diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index 97adc8e9f2..cd2c13af4f 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -888,7 +888,7 @@ std::vector< std::pair > { Database* db = theApp->getTxnDB()->getDB(); - ScopedLock dbLock = theApp->getTxnDB()->getDBLock(); + ScopedLock sl(theApp->getTxnDB()->getDBLock()); SQL_FOREACH(db, sql) { @@ -909,7 +909,7 @@ std::vector RippleAddress acct; { Database* db = theApp->getTxnDB()->getDB(); - ScopedLock dblock = theApp->getTxnDB()->getDBLock(); + ScopedLock sl(theApp->getTxnDB()->getDBLock()); SQL_FOREACH(db, sql) { if (acct.setAccountID(db->getStrBinary("Account"))) diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index 1765efcdf2..bed264410f 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1158,7 +1158,7 @@ Json::Value RPCHandler::doTxHistory(const Json::Value& params) { Database* db = theApp->getTxnDB()->getDB(); - ScopedLock dbLock = theApp->getTxnDB()->getDBLock(); + ScopedLock sl (theApp->getTxnDB()->getDBLock()); SQL_FOREACH(db, sql) { diff --git a/src/cpp/ripple/ScopedLock.h b/src/cpp/ripple/ScopedLock.h index 5f85b83ed3..e0859fd774 100644 --- a/src/cpp/ripple/ScopedLock.h +++ b/src/cpp/ripple/ScopedLock.h @@ -6,16 +6,18 @@ #include #include +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 -class ScopedLock +class SharedScopedLock { protected: mutable boost::shared_ptr mHolder; public: - ScopedLock(boost::recursive_mutex& mutex) : + SharedScopedLock(boost::recursive_mutex& mutex) : mHolder(boost::make_shared(boost::ref(mutex))) { ; } void lock() const { mHolder->lock(); } diff --git a/src/cpp/ripple/Transaction.cpp b/src/cpp/ripple/Transaction.cpp index 304494826c..be3c21752d 100644 --- a/src/cpp/ripple/Transaction.cpp +++ b/src/cpp/ripple/Transaction.cpp @@ -150,7 +150,7 @@ bool Transaction::save() % mTransaction->getTransactionID().GetHex()); Database *db = theApp->getTxnDB()->getDB(); - ScopedLock dbLock = theApp->getTxnDB()->getDBLock(); + ScopedLock dbLock(theApp->getTxnDB()->getDBLock()); if (SQL_EXISTS(db, exists)) return false; return db->executeSQL(mTransaction->getSQLInsertHeader() + mTransaction->getSQL(getLedger(), status) + ";");