diff options
Diffstat (limited to 'src/common/async/completion.h')
-rw-r--r-- | src/common/async/completion.h | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/common/async/completion.h b/src/common/async/completion.h index d8065934e01..6cdfaaa63b7 100644 --- a/src/common/async/completion.h +++ b/src/common/async/completion.h @@ -21,6 +21,7 @@ #include <boost/asio/defer.hpp> #include <boost/asio/dispatch.hpp> #include <boost/asio/executor_work_guard.hpp> +#include <boost/asio/recycling_allocator.hpp> #include <boost/asio/post.hpp> #include "bind_handler.h" @@ -173,7 +174,8 @@ class CompletionImpl final : public Completion<void(Args...), T> { Handler handler; // use Handler's associated allocator - using Alloc2 = boost::asio::associated_allocator_t<Handler>; + using DefaultAlloc = boost::asio::recycling_allocator<void>; + using Alloc2 = boost::asio::associated_allocator_t<Handler, DefaultAlloc>; using Traits2 = std::allocator_traits<Alloc2>; using RebindAlloc2 = typename Traits2::template rebind_alloc<CompletionImpl>; using RebindTraits2 = std::allocator_traits<RebindAlloc2>; @@ -196,16 +198,16 @@ class CompletionImpl final : public Completion<void(Args...), T> { void destroy_defer(std::tuple<Args...>&& args) override { auto w = std::move(work); auto ex2 = w.second.get_executor(); - RebindAlloc2 alloc2 = boost::asio::get_associated_allocator(handler); + RebindAlloc2 alloc2 = boost::asio::get_associated_allocator(handler, DefaultAlloc{}); auto f = bind_and_forward(ex2, std::move(handler), std::move(args)); RebindTraits2::destroy(alloc2, this); RebindTraits2::deallocate(alloc2, this, 1); - boost::asio::defer(boost::asio::bind_executor(ex2, std::move(f))); + boost::asio::defer(std::move(f)); } void destroy_dispatch(std::tuple<Args...>&& args) override { auto w = std::move(work); auto ex2 = w.second.get_executor(); - RebindAlloc2 alloc2 = boost::asio::get_associated_allocator(handler); + RebindAlloc2 alloc2 = boost::asio::get_associated_allocator(handler, DefaultAlloc{}); auto f = bind_and_forward(ex2, std::move(handler), std::move(args)); RebindTraits2::destroy(alloc2, this); RebindTraits2::deallocate(alloc2, this, 1); @@ -214,14 +216,14 @@ class CompletionImpl final : public Completion<void(Args...), T> { void destroy_post(std::tuple<Args...>&& args) override { auto w = std::move(work); auto ex2 = w.second.get_executor(); - RebindAlloc2 alloc2 = boost::asio::get_associated_allocator(handler); + RebindAlloc2 alloc2 = boost::asio::get_associated_allocator(handler, DefaultAlloc{}); auto f = bind_and_forward(ex2, std::move(handler), std::move(args)); RebindTraits2::destroy(alloc2, this); RebindTraits2::deallocate(alloc2, this, 1); boost::asio::post(std::move(f)); } void destroy() override { - RebindAlloc2 alloc2 = boost::asio::get_associated_allocator(handler); + RebindAlloc2 alloc2 = boost::asio::get_associated_allocator(handler, DefaultAlloc{}); RebindTraits2::destroy(alloc2, this); RebindTraits2::deallocate(alloc2, this, 1); } @@ -238,7 +240,7 @@ class CompletionImpl final : public Completion<void(Args...), T> { public: template <typename ...TArgs> static auto create(const Executor1& ex, Handler&& handler, TArgs&& ...args) { - auto alloc2 = boost::asio::get_associated_allocator(handler); + auto alloc2 = boost::asio::get_associated_allocator(handler, DefaultAlloc{}); using Ptr = std::unique_ptr<CompletionImpl>; return Ptr{new (alloc2) CompletionImpl(ex, std::move(handler), std::forward<TArgs>(args)...)}; |