File indexing completed on 2025-07-11 08:05:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP
0012 #define BOOST_ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP
0013
0014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0015 # pragma once
0016 #endif
0017
0018 #include <boost/asio/detail/config.hpp>
0019 #include <boost/asio/detail/memory.hpp>
0020 #include <boost/asio/detail/recycling_allocator.hpp>
0021 #include <boost/asio/associated_allocator.hpp>
0022
0023 #include <boost/asio/detail/push_options.hpp>
0024
0025 #define BOOST_ASIO_DEFINE_TAGGED_HANDLER_PTR(purpose, op) \
0026 struct ptr \
0027 { \
0028 Handler* h; \
0029 op* v; \
0030 op* p; \
0031 ~ptr() \
0032 { \
0033 reset(); \
0034 } \
0035 static op* allocate(Handler& handler) \
0036 { \
0037 typedef typename ::boost::asio::associated_allocator< \
0038 Handler>::type associated_allocator_type; \
0039 typedef typename ::boost::asio::detail::get_recycling_allocator< \
0040 associated_allocator_type, purpose>::type default_allocator_type; \
0041 BOOST_ASIO_REBIND_ALLOC(default_allocator_type, op) a( \
0042 ::boost::asio::detail::get_recycling_allocator< \
0043 associated_allocator_type, purpose>::get( \
0044 ::boost::asio::get_associated_allocator(handler))); \
0045 return a.allocate(1); \
0046 } \
0047 void reset() \
0048 { \
0049 if (p) \
0050 { \
0051 p->~op(); \
0052 p = 0; \
0053 } \
0054 if (v) \
0055 { \
0056 typedef typename ::boost::asio::associated_allocator< \
0057 Handler>::type associated_allocator_type; \
0058 typedef typename ::boost::asio::detail::get_recycling_allocator< \
0059 associated_allocator_type, purpose>::type default_allocator_type; \
0060 BOOST_ASIO_REBIND_ALLOC(default_allocator_type, op) a( \
0061 ::boost::asio::detail::get_recycling_allocator< \
0062 associated_allocator_type, purpose>::get( \
0063 ::boost::asio::get_associated_allocator(*h))); \
0064 a.deallocate(static_cast<op*>(v), 1); \
0065 v = 0; \
0066 } \
0067 } \
0068 } \
0069
0070
0071 #define BOOST_ASIO_DEFINE_HANDLER_PTR(op) \
0072 BOOST_ASIO_DEFINE_TAGGED_HANDLER_PTR( \
0073 ::boost::asio::detail::thread_info_base::default_tag, op ) \
0074
0075
0076 #define BOOST_ASIO_DEFINE_TAGGED_HANDLER_ALLOCATOR_PTR(purpose, op) \
0077 struct ptr \
0078 { \
0079 const Alloc* a; \
0080 void* v; \
0081 op* p; \
0082 ~ptr() \
0083 { \
0084 reset(); \
0085 } \
0086 static op* allocate(const Alloc& a) \
0087 { \
0088 typedef typename ::boost::asio::detail::get_recycling_allocator< \
0089 Alloc, purpose>::type recycling_allocator_type; \
0090 BOOST_ASIO_REBIND_ALLOC(recycling_allocator_type, op) a1( \
0091 ::boost::asio::detail::get_recycling_allocator< \
0092 Alloc, purpose>::get(a)); \
0093 return a1.allocate(1); \
0094 } \
0095 void reset() \
0096 { \
0097 if (p) \
0098 { \
0099 p->~op(); \
0100 p = 0; \
0101 } \
0102 if (v) \
0103 { \
0104 typedef typename ::boost::asio::detail::get_recycling_allocator< \
0105 Alloc, purpose>::type recycling_allocator_type; \
0106 BOOST_ASIO_REBIND_ALLOC(recycling_allocator_type, op) a1( \
0107 ::boost::asio::detail::get_recycling_allocator< \
0108 Alloc, purpose>::get(*a)); \
0109 a1.deallocate(static_cast<op*>(v), 1); \
0110 v = 0; \
0111 } \
0112 } \
0113 } \
0114
0115
0116 #define BOOST_ASIO_DEFINE_HANDLER_ALLOCATOR_PTR(op) \
0117 BOOST_ASIO_DEFINE_TAGGED_HANDLER_ALLOCATOR_PTR( \
0118 ::boost::asio::detail::thread_info_base::default_tag, op ) \
0119
0120
0121 #include <boost/asio/detail/pop_options.hpp>
0122
0123 #endif