From a6f866b4d8dd8d3d2dedf7619bcae41007f06974 Mon Sep 17 00:00:00 2001 From: Tom Ritchford Date: Sun, 9 Aug 2015 20:34:54 -0400 Subject: [PATCH] Use std::function in JobQueue. --- src/ripple/app/ledger/impl/LedgerConsensusImp.cpp | 13 ++++++++----- src/ripple/core/JobQueue.h | 10 +++------- src/ripple/core/impl/JobQueue.cpp | 6 +++--- src/ripple/rpc/impl/Yield.cpp | 2 +- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp b/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp index a8bf5e6266..3909a06130 100644 --- a/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp +++ b/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp @@ -642,11 +642,14 @@ void LedgerConsensusImp::handleLCL (uint256 const& lclHash) // Tell the ledger acquire system that we need the consensus ledger mAcquiringLedger = mPrevLedgerHash; - getApp().getJobQueue().addJob (jtADVANCE, "getConsensusLedger", - std::bind ( - &InboundLedgers::acquire, - &getApp().getInboundLedgers(), - mPrevLedgerHash, 0, InboundLedger::fcCONSENSUS)); + auto& previousHash = mPrevLedgerHash; + auto acquire = [previousHash] (Job&) { + getApp().getInboundLedgers().acquire( + previousHash, 0, InboundLedger::fcCONSENSUS); + }; + getApp().getJobQueue().addJob ( + jtADVANCE, "getConsensusLedger", acquire); +; mHaveCorrectLCL = false; } return; diff --git a/src/ripple/core/JobQueue.h b/src/ripple/core/JobQueue.h index 9cb21db60b..1968a97863 100644 --- a/src/ripple/core/JobQueue.h +++ b/src/ripple/core/JobQueue.h @@ -36,15 +36,11 @@ protected: JobQueue (char const* name, Stoppable& parent); public: + using JobFunction = std::function ; virtual ~JobQueue () { } - // VFALCO NOTE Using boost::function here because Visual Studio 2012 - // std::function doesn't swallow return types. - // - // TODO Replace with std::function - // - virtual void addJob (JobType type, - std::string const& name, boost::function const& job) = 0; + virtual void addJob ( + JobType, std::string const& name, JobFunction const&) = 0; // Jobs waiting at this priority virtual int getJobCount (JobType t) const = 0; diff --git a/src/ripple/core/impl/JobQueue.cpp b/src/ripple/core/impl/JobQueue.cpp index 2714263dbe..900531797c 100644 --- a/src/ripple/core/impl/JobQueue.cpp +++ b/src/ripple/core/impl/JobQueue.cpp @@ -115,8 +115,8 @@ public: job_count = m_jobSet.size (); } - void addJob (JobType type, std::string const& name, - boost::function const& jobFunc) override + void addJob ( + JobType type, std::string const& name, JobFunction const& func) override { assert (type != jtINVALID); @@ -166,7 +166,7 @@ public: std::pair ::iterator, bool> result ( m_jobSet.insert (Job (type, name, ++m_lastJob, - data.load (), jobFunc, m_cancelCallback))); + data.load (), func, m_cancelCallback))); queueJob (*result.first, lock); } } diff --git a/src/ripple/rpc/impl/Yield.cpp b/src/ripple/rpc/impl/Yield.cpp index 7294a354bb..9bf55794c0 100644 --- a/src/ripple/rpc/impl/Yield.cpp +++ b/src/ripple/rpc/impl/Yield.cpp @@ -38,7 +38,7 @@ namespace { void runOnJobQueue(std::string const& name, Callback const& callback) { - boost::function cb([callback] (Job&) { callback(); }); + auto cb = [callback] (Job&) { callback(); }; getApp().getJobQueue().addJob(jtCLIENT, name, cb); };