Use qalloc for RawStateTable and OpenView::txs_

This commit is contained in:
Vinnie Falco
2015-11-09 13:36:28 -08:00
committed by Nik Bougalis
parent 3e5ec91977
commit 2401b44bed
6 changed files with 91 additions and 58 deletions

View File

@@ -1956,6 +1956,8 @@
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\basics\make_SSLContext.h"> <ClInclude Include="..\..\src\ripple\basics\make_SSLContext.h">
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\basics\qalloc.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\basics\RangeSet.h"> <ClInclude Include="..\..\src\ripple\basics\RangeSet.h">
</ClInclude> </ClInclude>
<None Include="..\..\src\ripple\basics\README.md"> <None Include="..\..\src\ripple\basics\README.md">
@@ -3965,8 +3967,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild> <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile> </ClCompile>
<ClInclude Include="..\..\src\ripple\unl\tests\qalloc.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\unl\tests\Sim1.h"> <ClInclude Include="..\..\src\ripple\unl\tests\Sim1.h">
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\unl\tests\Sim2.h"> <ClInclude Include="..\..\src\ripple\unl\tests\Sim2.h">

View File

@@ -2685,6 +2685,9 @@
<ClInclude Include="..\..\src\ripple\basics\make_SSLContext.h"> <ClInclude Include="..\..\src\ripple\basics\make_SSLContext.h">
<Filter>ripple\basics</Filter> <Filter>ripple\basics</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\ripple\basics\qalloc.h">
<Filter>ripple\basics</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\basics\RangeSet.h"> <ClInclude Include="..\..\src\ripple\basics\RangeSet.h">
<Filter>ripple\basics</Filter> <Filter>ripple\basics</Filter>
</ClInclude> </ClInclude>
@@ -4593,9 +4596,6 @@
<ClCompile Include="..\..\src\ripple\unl\tests\Network_test.cpp"> <ClCompile Include="..\..\src\ripple\unl\tests\Network_test.cpp">
<Filter>ripple\unl\tests</Filter> <Filter>ripple\unl\tests</Filter>
</ClCompile> </ClCompile>
<ClInclude Include="..\..\src\ripple\unl\tests\qalloc.h">
<Filter>ripple\unl\tests</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\unl\tests\Sim1.h"> <ClInclude Include="..\..\src\ripple\unl\tests\Sim1.h">
<Filter>ripple\unl\tests</Filter> <Filter>ripple\unl\tests</Filter>
</ClInclude> </ClInclude>

View File

@@ -17,8 +17,8 @@
*/ */
//============================================================================== //==============================================================================
#ifndef RIPPLE_SIM_QALLOC_H_INCLUDED #ifndef RIPPLE_BASICS_QALLOC_H_INCLUDED
#define RIPPLE_SIM_QALLOC_H_INCLUDED #define RIPPLE_BASICS_QALLOC_H_INCLUDED
#include <ripple/basics/contract.h> #include <ripple/basics/contract.h>
#include <boost/intrusive/list.hpp> #include <boost/intrusive/list.hpp>
@@ -29,9 +29,9 @@
#include <memory> #include <memory>
#include <new> #include <new>
#include <sstream> #include <sstream>
#include <type_traits>
namespace ripple { namespace ripple {
namespace test {
namespace detail { namespace detail {
@@ -87,11 +87,11 @@ public:
} // detail } // detail
template <class T> template <class T, bool ShareOnCopy = true>
class qalloc_type class qalloc_type
{ {
private: private:
template <class U> template <class, bool>
friend class qalloc_type; friend class qalloc_type;
std::shared_ptr< std::shared_ptr<
@@ -105,22 +105,24 @@ public:
std::add_lvalue_reference<T>::type; std::add_lvalue_reference<T>::type;
using const_reference = typename using const_reference = typename
std::add_lvalue_reference<T const>::type; std::add_lvalue_reference<T const>::type;
using propagate_on_container_move_assignment =
std::true_type;
template <class U> template <class U>
struct rebind struct rebind
{ {
using other = qalloc_type<U>; using other = qalloc_type<U, ShareOnCopy>;
}; };
qalloc_type (qalloc_type const&) = default; qalloc_type (qalloc_type const&) = default;
qalloc_type& operator= (qalloc_type const&) = default;
qalloc_type (qalloc_type&& other) = default; qalloc_type (qalloc_type&& other) = default;
qalloc_type& operator= (qalloc_type const&) = default;
qalloc_type& operator= (qalloc_type&&) = default; qalloc_type& operator= (qalloc_type&&) = default;
qalloc_type(); qalloc_type();
template <class U> template <class U>
qalloc_type (qalloc_type<U> const& u); qalloc_type (qalloc_type<U, ShareOnCopy> const& u);
template <class U> template <class U>
U* U*
@@ -136,16 +138,23 @@ public:
void void
deallocate (T* p, std::size_t n); deallocate (T* p, std::size_t n);
void template <class U>
destroy (T* t); bool
operator== (qalloc_type<U, ShareOnCopy> const& u);
template <class U> template <class U>
bool bool
operator== (qalloc_type<U> const& u); operator!= (qalloc_type<U, ShareOnCopy> const& u);
template <class U> qalloc_type
bool select_on_container_copy_construction() const;
operator!= (qalloc_type<U> const& u);
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. /** Allocator optimized for delete in temporal order.
@@ -158,7 +167,7 @@ public:
May not be called concurrently. May not be called concurrently.
*/ */
using qalloc = qalloc_type<int>; using qalloc = qalloc_type<int, true>;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@@ -292,25 +301,25 @@ qalloc_impl<_>::deallocate (void* p)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
template <class T> template <class T, bool ShareOnCopy>
qalloc_type<T>::qalloc_type() qalloc_type<T, ShareOnCopy>::qalloc_type()
: impl_ (std::make_shared< : impl_ (std::make_shared<
detail::qalloc_impl<>>()) detail::qalloc_impl<>>())
{ {
} }
template <class T> template <class T, bool ShareOnCopy>
template <class U> template <class U>
qalloc_type<T>::qalloc_type( qalloc_type<T, ShareOnCopy>::qalloc_type(
qalloc_type<U> const& u) qalloc_type<U, ShareOnCopy> const& u)
: impl_ (u.impl_) : impl_ (u.impl_)
{ {
} }
template <class T> template <class T, bool ShareOnCopy>
template <class U> template <class U>
U* U*
qalloc_type<T>::alloc (std::size_t n) qalloc_type<T, ShareOnCopy>::alloc (std::size_t n)
{ {
if (n > std::numeric_limits< if (n > std::numeric_limits<
std::size_t>::max() / sizeof(U)) std::size_t>::max() / sizeof(U))
@@ -321,61 +330,77 @@ qalloc_type<T>::alloc (std::size_t n)
std::alignment_of<U>::value)); std::alignment_of<U>::value));
} }
template <class T> template <class T, bool ShareOnCopy>
template <class U> template <class U>
inline inline
void void
qalloc_type<T>::dealloc( qalloc_type<T, ShareOnCopy>::dealloc(
U* p, std::size_t n) U* p, std::size_t n)
{ {
impl_->deallocate(p); impl_->deallocate(p);
} }
template <class T> template <class T, bool ShareOnCopy>
T* T*
qalloc_type<T>::allocate (std::size_t n) qalloc_type<T, ShareOnCopy>::allocate (std::size_t n)
{ {
return alloc<T>(n); return alloc<T>(n);
} }
template <class T> template <class T, bool ShareOnCopy>
inline inline
void void
qalloc_type<T>::deallocate( qalloc_type<T, ShareOnCopy>::deallocate(
T* p, std::size_t n) T* p, std::size_t n)
{ {
dealloc(p, n); dealloc(p, n);
} }
template <class T> template <class T, bool ShareOnCopy>
inline
void
qalloc_type<T>::destroy (T* t)
{
t->~T();
}
template <class T>
template <class U> template <class U>
inline inline
bool bool
qalloc_type<T>::operator==( qalloc_type<T, ShareOnCopy>::operator==(
qalloc_type<U> const& u) qalloc_type<U, ShareOnCopy> const& u)
{ {
return impl_.get() == u.impl_.get(); return impl_.get() == u.impl_.get();
} }
template <class T> template <class T, bool ShareOnCopy>
template <class U> template <class U>
inline inline
bool bool
qalloc_type<T>::operator!=( qalloc_type<T, ShareOnCopy>::operator!=(
qalloc_type<U> const& u) qalloc_type<U, ShareOnCopy> const& u)
{ {
return ! (*this == u); return ! (*this == u);
} }
} // test template <class T, bool ShareOnCopy>
auto
qalloc_type<T, ShareOnCopy>::select_on_container_copy_construction() const ->
qalloc_type
{
return select_on_copy(
std::integral_constant<bool, ShareOnCopy>{});
}
template <class T, bool ShareOnCopy>
auto
qalloc_type<T, ShareOnCopy>::select_on_copy(std::true_type) const ->
qalloc_type
{
return *this; // shared arena
}
template <class T, bool ShareOnCopy>
auto
qalloc_type<T, ShareOnCopy>::select_on_copy(std::false_type) const ->
qalloc_type
{
return {}; // new arena
}
} // ripple } // ripple
#endif #endif

View File

@@ -23,7 +23,10 @@
#include <ripple/ledger/RawView.h> #include <ripple/ledger/RawView.h>
#include <ripple/ledger/ReadView.h> #include <ripple/ledger/ReadView.h>
#include <ripple/ledger/detail/RawStateTable.h> #include <ripple/ledger/detail/RawStateTable.h>
#include <ripple/basics/qalloc.h>
#include <ripple/protocol/XRPAmount.h> #include <ripple/protocol/XRPAmount.h>
#include <functional>
#include <utility>
namespace ripple { namespace ripple {
@@ -51,9 +54,11 @@ private:
// List of tx, key order // List of tx, key order
using txs_map = std::map<key_type, using txs_map = std::map<key_type,
std::pair<std::shared_ptr< std::pair<std::shared_ptr<Serializer const>,
Serializer const>, std::shared_ptr< std::shared_ptr<Serializer const>>,
Serializer const>>>; std::less<key_type>, qalloc_type<std::pair<key_type const,
std::pair<std::shared_ptr<Serializer const>,
std::shared_ptr<Serializer const>>>, false>>;
Rules rules_; Rules rules_;
txs_map txs_; txs_map txs_;

View File

@@ -22,6 +22,7 @@
#include <ripple/ledger/RawView.h> #include <ripple/ledger/RawView.h>
#include <ripple/ledger/ReadView.h> #include <ripple/ledger/ReadView.h>
#include <ripple/basics/qalloc.h>
#include <map> #include <map>
#include <utility> #include <utility>
@@ -89,7 +90,9 @@ private:
class sles_iter_impl; class sles_iter_impl;
using items_t = std::map<key_type, using items_t = std::map<key_type,
std::pair<Action, std::shared_ptr<SLE>>>; std::pair<Action, std::shared_ptr<SLE>>,
std::less<key_type>, qalloc_type<std::pair<key_type const,
std::pair<Action, std::shared_ptr<SLE>>>, false>>;
items_t items_; items_t items_;
XRPAmount dropsDestroyed_ = 0; XRPAmount dropsDestroyed_ = 0;

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_SIM_BASICNETWORK_H_INCLUDED #ifndef RIPPLE_SIM_BASICNETWORK_H_INCLUDED
#define RIPPLE_SIM_BASICNETWORK_H_INCLUDED #define RIPPLE_SIM_BASICNETWORK_H_INCLUDED
#include <ripple/unl/tests/qalloc.h> #include <ripple/basics/qalloc.h>
#include <beast/chrono/manual_clock.h> #include <beast/chrono/manual_clock.h>
#include <beast/hash/hash_append.h> #include <beast/hash/hash_append.h>
#include <beast/hash/uhash.h> #include <beast/hash/uhash.h>
@@ -49,7 +49,7 @@ namespace test {
vertices and configurable connections representing edges. vertices and configurable connections representing edges.
The caller is responsible for creating the Peer objects ahead The caller is responsible for creating the Peer objects ahead
of time. of time.
Peer objects cannot be destroyed once the BasicNetwork is Peer objects cannot be destroyed once the BasicNetwork is
constructed. To handle peers going online and offline, constructed. To handle peers going online and offline,
callers can simply disconnect all links and reconnect them callers can simply disconnect all links and reconnect them
@@ -166,7 +166,7 @@ private:
, h_ (std::move(h)) , h_ (std::move(h))
{ {
} }
msg_impl (Peer* from_, Peer* to_, msg_impl (Peer* from_, Peer* to_,
time_point when_, Handler const& h) time_point when_, Handler const& h)
: msg (from_, to_, when_) : msg (from_, to_, when_)
@@ -320,7 +320,7 @@ public:
If a connection is present, both ends are If a connection is present, both ends are
disconnected. disconnected.
Any pending messages on the connection Any pending messages on the connection
are discarded. are discarded.
@@ -345,7 +345,7 @@ public:
Effects: Effects:
If the link is not broken when the If the link is not broken when the
link's `delay` time has elapsed, link's `delay` time has elapsed,
the function will be invoked with the function will be invoked with
no arguments. no arguments.
@@ -399,7 +399,7 @@ public:
cancel (cancel_token const& token); cancel (cancel_token const& token);
/** Perform breadth-first search. /** Perform breadth-first search.
Function will be called with this signature: Function will be called with this signature:
void(std::size_t, Peer&); void(std::size_t, Peer&);