From 2401b44bedef9dce2cd639ae6d301276813a95c5 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 9 Nov 2015 13:36:28 -0800 Subject: [PATCH] Use qalloc for RawStateTable and OpenView::txs_ --- Builds/VisualStudio2015/RippleD.vcxproj | 4 +- .../VisualStudio2015/RippleD.vcxproj.filters | 6 +- src/ripple/{unl/tests => basics}/qalloc.h | 111 +++++++++++------- src/ripple/ledger/OpenView.h | 11 +- src/ripple/ledger/detail/RawStateTable.h | 5 +- src/ripple/unl/tests/BasicNetwork.h | 12 +- 6 files changed, 91 insertions(+), 58 deletions(-) rename src/ripple/{unl/tests => basics}/qalloc.h (77%) diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index 4c0c2c9aa..b512202ed 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -1956,6 +1956,8 @@ + + @@ -3965,8 +3967,6 @@ True True - - diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index 3680883f6..fab7841dd 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -2685,6 +2685,9 @@ ripple\basics + + ripple\basics + ripple\basics @@ -4593,9 +4596,6 @@ ripple\unl\tests - - ripple\unl\tests - ripple\unl\tests diff --git a/src/ripple/unl/tests/qalloc.h b/src/ripple/basics/qalloc.h similarity index 77% rename from src/ripple/unl/tests/qalloc.h rename to src/ripple/basics/qalloc.h index 29efe0ec5..bb2be4498 100644 --- a/src/ripple/unl/tests/qalloc.h +++ b/src/ripple/basics/qalloc.h @@ -17,8 +17,8 @@ */ //============================================================================== -#ifndef RIPPLE_SIM_QALLOC_H_INCLUDED -#define RIPPLE_SIM_QALLOC_H_INCLUDED +#ifndef RIPPLE_BASICS_QALLOC_H_INCLUDED +#define RIPPLE_BASICS_QALLOC_H_INCLUDED #include #include @@ -29,9 +29,9 @@ #include #include #include +#include namespace ripple { -namespace test { namespace detail { @@ -87,11 +87,11 @@ public: } // detail -template +template class qalloc_type { private: - template + template friend class qalloc_type; std::shared_ptr< @@ -105,22 +105,24 @@ public: std::add_lvalue_reference::type; using const_reference = typename std::add_lvalue_reference::type; + using propagate_on_container_move_assignment = + std::true_type; template struct rebind { - using other = qalloc_type; + using other = qalloc_type; }; qalloc_type (qalloc_type const&) = default; - qalloc_type& operator= (qalloc_type const&) = default; qalloc_type (qalloc_type&& other) = default; + qalloc_type& operator= (qalloc_type const&) = default; qalloc_type& operator= (qalloc_type&&) = default; qalloc_type(); template - qalloc_type (qalloc_type const& u); + qalloc_type (qalloc_type const& u); template U* @@ -136,16 +138,23 @@ public: void deallocate (T* p, std::size_t n); - void - destroy (T* t); + template + bool + operator== (qalloc_type const& u); template bool - operator== (qalloc_type const& u); + operator!= (qalloc_type const& u); - template - bool - operator!= (qalloc_type const& u); + qalloc_type + select_on_container_copy_construction() const; + +private: + qalloc_type + select_on_copy(std::true_type) const; + + qalloc_type + select_on_copy(std::false_type) const; }; /** Allocator optimized for delete in temporal order. @@ -158,7 +167,7 @@ public: May not be called concurrently. */ -using qalloc = qalloc_type; +using qalloc = qalloc_type; //------------------------------------------------------------------------------ @@ -292,25 +301,25 @@ qalloc_impl<_>::deallocate (void* p) //------------------------------------------------------------------------------ -template -qalloc_type::qalloc_type() +template +qalloc_type::qalloc_type() : impl_ (std::make_shared< detail::qalloc_impl<>>()) { } -template +template template -qalloc_type::qalloc_type( - qalloc_type const& u) +qalloc_type::qalloc_type( + qalloc_type const& u) : impl_ (u.impl_) { } -template +template template U* -qalloc_type::alloc (std::size_t n) +qalloc_type::alloc (std::size_t n) { if (n > std::numeric_limits< std::size_t>::max() / sizeof(U)) @@ -321,61 +330,77 @@ qalloc_type::alloc (std::size_t n) std::alignment_of::value)); } -template +template template inline void -qalloc_type::dealloc( +qalloc_type::dealloc( U* p, std::size_t n) { impl_->deallocate(p); } -template +template T* -qalloc_type::allocate (std::size_t n) +qalloc_type::allocate (std::size_t n) { return alloc(n); } -template +template inline void -qalloc_type::deallocate( +qalloc_type::deallocate( T* p, std::size_t n) { dealloc(p, n); } -template -inline -void -qalloc_type::destroy (T* t) -{ - t->~T(); -} - -template +template template inline bool -qalloc_type::operator==( - qalloc_type const& u) +qalloc_type::operator==( + qalloc_type const& u) { return impl_.get() == u.impl_.get(); } -template +template template inline bool -qalloc_type::operator!=( - qalloc_type const& u) +qalloc_type::operator!=( + qalloc_type const& u) { return ! (*this == u); } -} // test +template +auto +qalloc_type::select_on_container_copy_construction() const -> + qalloc_type +{ + return select_on_copy( + std::integral_constant{}); +} + +template +auto +qalloc_type::select_on_copy(std::true_type) const -> + qalloc_type +{ + return *this; // shared arena +} + +template +auto +qalloc_type::select_on_copy(std::false_type) const -> + qalloc_type +{ + return {}; // new arena +} + } // ripple #endif diff --git a/src/ripple/ledger/OpenView.h b/src/ripple/ledger/OpenView.h index 4865a3820..ce9f4fc3a 100644 --- a/src/ripple/ledger/OpenView.h +++ b/src/ripple/ledger/OpenView.h @@ -23,7 +23,10 @@ #include #include #include +#include #include +#include +#include namespace ripple { @@ -51,9 +54,11 @@ private: // List of tx, key order using txs_map = std::map, std::shared_ptr< - Serializer const>>>; + std::pair, + std::shared_ptr>, + std::less, qalloc_type, + std::shared_ptr>>, false>>; Rules rules_; txs_map txs_; diff --git a/src/ripple/ledger/detail/RawStateTable.h b/src/ripple/ledger/detail/RawStateTable.h index 973e19e25..651b6b60c 100644 --- a/src/ripple/ledger/detail/RawStateTable.h +++ b/src/ripple/ledger/detail/RawStateTable.h @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -89,7 +90,9 @@ private: class sles_iter_impl; using items_t = std::map>>; + std::pair>, + std::less, qalloc_type>>, false>>; items_t items_; XRPAmount dropsDestroyed_ = 0; diff --git a/src/ripple/unl/tests/BasicNetwork.h b/src/ripple/unl/tests/BasicNetwork.h index 0bc004da9..8095f859d 100644 --- a/src/ripple/unl/tests/BasicNetwork.h +++ b/src/ripple/unl/tests/BasicNetwork.h @@ -20,7 +20,7 @@ #ifndef RIPPLE_SIM_BASICNETWORK_H_INCLUDED #define RIPPLE_SIM_BASICNETWORK_H_INCLUDED -#include +#include #include #include #include @@ -49,7 +49,7 @@ namespace test { vertices and configurable connections representing edges. The caller is responsible for creating the Peer objects ahead of time. - + Peer objects cannot be destroyed once the BasicNetwork is constructed. To handle peers going online and offline, callers can simply disconnect all links and reconnect them @@ -166,7 +166,7 @@ private: , h_ (std::move(h)) { } - + msg_impl (Peer* from_, Peer* to_, time_point when_, Handler const& h) : msg (from_, to_, when_) @@ -320,7 +320,7 @@ public: If a connection is present, both ends are disconnected. - + Any pending messages on the connection are discarded. @@ -345,7 +345,7 @@ public: Effects: - If the link is not broken when the + If the link is not broken when the link's `delay` time has elapsed, the function will be invoked with no arguments. @@ -399,7 +399,7 @@ public: cancel (cancel_token const& token); /** Perform breadth-first search. - + Function will be called with this signature: void(std::size_t, Peer&);