mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Replace qalloc with boost::pmr
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2018 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/basics/qalloc.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <type_traits>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
struct qalloc_test : beast::unit_test::suite
|
||||
{
|
||||
void
|
||||
testBasicProperties()
|
||||
{
|
||||
BEAST_EXPECT(std::is_default_constructible<qalloc>{});
|
||||
BEAST_EXPECT(std::is_copy_constructible<qalloc>{});
|
||||
BEAST_EXPECT(std::is_copy_assignable<qalloc>{});
|
||||
BEAST_EXPECT(std::is_nothrow_move_constructible<qalloc>{});
|
||||
BEAST_EXPECT(std::is_nothrow_move_assignable<qalloc>{});
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
testBasicProperties();
|
||||
}
|
||||
};
|
||||
|
||||
BEAST_DEFINE_TESTSUITE(qalloc, ripple_basics, ripple);
|
||||
|
||||
} // namespace ripple
|
||||
@@ -20,9 +20,12 @@
|
||||
#ifndef RIPPLE_TEST_CSF_SCHEDULER_H_INCLUDED
|
||||
#define RIPPLE_TEST_CSF_SCHEDULER_H_INCLUDED
|
||||
|
||||
#include <ripple/basics/qalloc.h>
|
||||
#include <ripple/basics/ByteUtilities.h>
|
||||
#include <ripple/beast/clock/manual_clock.h>
|
||||
|
||||
#include <boost/container/pmr/monotonic_buffer_resource.hpp>
|
||||
#include <boost/intrusive/set.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
@@ -109,8 +112,8 @@ private:
|
||||
using by_when_set = typename boost::intrusive::make_multiset<
|
||||
event,
|
||||
boost::intrusive::constant_time_size<false>>::type;
|
||||
|
||||
qalloc alloc_;
|
||||
// alloc_ is owned by the scheduler
|
||||
boost::container::pmr::monotonic_buffer_resource* alloc_;
|
||||
by_when_set by_when_;
|
||||
|
||||
public:
|
||||
@@ -120,7 +123,8 @@ private:
|
||||
queue_type&
|
||||
operator=(queue_type const&) = delete;
|
||||
|
||||
explicit queue_type(qalloc const& alloc);
|
||||
explicit queue_type(
|
||||
boost::container::pmr::monotonic_buffer_resource* alloc);
|
||||
|
||||
~queue_type();
|
||||
|
||||
@@ -141,7 +145,7 @@ private:
|
||||
erase(iterator iter);
|
||||
};
|
||||
|
||||
qalloc alloc_;
|
||||
boost::container::pmr::monotonic_buffer_resource alloc_{kilobytes(256)};
|
||||
queue_type queue_;
|
||||
|
||||
// Aged containers that rely on this clock take a non-const reference =(
|
||||
@@ -154,10 +158,6 @@ public:
|
||||
|
||||
Scheduler();
|
||||
|
||||
/** Return the allocator. */
|
||||
qalloc const&
|
||||
alloc() const;
|
||||
|
||||
/** Return the clock. (aged_containers want a non-const ref =( */
|
||||
clock_type&
|
||||
clock() const;
|
||||
@@ -275,7 +275,9 @@ public:
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
inline Scheduler::queue_type::queue_type(qalloc const& alloc) : alloc_(alloc)
|
||||
inline Scheduler::queue_type::queue_type(
|
||||
boost::container::pmr::monotonic_buffer_resource* alloc)
|
||||
: alloc_(alloc)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -286,7 +288,7 @@ inline Scheduler::queue_type::~queue_type()
|
||||
auto e = &*iter;
|
||||
++iter;
|
||||
e->~event();
|
||||
alloc_.dealloc(e, 1);
|
||||
alloc_->deallocate(e, sizeof(e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,7 +316,7 @@ Scheduler::queue_type::emplace(time_point when, Handler&& h) ->
|
||||
typename by_when_set::iterator
|
||||
{
|
||||
using event_type = event_impl<std::decay_t<Handler>>;
|
||||
auto const p = alloc_.alloc<event_type>(1);
|
||||
auto const p = alloc_->allocate(sizeof(event_type));
|
||||
auto& e = *new (p) event_type(when, std::forward<Handler>(h));
|
||||
return by_when_.insert(e);
|
||||
}
|
||||
@@ -325,7 +327,7 @@ Scheduler::queue_type::erase(iterator iter) -> typename by_when_set::iterator
|
||||
auto& e = *iter;
|
||||
auto next = by_when_.erase(iter);
|
||||
e.~event();
|
||||
alloc_.dealloc(&e, 1);
|
||||
alloc_->deallocate(&e, sizeof(e));
|
||||
return next;
|
||||
}
|
||||
|
||||
@@ -349,16 +351,10 @@ private:
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
inline Scheduler::Scheduler() : queue_(alloc_)
|
||||
inline Scheduler::Scheduler() : queue_(&alloc_)
|
||||
{
|
||||
}
|
||||
|
||||
inline qalloc const&
|
||||
Scheduler::alloc() const
|
||||
{
|
||||
return alloc_;
|
||||
}
|
||||
|
||||
inline auto
|
||||
Scheduler::clock() const -> clock_type&
|
||||
{
|
||||
|
||||
@@ -17,10 +17,12 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/basics/ByteUtilities.h>
|
||||
#include <ripple/beast/unit_test.h>
|
||||
#include <set>
|
||||
#include <test/csf/Scheduler.h>
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace ripple {
|
||||
namespace test {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user