annotate DEPENDENCIES/generic/include/boost/asio/detail/handler_alloc_helpers.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //
Chris@16 2 // detail/handler_alloc_helpers.hpp
Chris@16 3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Chris@16 4 //
Chris@101 5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
Chris@16 6 //
Chris@16 7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 9 //
Chris@16 10
Chris@16 11 #ifndef BOOST_ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP
Chris@16 12 #define BOOST_ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP
Chris@16 13
Chris@16 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 15 # pragma once
Chris@16 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
Chris@16 17
Chris@16 18 #include <boost/asio/detail/config.hpp>
Chris@16 19 #include <boost/asio/detail/addressof.hpp>
Chris@16 20 #include <boost/asio/detail/noncopyable.hpp>
Chris@16 21 #include <boost/asio/handler_alloc_hook.hpp>
Chris@16 22
Chris@16 23 #include <boost/asio/detail/push_options.hpp>
Chris@16 24
Chris@16 25 // Calls to asio_handler_allocate and asio_handler_deallocate must be made from
Chris@16 26 // a namespace that does not contain any overloads of these functions. The
Chris@16 27 // boost_asio_handler_alloc_helpers namespace is defined here for that purpose.
Chris@16 28 namespace boost_asio_handler_alloc_helpers {
Chris@16 29
Chris@16 30 template <typename Handler>
Chris@16 31 inline void* allocate(std::size_t s, Handler& h)
Chris@16 32 {
Chris@16 33 #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
Chris@16 34 return ::operator new(s);
Chris@16 35 #else
Chris@16 36 using boost::asio::asio_handler_allocate;
Chris@16 37 return asio_handler_allocate(s, boost::asio::detail::addressof(h));
Chris@16 38 #endif
Chris@16 39 }
Chris@16 40
Chris@16 41 template <typename Handler>
Chris@16 42 inline void deallocate(void* p, std::size_t s, Handler& h)
Chris@16 43 {
Chris@16 44 #if !defined(BOOST_ASIO_HAS_HANDLER_HOOKS)
Chris@16 45 ::operator delete(p);
Chris@16 46 #else
Chris@16 47 using boost::asio::asio_handler_deallocate;
Chris@16 48 asio_handler_deallocate(p, s, boost::asio::detail::addressof(h));
Chris@16 49 #endif
Chris@16 50 }
Chris@16 51
Chris@16 52 } // namespace boost_asio_handler_alloc_helpers
Chris@16 53
Chris@16 54 #define BOOST_ASIO_DEFINE_HANDLER_PTR(op) \
Chris@16 55 struct ptr \
Chris@16 56 { \
Chris@16 57 Handler* h; \
Chris@16 58 void* v; \
Chris@16 59 op* p; \
Chris@16 60 ~ptr() \
Chris@16 61 { \
Chris@16 62 reset(); \
Chris@16 63 } \
Chris@16 64 void reset() \
Chris@16 65 { \
Chris@16 66 if (p) \
Chris@16 67 { \
Chris@16 68 p->~op(); \
Chris@16 69 p = 0; \
Chris@16 70 } \
Chris@16 71 if (v) \
Chris@16 72 { \
Chris@16 73 boost_asio_handler_alloc_helpers::deallocate(v, sizeof(op), *h); \
Chris@16 74 v = 0; \
Chris@16 75 } \
Chris@16 76 } \
Chris@16 77 } \
Chris@16 78 /**/
Chris@16 79
Chris@16 80 #include <boost/asio/detail/pop_options.hpp>
Chris@16 81
Chris@16 82 #endif // BOOST_ASIO_DETAIL_HANDLER_ALLOC_HELPERS_HPP