11 #ifndef ASIO_DETAIL_THREAD_INFO_BASE_HPP 12 #define ASIO_DETAIL_THREAD_INFO_BASE_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 18 #include "asio/detail/config.hpp" 21 #include "asio/detail/noncopyable.hpp" 23 #if defined(ASIO_HAS_STD_EXCEPTION_PTR) \ 24 && !defined(ASIO_NO_EXCEPTIONS) 26 # include "asio/multiple_exceptions.hpp" 27 #endif // defined(ASIO_HAS_STD_EXCEPTION_PTR) 30 #include "asio/detail/push_options.hpp" 41 enum { mem_index = 0 };
46 enum { mem_index = 1 };
51 enum { mem_index = 2 };
55 #if defined(ASIO_HAS_STD_EXCEPTION_PTR) \ 56 && !defined(ASIO_NO_EXCEPTIONS) 57 : has_pending_exception_(0)
58 #endif // defined(ASIO_HAS_STD_EXCEPTION_PTR) 61 for (
int i = 0; i < max_mem_index; ++i)
62 reusable_memory_[i] = 0;
67 for (
int i = 0; i < max_mem_index; ++i)
72 if (reusable_memory_[i])
73 ::operator
delete(reusable_memory_[i]);
83 void* pointer, std::size_t size)
85 deallocate(
default_tag(), this_thread, pointer, size);
88 template <
typename Purpose>
92 std::size_t chunks = (size + chunk_size - 1) / chunk_size;
94 if (this_thread && this_thread->reusable_memory_[Purpose::mem_index])
96 void*
const pointer = this_thread->reusable_memory_[Purpose::mem_index];
97 this_thread->reusable_memory_[Purpose::mem_index] = 0;
99 unsigned char*
const mem =
static_cast<unsigned char*
>(pointer);
100 if (static_cast<std::size_t>(mem[0]) >= chunks)
106 ::operator
delete(pointer);
109 void*
const pointer = ::operator
new(chunks * chunk_size + 1);
110 unsigned char*
const mem =
static_cast<unsigned char*
>(pointer);
111 mem[size] = (chunks <= UCHAR_MAX) ? static_cast<unsigned char>(chunks) : 0;
115 template <
typename Purpose>
117 void* pointer, std::size_t size)
119 if (size <= chunk_size * UCHAR_MAX)
121 if (this_thread && this_thread->reusable_memory_[Purpose::mem_index] == 0)
123 unsigned char*
const mem =
static_cast<unsigned char*
>(pointer);
125 this_thread->reusable_memory_[Purpose::mem_index] = pointer;
130 ::operator
delete(pointer);
133 void capture_current_exception()
135 #if defined(ASIO_HAS_STD_EXCEPTION_PTR) \ 136 && !defined(ASIO_NO_EXCEPTIONS) 137 switch (has_pending_exception_)
140 has_pending_exception_ = 1;
141 pending_exception_ = std::current_exception();
144 has_pending_exception_ = 2;
146 std::make_exception_ptr<multiple_exceptions>(
147 multiple_exceptions(pending_exception_));
152 #endif // defined(ASIO_HAS_STD_EXCEPTION_PTR) 156 void rethrow_pending_exception()
158 #if defined(ASIO_HAS_STD_EXCEPTION_PTR) \ 159 && !defined(ASIO_NO_EXCEPTIONS) 160 if (has_pending_exception_ > 0)
162 has_pending_exception_ = 0;
163 std::exception_ptr ex(
164 ASIO_MOVE_CAST(std::exception_ptr)(
165 pending_exception_));
166 std::rethrow_exception(ex);
168 #endif // defined(ASIO_HAS_STD_EXCEPTION_PTR) 173 enum { chunk_size = 4 };
174 enum { max_mem_index = 3 };
175 void* reusable_memory_[max_mem_index];
177 #if defined(ASIO_HAS_STD_EXCEPTION_PTR) \ 178 && !defined(ASIO_NO_EXCEPTIONS) 179 int has_pending_exception_;
180 std::exception_ptr pending_exception_;
181 #endif // defined(ASIO_HAS_STD_EXCEPTION_PTR) 188 #include "asio/detail/pop_options.hpp" 190 #endif // ASIO_DETAIL_THREAD_INFO_BASE_HPP Definition: noncopyable.hpp:25
Definition: thread_info_base.hpp:49
Definition: thread_info_base.hpp:35
Definition: any_io_executor.hpp:28
Definition: thread_info_base.hpp:44
Definition: thread_info_base.hpp:39