handler_alloc_hook.ipp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // impl/handler_alloc_hook.ipp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
  11. #define BOOST_ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <boost/asio/detail/call_stack.hpp>
  17. #include <boost/asio/handler_alloc_hook.hpp>
  18. #if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  19. # if defined(BOOST_ASIO_HAS_IOCP)
  20. # include <boost/asio/detail/win_iocp_thread_info.hpp>
  21. # else // defined(BOOST_ASIO_HAS_IOCP)
  22. # include <boost/asio/detail/task_io_service_thread_info.hpp>
  23. # endif // defined(BOOST_ASIO_HAS_IOCP)
  24. #endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  25. #include <boost/asio/detail/push_options.hpp>
  26. namespace boost {
  27. namespace asio {
  28. #if defined(BOOST_ASIO_HAS_IOCP)
  29. namespace detail { class win_iocp_io_service; }
  30. #endif // defined(BOOST_ASIO_HAS_IOCP)
  31. void* asio_handler_allocate(std::size_t size, ...)
  32. {
  33. #if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  34. # if defined(BOOST_ASIO_HAS_IOCP)
  35. typedef detail::win_iocp_io_service io_service_impl;
  36. typedef detail::win_iocp_thread_info thread_info;
  37. # else // defined(BOOST_ASIO_HAS_IOCP)
  38. typedef detail::task_io_service io_service_impl;
  39. typedef detail::task_io_service_thread_info thread_info;
  40. # endif // defined(BOOST_ASIO_HAS_IOCP)
  41. typedef detail::call_stack<io_service_impl, thread_info> call_stack;
  42. return thread_info::allocate(call_stack::top(), size);
  43. #else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  44. return ::operator new(size);
  45. #endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  46. }
  47. void asio_handler_deallocate(void* pointer, std::size_t size, ...)
  48. {
  49. #if !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  50. # if defined(BOOST_ASIO_HAS_IOCP)
  51. typedef detail::win_iocp_io_service io_service_impl;
  52. typedef detail::win_iocp_thread_info thread_info;
  53. # else // defined(BOOST_ASIO_HAS_IOCP)
  54. typedef detail::task_io_service io_service_impl;
  55. typedef detail::task_io_service_thread_info thread_info;
  56. # endif // defined(BOOST_ASIO_HAS_IOCP)
  57. typedef detail::call_stack<io_service_impl, thread_info> call_stack;
  58. thread_info::deallocate(call_stack::top(), pointer, size);
  59. #else // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  60. (void)size;
  61. ::operator delete(pointer);
  62. #endif // !defined(BOOST_ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  63. }
  64. } // namespace asio
  65. } // namespace boost
  66. #include <boost/asio/detail/pop_options.hpp>
  67. #endif // BOOST_ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP