summaryrefslogtreecommitdiff
path: root/src/third_party/asio-master/asio/include/asio/detail/handler_alloc_helpers.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/third_party/asio-master/asio/include/asio/detail/handler_alloc_helpers.hpp')
-rw-r--r--src/third_party/asio-master/asio/include/asio/detail/handler_alloc_helpers.hpp70
1 files changed, 55 insertions, 15 deletions
diff --git a/src/third_party/asio-master/asio/include/asio/detail/handler_alloc_helpers.hpp b/src/third_party/asio-master/asio/include/asio/detail/handler_alloc_helpers.hpp
index 861f5d45c7b..3b72e33345a 100644
--- a/src/third_party/asio-master/asio/include/asio/detail/handler_alloc_helpers.hpp
+++ b/src/third_party/asio-master/asio/include/asio/detail/handler_alloc_helpers.hpp
@@ -2,7 +2,7 @@
// detail/handler_alloc_helpers.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -18,6 +18,7 @@
#include "asio/detail/config.hpp"
#include "asio/detail/memory.hpp"
#include "asio/detail/noncopyable.hpp"
+#include "asio/detail/recycling_allocator.hpp"
#include "asio/associated_allocator.hpp"
#include "asio/handler_alloc_hook.hpp"
@@ -120,17 +121,34 @@ public:
Handler& handler_;
};
+template <typename Handler, typename Allocator>
+struct get_hook_allocator
+{
+ typedef Allocator type;
+
+ static type get(Handler&, const Allocator& a)
+ {
+ return a;
+ }
+};
+
+template <typename Handler, typename T>
+struct get_hook_allocator<Handler, std::allocator<T> >
+{
+ typedef hook_allocator<Handler, T> type;
+
+ static type get(Handler& handler, const std::allocator<T>&)
+ {
+ return type(handler);
+ }
+};
+
} // namespace detail
} // namespace asio
#define ASIO_DEFINE_HANDLER_PTR(op) \
struct ptr \
{ \
- typedef typename ::asio::associated_allocator<Handler, \
- ::asio::detail::hook_allocator<Handler, \
- void> >::type associated_allocator_type; \
- typedef ASIO_REBIND_ALLOC( \
- associated_allocator_type, op) allocator_type; \
Handler* h; \
op* v; \
op* p; \
@@ -140,16 +158,26 @@ public:
} \
static op* allocate(Handler& handler) \
{ \
- allocator_type a(::asio::associated_allocator<Handler, \
- ::asio::detail::hook_allocator<Handler, void> >::get(handler, \
- ::asio::detail::hook_allocator<Handler, void>(handler))); \
+ typedef typename ::asio::associated_allocator< \
+ Handler>::type associated_allocator_type; \
+ typedef typename ::asio::detail::get_hook_allocator< \
+ Handler, associated_allocator_type>::type hook_allocator_type; \
+ ASIO_REBIND_ALLOC(hook_allocator_type, op) a( \
+ ::asio::detail::get_hook_allocator< \
+ Handler, associated_allocator_type>::get( \
+ handler, ::asio::get_associated_allocator(handler))); \
return a.allocate(1); \
} \
void reset() \
{ \
- allocator_type a(::asio::associated_allocator<Handler, \
- ::asio::detail::hook_allocator<Handler, void> >::get(*h, \
- ::asio::detail::hook_allocator<Handler, void>(*h))); \
+ typedef typename ::asio::associated_allocator< \
+ Handler>::type associated_allocator_type; \
+ typedef typename ::asio::detail::get_hook_allocator< \
+ Handler, associated_allocator_type>::type hook_allocator_type; \
+ ASIO_REBIND_ALLOC(hook_allocator_type, op) a( \
+ ::asio::detail::get_hook_allocator< \
+ Handler, associated_allocator_type>::get( \
+ *h, ::asio::get_associated_allocator(*h))); \
if (p) \
{ \
p->~op(); \
@@ -164,18 +192,30 @@ public:
} \
/**/
-#define ASIO_DEFINE_HANDLER_ALLOCATOR_PTR(op, alloc) \
+#define ASIO_DEFINE_HANDLER_ALLOCATOR_PTR(op) \
struct ptr \
{ \
- ASIO_REBIND_ALLOC(alloc, op) a; \
+ const Alloc* a; \
void* v; \
op* p; \
~ptr() \
{ \
reset(); \
} \
+ static op* allocate(const Alloc& a) \
+ { \
+ typedef typename ::asio::detail::get_recycling_allocator< \
+ Alloc>::type recycling_allocator_type; \
+ ASIO_REBIND_ALLOC(recycling_allocator_type, op) a1( \
+ ::asio::detail::get_recycling_allocator<Alloc>::get(a)); \
+ return a1.allocate(1); \
+ } \
void reset() \
{ \
+ typedef typename ::asio::detail::get_recycling_allocator< \
+ Alloc>::type recycling_allocator_type; \
+ ASIO_REBIND_ALLOC(recycling_allocator_type, op) a1( \
+ ::asio::detail::get_recycling_allocator<Alloc>::get(*a)); \
if (p) \
{ \
p->~op(); \
@@ -183,7 +223,7 @@ public:
} \
if (v) \
{ \
- a.deallocate(static_cast<op*>(v), 1); \
+ a1.deallocate(static_cast<op*>(v), 1); \
v = 0; \
} \
} \