2#include <boost/asio.hpp>
10 static constexpr int lowest = std::numeric_limits<int>::min();
11 static constexpr int low = 10;
15 static constexpr int high = 100;
16 static constexpr int highest = std::numeric_limits<int>::max();
23 template <
typename Function>
26 std::unique_ptr<queued_handler_base> handler(
new queued_handler<Function>(
priority, --order_, std::move(function)));
28 handlers_.push(std::move(handler));
33 while (!handlers_.empty()) {
34 handlers_.top()->execute();
41 if( !handlers_.empty() ) {
42 handlers_.top()->execute();
46 return !handlers_.empty();
49 size_t size() {
return handlers_.size(); }
55 : context_(q), priority_(
p)
64 template <
typename Function,
typename Allocator>
67 context_.
add(priority_, std::move(
f));
70 template <
typename Function,
typename Allocator>
73 context_.
add(priority_, std::move(
f));
76 template <
typename Function,
typename Allocator>
79 context_.
add(priority_, std::move(
f));
87 return &context_ == &other.context_ && priority_ == other.priority_;
100 template <
typename Function>
101 boost::asio::executor_binder<Function, executor>
104 return boost::asio::bind_executor(
executor(*
this,
priority), std::forward<Function>(func) );
108 class queued_handler_base
111 queued_handler_base(
int p,
size_t order )
117 virtual ~queued_handler_base() =
default;
119 virtual void execute() = 0;
121 int priority()
const {
return priority_; }
125 friend bool operator<(
const queued_handler_base&
a,
126 const queued_handler_base& b)
noexcept
128 return std::tie(
a.priority_,
a.order_ ) < std::tie( b.priority_, b.order_ );
136 template <
typename Function>
137 class queued_handler :
public queued_handler_base
140 queued_handler(
int p,
size_t order, Function
f)
141 : queued_handler_base(
p, order )
142 , function_(
std::move(
f) )
146 void execute()
override
157 template<
typename Po
inter>
158 bool operator()(
const Pointer&
a,
const Pointer& b)
noexcept(
noexcept(*
a < *b))
164 std::priority_queue<std::unique_ptr<queued_handler_base>, std::deque<std::unique_ptr<queued_handler_base>>, deref_less> handlers_;
165 std::size_t order_ = std::numeric_limits<size_t>::max();
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
bool operator!=(const executor &other) const noexcept
execution_priority_queue & context() const noexcept
bool operator==(const executor &other) const noexcept
void on_work_started() const noexcept
void post(Function f, const Allocator &) const
executor(execution_priority_queue &q, int p)
void dispatch(Function f, const Allocator &) const
void on_work_finished() const noexcept
void defer(Function f, const Allocator &) const
void add(int priority, Function function)
boost::asio::executor_binder< Function, executor > wrap(int priority, Function &&func)
Concept for allocating, resizing and freeing memory block.
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
static constexpr int medium_high
static constexpr int lowest
static constexpr int medium
static constexpr int medium_low
static constexpr int high
static constexpr int highest