summaryrefslogtreecommitdiff
path: root/boost/asio/detail/thread_info_base.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/asio/detail/thread_info_base.hpp')
-rw-r--r--boost/asio/detail/thread_info_base.hpp49
1 files changed, 38 insertions, 11 deletions
diff --git a/boost/asio/detail/thread_info_base.hpp b/boost/asio/detail/thread_info_base.hpp
index c0dc322f41..16bb1787f3 100644
--- a/boost/asio/detail/thread_info_base.hpp
+++ b/boost/asio/detail/thread_info_base.hpp
@@ -2,7 +2,7 @@
// detail/thread_info_base.hpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
-// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
+// Copyright (c) 2003-2018 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -29,25 +29,50 @@ class thread_info_base
: private noncopyable
{
public:
+ struct default_tag
+ {
+ enum { mem_index = 0 };
+ };
+
+ struct awaitee_tag
+ {
+ enum { mem_index = 1 };
+ };
+
thread_info_base()
- : reusable_memory_(0)
{
+ for (int i = 0; i < max_mem_index; ++i)
+ reusable_memory_[i] = 0;
}
~thread_info_base()
{
- if (reusable_memory_)
- ::operator delete(reusable_memory_);
+ for (int i = 0; i < max_mem_index; ++i)
+ if (reusable_memory_[i])
+ ::operator delete(reusable_memory_[i]);
}
static void* allocate(thread_info_base* this_thread, std::size_t size)
{
+ return allocate(default_tag(), this_thread, size);
+ }
+
+ static void deallocate(thread_info_base* this_thread,
+ void* pointer, std::size_t size)
+ {
+ deallocate(default_tag(), this_thread, pointer, size);
+ }
+
+ template <typename Purpose>
+ static void* allocate(Purpose, thread_info_base* this_thread,
+ std::size_t size)
+ {
std::size_t chunks = (size + chunk_size - 1) / chunk_size;
- if (this_thread && this_thread->reusable_memory_)
+ if (this_thread && this_thread->reusable_memory_[Purpose::mem_index])
{
- void* const pointer = this_thread->reusable_memory_;
- this_thread->reusable_memory_ = 0;
+ void* const pointer = this_thread->reusable_memory_[Purpose::mem_index];
+ this_thread->reusable_memory_[Purpose::mem_index] = 0;
unsigned char* const mem = static_cast<unsigned char*>(pointer);
if (static_cast<std::size_t>(mem[0]) >= chunks)
@@ -65,16 +90,17 @@ public:
return pointer;
}
- static void deallocate(thread_info_base* this_thread,
+ template <typename Purpose>
+ static void deallocate(Purpose, thread_info_base* this_thread,
void* pointer, std::size_t size)
{
if (size <= chunk_size * UCHAR_MAX)
{
- if (this_thread && this_thread->reusable_memory_ == 0)
+ if (this_thread && this_thread->reusable_memory_[Purpose::mem_index] == 0)
{
unsigned char* const mem = static_cast<unsigned char*>(pointer);
mem[0] = mem[size];
- this_thread->reusable_memory_ = pointer;
+ this_thread->reusable_memory_[Purpose::mem_index] = pointer;
return;
}
}
@@ -84,7 +110,8 @@ public:
private:
enum { chunk_size = 4 };
- void* reusable_memory_;
+ enum { max_mem_index = 2 };
+ void* reusable_memory_[max_mem_index];
};
} // namespace detail