handler_alloc_hook.ipp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // impl/handler_alloc_hook.ipp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2015 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 ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP
  11. #define 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 "asio/detail/config.hpp"
  16. #include "asio/detail/call_stack.hpp"
  17. #include "asio/handler_alloc_hook.hpp"
  18. #if !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  19. # if defined(ASIO_HAS_IOCP)
  20. # include "asio/detail/win_iocp_thread_info.hpp"
  21. # else // defined(ASIO_HAS_IOCP)
  22. # include "asio/detail/task_io_service_thread_info.hpp"
  23. # endif // defined(ASIO_HAS_IOCP)
  24. #endif // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  25. #include "asio/detail/push_options.hpp"
  26. namespace asio {
  27. #if defined(ASIO_HAS_IOCP)
  28. namespace detail { class win_iocp_io_service; }
  29. #endif // defined(ASIO_HAS_IOCP)
  30. void* asio_handler_allocate(std::size_t size, ...)
  31. {
  32. #if !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  33. # if defined(ASIO_HAS_IOCP)
  34. typedef detail::win_iocp_io_service io_service_impl;
  35. typedef detail::win_iocp_thread_info thread_info;
  36. # else // defined(ASIO_HAS_IOCP)
  37. typedef detail::task_io_service io_service_impl;
  38. typedef detail::task_io_service_thread_info thread_info;
  39. # endif // defined(ASIO_HAS_IOCP)
  40. typedef detail::call_stack<io_service_impl, thread_info> call_stack;
  41. return thread_info::allocate(call_stack::top(), size);
  42. #else // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  43. return ::operator new(size);
  44. #endif // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  45. }
  46. void asio_handler_deallocate(void* pointer, std::size_t size, ...)
  47. {
  48. #if !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  49. # if defined(ASIO_HAS_IOCP)
  50. typedef detail::win_iocp_io_service io_service_impl;
  51. typedef detail::win_iocp_thread_info thread_info;
  52. # else // defined(ASIO_HAS_IOCP)
  53. typedef detail::task_io_service io_service_impl;
  54. typedef detail::task_io_service_thread_info thread_info;
  55. # endif // defined(ASIO_HAS_IOCP)
  56. typedef detail::call_stack<io_service_impl, thread_info> call_stack;
  57. thread_info::deallocate(call_stack::top(), pointer, size);
  58. #else // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  59. (void)size;
  60. ::operator delete(pointer);
  61. #endif // !defined(ASIO_DISABLE_SMALL_BLOCK_RECYCLING)
  62. }
  63. } // namespace asio
  64. #include "asio/detail/pop_options.hpp"
  65. #endif // ASIO_IMPL_HANDLER_ALLOC_HOOK_IPP