From 72777b6b839a66e6c5b8d4cf374ae914a147566c Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Wed, 28 Nov 2012 15:53:07 -0800 Subject: [PATCH] Remove some shared pointers on load monitors. --- src/cpp/ripple/HashedObject.cpp | 2 +- src/cpp/ripple/JobQueue.h | 2 ++ src/cpp/ripple/Ledger.cpp | 8 ++++---- src/cpp/ripple/Ledger.h | 3 ++- src/cpp/ripple/LoadMonitor.h | 3 ++- src/cpp/ripple/NetworkOPs.cpp | 2 +- src/cpp/ripple/Peer.cpp | 2 +- src/cpp/ripple/RPCHandler.cpp | 2 +- src/cpp/ripple/ValidationCollection.cpp | 2 +- 9 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/cpp/ripple/HashedObject.cpp b/src/cpp/ripple/HashedObject.cpp index fe94aaf045..d430272a37 100644 --- a/src/cpp/ripple/HashedObject.cpp +++ b/src/cpp/ripple/HashedObject.cpp @@ -61,7 +61,7 @@ void HashedObjectStore::waitWrite() void HashedObjectStore::bulkWrite() { - LoadEvent::pointer event = theApp->getJobQueue().getLoadEvent(jtDISK); + LoadEvent::autoptr event(theApp->getJobQueue().getLoadEventAP(jtDISK)); while (1) { std::vector< boost::shared_ptr > set; diff --git a/src/cpp/ripple/JobQueue.h b/src/cpp/ripple/JobQueue.h index ca91a06f19..6dc495da7e 100644 --- a/src/cpp/ripple/JobQueue.h +++ b/src/cpp/ripple/JobQueue.h @@ -104,6 +104,8 @@ public: LoadEvent::pointer getLoadEvent(JobType t) { return boost::make_shared(boost::ref(mJobLoads[t]), true, 1); } + LoadEvent::autoptr getLoadEventAP(JobType t) + { return LoadEvent::autoptr(new LoadEvent(mJobLoads[t], true, 1)); } Json::Value getJson(int c = 0); }; diff --git a/src/cpp/ripple/Ledger.cpp b/src/cpp/ripple/Ledger.cpp index 1f1b2e565b..2e9482e0fe 100644 --- a/src/cpp/ripple/Ledger.cpp +++ b/src/cpp/ripple/Ledger.cpp @@ -339,9 +339,8 @@ uint256 Ledger::getHash() return mHash; } -void Ledger::saveAcceptedLedger(bool fromConsensus) +void Ledger::saveAcceptedLedger(bool fromConsensus, LoadEvent::pointer event) { // can be called in a different thread - LoadEvent::pointer event = theApp->getJobQueue().getLoadEvent(jtDISK); cLog(lsTRACE) << "saveAcceptedLedger " << (fromConsensus ? "fromConsensus " : "fromAcquire ") << getLedgerSeq(); static boost::format ledgerExists("SELECT LedgerSeq FROM Ledgers where LedgerSeq = %d;"); static boost::format deleteLedger("DELETE FROM Ledgers WHERE LedgerSeq = %d;"); @@ -439,7 +438,7 @@ void Ledger::saveAcceptedLedger(bool fromConsensus) } theApp->getLedgerMaster().setFullLedger(shared_from_this()); - event = LoadEvent::pointer(); + event->stop(); theApp->getOPs().pubLedger(shared_from_this()); @@ -1136,7 +1135,8 @@ void Ledger::pendSave(bool fromConsensus) if (!fromConsensus && !theApp->isNewFlag(getHash(), SF_SAVED)) return; - boost::thread thread(boost::bind(&Ledger::saveAcceptedLedger, shared_from_this(), fromConsensus)); + boost::thread thread(boost::bind(&Ledger::saveAcceptedLedger, shared_from_this(), + fromConsensus, theApp->getJobQueue().getLoadEvent(jtDISK))); thread.detach(); boost::recursive_mutex::scoped_lock sl(sPendingSaveLock); diff --git a/src/cpp/ripple/Ledger.h b/src/cpp/ripple/Ledger.h index 64bf9ef4a6..7f9556c3ed 100644 --- a/src/cpp/ripple/Ledger.h +++ b/src/cpp/ripple/Ledger.h @@ -19,6 +19,7 @@ #include "BitcoinUtil.h" #include "SHAMap.h" #include "InstanceCounter.h" +#include "LoadMonitor.h" enum LedgerStateParms { @@ -93,7 +94,7 @@ protected: static void incPendingSaves(); static void decPendingSaves(); - void saveAcceptedLedger(bool fromConsensus); + void saveAcceptedLedger(bool fromConsensus, LoadEvent::pointer); public: Ledger(const RippleAddress& masterID, uint64 startAmount); // used for the starting bootstrap ledger diff --git a/src/cpp/ripple/LoadMonitor.h b/src/cpp/ripple/LoadMonitor.h index 992046c178..6eb259a792 100644 --- a/src/cpp/ripple/LoadMonitor.h +++ b/src/cpp/ripple/LoadMonitor.h @@ -36,7 +36,8 @@ public: class LoadEvent { public: - typedef boost::shared_ptr pointer; + typedef boost::shared_ptr pointer; + typedef std::auto_ptr autoptr; protected: LoadMonitor& mMonitor; diff --git a/src/cpp/ripple/NetworkOPs.cpp b/src/cpp/ripple/NetworkOPs.cpp index cd2c13af4f..e67d8eb927 100644 --- a/src/cpp/ripple/NetworkOPs.cpp +++ b/src/cpp/ripple/NetworkOPs.cpp @@ -1002,7 +1002,7 @@ void NetworkOPs::pubLedger(Ledger::ref lpAccepted) if (NetworkOPs::omDISCONNECTED == getOperatingMode()) return; - LoadEvent::pointer event = theApp->getJobQueue().getLoadEvent(jtPUBLEDGER); + LoadEvent::autoptr event(theApp->getJobQueue().getLoadEventAP(jtPUBLEDGER)); { boost::recursive_mutex::scoped_lock sl(mMonitorLock); diff --git a/src/cpp/ripple/Peer.cpp b/src/cpp/ripple/Peer.cpp index f14b4411ba..f207cba9b1 100644 --- a/src/cpp/ripple/Peer.cpp +++ b/src/cpp/ripple/Peer.cpp @@ -373,7 +373,7 @@ void Peer::processReadBuffer() // std::cerr << "Peer::processReadBuffer: " << mIpPort.first << " " << mIpPort.second << std::endl; - LoadEvent::pointer event = theApp->getJobQueue().getLoadEvent(jtPEER); + LoadEvent::autoptr event(theApp->getJobQueue().getLoadEventAP(jtPEER)); boost::recursive_mutex::scoped_lock sl(theApp->getMasterLock()); diff --git a/src/cpp/ripple/RPCHandler.cpp b/src/cpp/ripple/RPCHandler.cpp index bed264410f..2e94baa2a8 100644 --- a/src/cpp/ripple/RPCHandler.cpp +++ b/src/cpp/ripple/RPCHandler.cpp @@ -1482,7 +1482,7 @@ Json::Value RPCHandler::doCommand(const std::string& command, Json::Value& param cLog(lsTRACE) << "RPC:" << command; cLog(lsTRACE) << "RPC params:" << params; - LoadEvent::pointer le = theApp->getJobQueue().getLoadEvent(jtRPC); + LoadEvent::autoptr le(theApp->getJobQueue().getLoadEventAP(jtRPC)); mRole = role; diff --git a/src/cpp/ripple/ValidationCollection.cpp b/src/cpp/ripple/ValidationCollection.cpp index cab64a9508..f663b2c2a1 100644 --- a/src/cpp/ripple/ValidationCollection.cpp +++ b/src/cpp/ripple/ValidationCollection.cpp @@ -289,7 +289,7 @@ void ValidationCollection::condWrite() void ValidationCollection::doWrite() { - LoadEvent::pointer event = theApp->getJobQueue().getLoadEvent(jtDISK); + LoadEvent::autoptr event(theApp->getJobQueue().getLoadEventAP(jtDISK)); static boost::format insVal("INSERT INTO LedgerValidations " "(LedgerHash,NodePubKey,Flags,SignTime,Signature) VALUES ('%s','%s','%u','%u',%s);");