Permalink
Browse files

Use qalloc for RawStateTable and OpenView::txs_

  • Loading branch information...
vinniefalco authored and nbougalis committed Nov 9, 2015
1 parent 3e5ec91 commit 2401b44bedef9dce2cd639ae6d301276813a95c5
@@ -1956,6 +1956,8 @@
</ClInclude>
<ClInclude Include="..\..\src\ripple\basics\make_SSLContext.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\basics\qalloc.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\basics\RangeSet.h">
</ClInclude>
<None Include="..\..\src\ripple\basics\README.md">
@@ -3965,8 +3967,6 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\unl\tests\qalloc.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\unl\tests\Sim1.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\unl\tests\Sim2.h">
@@ -2685,6 +2685,9 @@
<ClInclude Include="..\..\src\ripple\basics\make_SSLContext.h">
<Filter>ripple\basics</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\basics\qalloc.h">
<Filter>ripple\basics</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\basics\RangeSet.h">
<Filter>ripple\basics</Filter>
</ClInclude>
@@ -4593,9 +4596,6 @@
<ClCompile Include="..\..\src\ripple\unl\tests\Network_test.cpp">
<Filter>ripple\unl\tests</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\unl\tests\qalloc.h">
<Filter>ripple\unl\tests</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\unl\tests\Sim1.h">
<Filter>ripple\unl\tests</Filter>
</ClInclude>
@@ -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 <ripple/basics/contract.h>
#include <boost/intrusive/list.hpp>
@@ -29,9 +29,9 @@
#include <memory>
#include <new>
#include <sstream>
#include <type_traits>
namespace ripple {
namespace test {
namespace detail {
@@ -87,11 +87,11 @@ class qalloc_impl
} // detail
template <class T>
template <class T, bool ShareOnCopy = true>
class qalloc_type
{
private:
template <class U>
template <class, bool>
friend class qalloc_type;
std::shared_ptr<
@@ -105,22 +105,24 @@ class qalloc_type
std::add_lvalue_reference<T>::type;
using const_reference = typename
std::add_lvalue_reference<T const>::type;
using propagate_on_container_move_assignment =
std::true_type;
template <class U>
struct rebind
{
using other = qalloc_type<U>;
using other = qalloc_type<U, ShareOnCopy>;
};
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 <class U>
qalloc_type (qalloc_type<U> const& u);
qalloc_type (qalloc_type<U, ShareOnCopy> const& u);
template <class U>
U*
@@ -136,16 +138,23 @@ class qalloc_type
void
deallocate (T* p, std::size_t n);
void
destroy (T* t);
template <class U>
bool
operator== (qalloc_type<U> const& u);
operator== (qalloc_type<U, ShareOnCopy> const& u);
template <class U>
bool
operator!= (qalloc_type<U> const& u);
operator!= (qalloc_type<U, ShareOnCopy> 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 @@ class qalloc_type
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>
qalloc_type<T>::qalloc_type()
template <class T, bool ShareOnCopy>
qalloc_type<T, ShareOnCopy>::qalloc_type()
: impl_ (std::make_shared<
detail::qalloc_impl<>>())
{
}
template <class T>
template <class T, bool ShareOnCopy>
template <class U>
qalloc_type<T>::qalloc_type(
qalloc_type<U> const& u)
qalloc_type<T, ShareOnCopy>::qalloc_type(
qalloc_type<U, ShareOnCopy> const& u)
: impl_ (u.impl_)
{
}
template <class T>
template <class T, bool ShareOnCopy>
template <class U>
U*
qalloc_type<T>::alloc (std::size_t n)
qalloc_type<T, ShareOnCopy>::alloc (std::size_t n)
{
if (n > std::numeric_limits<
std::size_t>::max() / sizeof(U))
@@ -321,61 +330,77 @@ qalloc_type<T>::alloc (std::size_t n)
std::alignment_of<U>::value));
}
template <class T>
template <class T, bool ShareOnCopy>
template <class U>
inline
void
qalloc_type<T>::dealloc(
qalloc_type<T, ShareOnCopy>::dealloc(
U* p, std::size_t n)
{
impl_->deallocate(p);
}
template <class T>
template <class T, bool ShareOnCopy>
T*
qalloc_type<T>::allocate (std::size_t n)
qalloc_type<T, ShareOnCopy>::allocate (std::size_t n)
{
return alloc<T>(n);
}
template <class T>
template <class T, bool ShareOnCopy>
inline
void
qalloc_type<T>::deallocate(
qalloc_type<T, ShareOnCopy>::deallocate(
T* p, std::size_t n)
{
dealloc(p, n);
}
template <class T>
inline
void
qalloc_type<T>::destroy (T* t)
{
t->~T();
}
template <class T>
template <class T, bool ShareOnCopy>
template <class U>
inline
bool
qalloc_type<T>::operator==(
qalloc_type<U> const& u)
qalloc_type<T, ShareOnCopy>::operator==(
qalloc_type<U, ShareOnCopy> const& u)
{
return impl_.get() == u.impl_.get();
}
template <class T>
template <class T, bool ShareOnCopy>
template <class U>
inline
bool
qalloc_type<T>::operator!=(
qalloc_type<U> const& u)
qalloc_type<T, ShareOnCopy>::operator!=(
qalloc_type<U, ShareOnCopy> const& 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
#endif
@@ -23,7 +23,10 @@
#include <ripple/ledger/RawView.h>
#include <ripple/ledger/ReadView.h>
#include <ripple/ledger/detail/RawStateTable.h>
#include <ripple/basics/qalloc.h>
#include <ripple/protocol/XRPAmount.h>
#include <functional>
#include <utility>
namespace ripple {
@@ -51,9 +54,11 @@ class OpenView
// List of tx, key order
using txs_map = std::map<key_type,
std::pair<std::shared_ptr<
Serializer const>, std::shared_ptr<
Serializer const>>>;
std::pair<std::shared_ptr<Serializer const>,
std::shared_ptr<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_;
txs_map txs_;
@@ -22,6 +22,7 @@
#include <ripple/ledger/RawView.h>
#include <ripple/ledger/ReadView.h>
#include <ripple/basics/qalloc.h>
#include <map>
#include <utility>
@@ -89,7 +90,9 @@ class RawStateTable
class sles_iter_impl;
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_;
XRPAmount dropsDestroyed_ = 0;
@@ -20,7 +20,7 @@
#ifndef 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/hash/hash_append.h>
#include <beast/hash/uhash.h>
@@ -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 @@ class BasicNetwork
, h_ (std::move(h))
{
}
msg_impl (Peer* from_, Peer* to_,
time_point when_, Handler const& h)
: msg (from_, to_, when_)
@@ -320,7 +320,7 @@ class BasicNetwork
If a connection is present, both ends are
disconnected.
Any pending messages on the connection
are discarded.
@@ -345,7 +345,7 @@ class BasicNetwork
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 @@ class BasicNetwork
cancel (cancel_token const& token);
/** Perform breadth-first search.
Function will be called with this signature:
void(std::size_t, Peer&);

0 comments on commit 2401b44

Please sign in to comment.