Realistic 3D camera system
3D camera system components
thread_info_base.hpp
Go to the documentation of this file.
1 //
2 // detail/thread_info_base.hpp
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 
11 #ifndef ASIO_DETAIL_THREAD_INFO_BASE_HPP
12 #define ASIO_DETAIL_THREAD_INFO_BASE_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include <climits>
19 #include <cstddef>
21 
23 
24 namespace asio {
25 namespace detail {
26 
28  : private noncopyable
29 {
30 public:
32  : reusable_memory_(0)
33  {
34  }
35 
37  {
38  if (reusable_memory_)
39  ::operator delete(reusable_memory_);
40  }
41 
42  static void* allocate(thread_info_base* this_thread, std::size_t size)
43  {
44  if (this_thread && this_thread->reusable_memory_)
45  {
46  void* const pointer = this_thread->reusable_memory_;
47  this_thread->reusable_memory_ = 0;
48 
49  unsigned char* const mem = static_cast<unsigned char*>(pointer);
50  if (static_cast<std::size_t>(mem[0]) >= size)
51  {
52  mem[size] = mem[0];
53  return pointer;
54  }
55 
56  ::operator delete(pointer);
57  }
58 
59  void* const pointer = ::operator new(size + 1);
60  unsigned char* const mem = static_cast<unsigned char*>(pointer);
61  mem[size] = (size <= UCHAR_MAX) ? static_cast<unsigned char>(size) : 0;
62  return pointer;
63  }
64 
65  static void deallocate(thread_info_base* this_thread,
66  void* pointer, std::size_t size)
67  {
68  if (size <= UCHAR_MAX)
69  {
70  if (this_thread && this_thread->reusable_memory_ == 0)
71  {
72  unsigned char* const mem = static_cast<unsigned char*>(pointer);
73  mem[0] = mem[size];
74  this_thread->reusable_memory_ = pointer;
75  return;
76  }
77  }
78 
79  ::operator delete(pointer);
80  }
81 
82 private:
83  void* reusable_memory_;
84 };
85 
86 } // namespace detail
87 } // namespace asio
88 
90 
91 #endif // ASIO_DETAIL_THREAD_INFO_BASE_HPP
static void deallocate(thread_info_base *this_thread, void *pointer, std::size_t size)
static void * allocate(thread_info_base *this_thread, std::size_t size)