2 // detail/thread_info_base.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
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)
11 #ifndef BOOST_ASIO_DETAIL_THREAD_INFO_BASE_HPP
12 #define BOOST_ASIO_DETAIL_THREAD_INFO_BASE_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
20 #include <boost/asio/detail/noncopyable.hpp>
22 #include <boost/asio/detail/push_options.hpp>
28 class thread_info_base
40 ::operator delete(reusable_memory_);
43 static void* allocate(thread_info_base* this_thread, std::size_t size)
45 if (this_thread && this_thread->reusable_memory_)
47 void* const pointer = this_thread->reusable_memory_;
48 this_thread->reusable_memory_ = 0;
50 unsigned char* const mem = static_cast<unsigned char*>(pointer);
51 if (static_cast<std::size_t>(mem[0]) >= size)
57 ::operator delete(pointer);
60 void* const pointer = ::operator new(size + 1);
61 unsigned char* const mem = static_cast<unsigned char*>(pointer);
62 mem[size] = (size <= UCHAR_MAX) ? static_cast<unsigned char>(size) : 0;
66 static void deallocate(thread_info_base* this_thread,
67 void* pointer, std::size_t size)
69 if (size <= UCHAR_MAX)
71 if (this_thread && this_thread->reusable_memory_ == 0)
73 unsigned char* const mem = static_cast<unsigned char*>(pointer);
75 this_thread->reusable_memory_ = pointer;
80 ::operator delete(pointer);
84 void* reusable_memory_;
91 #include <boost/asio/detail/pop_options.hpp>
93 #endif // BOOST_ASIO_DETAIL_THREAD_INFO_BASE_HPP