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 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">

View File

@@ -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>

View File

@@ -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 @@ public:
} // 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 @@ public:
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 @@ public:
void
deallocate (T* p, std::size_t n);
void
destroy (T* t);
template <class U>
bool
operator== (qalloc_type<U, ShareOnCopy> const& u);
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);
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<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

View File

@@ -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 @@ private:
// 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_;

View File

@@ -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 @@ private:
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;

View File

@@ -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>