mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Use std::atomic
This commit is contained in:
committed by
Tom Ritchford
parent
c24a497a23
commit
b43832fe57
@@ -69,7 +69,7 @@ InboundLedger::~InboundLedger ()
|
||||
{
|
||||
// Save any received AS data not processed. It could be useful
|
||||
// for populating a different ledger
|
||||
BOOST_FOREACH (PeerDataPairType& entry, mReceivedData)
|
||||
for (auto& entry : mReceivedData)
|
||||
{
|
||||
if (entry.second->type () == protocol::liAS_NODE)
|
||||
getApp().getInboundLedgers().gotStaleData(entry.second);
|
||||
@@ -164,8 +164,7 @@ bool InboundLedger::tryLocal ()
|
||||
if (mLedger->peekTransactionMap ()->fetchRoot (
|
||||
mLedger->getTransHash (), &filter))
|
||||
{
|
||||
std::vector<uint256> h (mLedger->getNeededTransactionHashes (
|
||||
1, &filter));
|
||||
auto h (mLedger->getNeededTransactionHashes (1, &filter));
|
||||
|
||||
if (h.empty ())
|
||||
{
|
||||
@@ -193,8 +192,7 @@ bool InboundLedger::tryLocal ()
|
||||
if (mLedger->peekAccountStateMap ()->fetchRoot (
|
||||
mLedger->getAccountHash (), &filter))
|
||||
{
|
||||
std::vector<uint256> h (mLedger->getNeededAccountStateHashes (
|
||||
1, &filter));
|
||||
auto h (mLedger->getNeededAccountStateHashes (1, &filter));
|
||||
|
||||
if (h.empty ())
|
||||
{
|
||||
@@ -459,7 +457,7 @@ void InboundLedger::trigger (Peer::ptr const& peer)
|
||||
if (!isProgress () && !mFailed && mByHash && (
|
||||
getTimeouts () > ledgerBecomeAggressiveThreshold))
|
||||
{
|
||||
std::vector<neededHash_t> need = getNeededHashes ();
|
||||
auto need = getNeededHashes ();
|
||||
|
||||
if (!need.empty ())
|
||||
{
|
||||
@@ -467,7 +465,7 @@ void InboundLedger::trigger (Peer::ptr const& peer)
|
||||
tmBH.set_query (true);
|
||||
tmBH.set_ledgerhash (mHash.begin (), mHash.size ());
|
||||
bool typeSet = false;
|
||||
BOOST_FOREACH (neededHash_t & p, need)
|
||||
for (auto& p : need)
|
||||
{
|
||||
if (m_journal.warning) m_journal.warning
|
||||
<< "Want: " << p.second;
|
||||
@@ -1009,9 +1007,7 @@ std::vector<InboundLedger::neededHash_t> InboundLedger::getNeededHashes ()
|
||||
{
|
||||
AccountStateSF filter (mLedger->getLedgerSeq ());
|
||||
// VFALCO NOTE What's the number 4?
|
||||
std::vector<uint256> v = mLedger->getNeededAccountStateHashes (
|
||||
4, &filter);
|
||||
BOOST_FOREACH (uint256 const & h, v)
|
||||
for (auto const& h : mLedger->getNeededAccountStateHashes (4, &filter))
|
||||
{
|
||||
ret.push_back (std::make_pair (
|
||||
protocol::TMGetObjectByHash::otSTATE_NODE, h));
|
||||
@@ -1022,9 +1018,7 @@ std::vector<InboundLedger::neededHash_t> InboundLedger::getNeededHashes ()
|
||||
{
|
||||
TransactionStateSF filter (mLedger->getLedgerSeq ());
|
||||
// VFALCO NOTE What's the number 4?
|
||||
std::vector<uint256> v = mLedger->getNeededTransactionHashes (
|
||||
4, &filter);
|
||||
BOOST_FOREACH (uint256 const & h, v)
|
||||
for (auto const& h : mLedger->getNeededTransactionHashes (4, &filter))
|
||||
{
|
||||
ret.push_back (std::make_pair (
|
||||
protocol::TMGetObjectByHash::otTRANSACTION_NODE, h));
|
||||
@@ -1198,7 +1192,7 @@ void InboundLedger::runData ()
|
||||
|
||||
// Select the peer that gives us the most nodes that are useful,
|
||||
// breaking ties in favor of the peer that responded first.
|
||||
BOOST_FOREACH (PeerDataPairType& entry, data)
|
||||
for (auto& entry : data)
|
||||
{
|
||||
Peer::ptr peer = entry.first.lock();
|
||||
if (peer)
|
||||
@@ -1257,7 +1251,6 @@ Json::Value InboundLedger::getJson (int)
|
||||
|
||||
// VFALCO Why 16?
|
||||
auto v = mLedger->getNeededAccountStateHashes (16, nullptr);
|
||||
|
||||
for (auto const& h : v)
|
||||
{
|
||||
hv.append (to_string (h));
|
||||
@@ -1270,7 +1263,6 @@ Json::Value InboundLedger::getJson (int)
|
||||
Json::Value hv (Json::arrayValue);
|
||||
// VFALCO Why 16?
|
||||
auto v = mLedger->getNeededTransactionHashes (16, nullptr);
|
||||
|
||||
for (auto const& h : v)
|
||||
{
|
||||
hv.append (to_string (h));
|
||||
|
||||
@@ -69,6 +69,7 @@ IoServicePool::IoServicePool (Stoppable& parent, std::string const& name,
|
||||
, m_service (numberOfThreads)
|
||||
, m_work (std::ref (m_service))
|
||||
, m_threadsDesired (numberOfThreads)
|
||||
, m_threadsRunning (0)
|
||||
{
|
||||
bassert (m_threadsDesired > 0);
|
||||
}
|
||||
@@ -125,7 +126,7 @@ void IoServicePool::onThreadExit()
|
||||
bassert (isStopping());
|
||||
|
||||
// must have at least count 1
|
||||
bassert (m_threadsRunning.get() > 0);
|
||||
bassert (m_threadsRunning.load() > 0);
|
||||
|
||||
if (--m_threadsRunning == 0)
|
||||
{
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
/** An io_service with an associated group of threads. */
|
||||
@@ -50,7 +52,7 @@ private:
|
||||
boost::optional <boost::asio::io_service::work> m_work;
|
||||
std::vector <std::unique_ptr <ServiceThread>> m_threads;
|
||||
int m_threadsDesired;
|
||||
beast::Atomic <int> m_threadsRunning;
|
||||
std::atomic <int> m_threadsRunning;
|
||||
};
|
||||
|
||||
} // ripple
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#ifndef RIPPLE_PATHREQUESTS_H
|
||||
#define RIPPLE_PATHREQUESTS_H
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
class PathRequests
|
||||
@@ -66,7 +68,7 @@ private:
|
||||
// Use a RippleLineCache
|
||||
RippleLineCache::pointer mLineCache;
|
||||
|
||||
beast::Atomic<int> mLastIdentifier;
|
||||
std::atomic<int> mLastIdentifier;
|
||||
|
||||
typedef RippleRecursiveMutex LockType;
|
||||
typedef std::lock_guard <LockType> ScopedLockType;
|
||||
|
||||
@@ -651,15 +651,6 @@ bool SHAMap::hasLeafNode (uint256 const& tag, uint256 const& targetNodeHash)
|
||||
return false; // If this was a matching leaf, we would have caught it already
|
||||
}
|
||||
|
||||
#if 0
|
||||
static
|
||||
void addFPtoList (std::list<SHAMap::fetchPackEntry_t>& list,
|
||||
const uint256& hash, const Blob& blob)
|
||||
{
|
||||
list.push_back (SHAMap::fetchPackEntry_t (hash, blob));
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
@param have A pointer to the map that the recipient already has (if any).
|
||||
@param includeLeaves True if leaf nodes should be included.
|
||||
|
||||
@@ -28,7 +28,7 @@ template <typename Integer>
|
||||
class STInteger : public SerializedType
|
||||
{
|
||||
public:
|
||||
STInteger (Integer v = 0) : value_ (v)
|
||||
explicit STInteger (Integer v) : value_ (v)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
// This is the primary interface into the "client" portion of the program.
|
||||
@@ -43,7 +45,7 @@ InfoSub::InfoSub (Source& source, Consumer consumer)
|
||||
: m_consumer (consumer)
|
||||
, m_source (source)
|
||||
{
|
||||
static beast::Atomic <int> s_seq_id;
|
||||
static std::atomic <int> s_seq_id (0);
|
||||
mSeq = ++s_seq_id;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,6 +73,7 @@ OverlayImpl::OverlayImpl (Stoppable& parent,
|
||||
, m_io_service (io_service)
|
||||
, m_ssl_context (ssl_context)
|
||||
, m_resolver (resolver)
|
||||
, m_nextShortId (0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <boost/asio/ssl/context.hpp>
|
||||
|
||||
#include <beast/cxx14/memory.h> // <memory>
|
||||
#include <atomic>
|
||||
#include <cassert>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
@@ -92,7 +93,7 @@ private:
|
||||
Resolver& m_resolver;
|
||||
|
||||
/** Monotically increasing identifiers for peers */
|
||||
beast::Atomic <Peer::ShortId> m_nextShortId;
|
||||
std::atomic <Peer::ShortId> m_nextShortId;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user