Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std::atomic instead of beast::Atomic #474

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions src/ripple/module/app/ledger/InboundLedger.cpp
Original file line number Diff line number Diff line change
@@ -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,15 +457,15 @@ 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 ())
{
protocol::TMGetObjectByHash tmBH;
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));
3 changes: 2 additions & 1 deletion src/ripple/module/app/main/IoServicePool.cpp
Original file line number Diff line number Diff line change
@@ -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)
{
4 changes: 3 additions & 1 deletion src/ripple/module/app/main/IoServicePool.h
Original file line number Diff line number Diff line change
@@ -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 @@ class IoServicePool : public beast::Stoppable
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
4 changes: 3 additions & 1 deletion src/ripple/module/app/paths/PathRequests.h
Original file line number Diff line number Diff line change
@@ -20,6 +20,8 @@
#ifndef RIPPLE_PATHREQUESTS_H
#define RIPPLE_PATHREQUESTS_H

#include <atomic>

namespace ripple {

class PathRequests
@@ -66,7 +68,7 @@ class PathRequests
// Use a RippleLineCache
RippleLineCache::pointer mLineCache;

beast::Atomic<int> mLastIdentifier;
std::atomic<int> mLastIdentifier;

typedef RippleRecursiveMutex LockType;
typedef std::lock_guard <LockType> ScopedLockType;
9 changes: 0 additions & 9 deletions src/ripple/module/app/shamap/SHAMapSync.cpp
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion src/ripple/module/data/protocol/STInteger.h
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ template <typename Integer>
class STInteger : public SerializedType
{
public:
STInteger (Integer v = 0) : value_ (v)
explicit STInteger (Integer v) : value_ (v)
{
}

4 changes: 3 additions & 1 deletion src/ripple/module/net/rpc/InfoSub.cpp
Original file line number Diff line number Diff line change
@@ -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;
}

1 change: 1 addition & 0 deletions src/ripple/overlay/impl/OverlayImpl.cpp
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@ OverlayImpl::OverlayImpl (Stoppable& parent,
, m_io_service (io_service)
, m_ssl_context (ssl_context)
, m_resolver (resolver)
, m_nextShortId (0)
{
}

3 changes: 2 additions & 1 deletion src/ripple/overlay/impl/OverlayImpl.h
Original file line number Diff line number Diff line change
@@ -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 @@ class OverlayImpl
Resolver& m_resolver;

/** Monotically increasing identifiers for peers */
beast::Atomic <Peer::ShortId> m_nextShortId;
std::atomic <Peer::ShortId> m_nextShortId;

//--------------------------------------------------------------------------