]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/asio/detail/recycling_allocator.hpp
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / boost / asio / detail / recycling_allocator.hpp
CommitLineData
b32b8144
FG
1//
2// detail/recycling_allocator.hpp
3// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4//
f67539c2 5// Copyright (c) 2003-2020 Christopher M. Kohlhoff (chris at kohlhoff dot com)
b32b8144
FG
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 BOOST_ASIO_DETAIL_RECYCLING_ALLOCATOR_HPP
12#define BOOST_ASIO_DETAIL_RECYCLING_ALLOCATOR_HPP
13
14#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15# pragma once
16#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
18#include <boost/asio/detail/config.hpp>
19#include <boost/asio/detail/memory.hpp>
20#include <boost/asio/detail/thread_context.hpp>
21#include <boost/asio/detail/thread_info_base.hpp>
22
23#include <boost/asio/detail/push_options.hpp>
24
25namespace boost {
26namespace asio {
27namespace detail {
28
92f5a8d4 29template <typename T, typename Purpose = thread_info_base::default_tag>
b32b8144
FG
30class recycling_allocator
31{
32public:
33 typedef T value_type;
34
35 template <typename U>
36 struct rebind
37 {
92f5a8d4 38 typedef recycling_allocator<U, Purpose> other;
b32b8144
FG
39 };
40
41 recycling_allocator()
42 {
43 }
44
45 template <typename U>
92f5a8d4 46 recycling_allocator(const recycling_allocator<U, Purpose>&)
b32b8144
FG
47 {
48 }
49
50 T* allocate(std::size_t n)
51 {
52 typedef thread_context::thread_call_stack call_stack;
92f5a8d4
TL
53 void* p = thread_info_base::allocate(Purpose(),
54 call_stack::top(), sizeof(T) * n);
b32b8144
FG
55 return static_cast<T*>(p);
56 }
57
58 void deallocate(T* p, std::size_t n)
59 {
60 typedef thread_context::thread_call_stack call_stack;
92f5a8d4
TL
61 thread_info_base::deallocate(Purpose(),
62 call_stack::top(), p, sizeof(T) * n);
b32b8144
FG
63 }
64};
65
92f5a8d4
TL
66template <typename Purpose>
67class recycling_allocator<void, Purpose>
b32b8144
FG
68{
69public:
70 typedef void value_type;
71
72 template <typename U>
73 struct rebind
74 {
92f5a8d4 75 typedef recycling_allocator<U, Purpose> other;
b32b8144
FG
76 };
77
78 recycling_allocator()
79 {
80 }
81
82 template <typename U>
92f5a8d4 83 recycling_allocator(const recycling_allocator<U, Purpose>&)
b32b8144
FG
84 {
85 }
86};
87
92f5a8d4 88template <typename Allocator, typename Purpose>
b32b8144
FG
89struct get_recycling_allocator
90{
91 typedef Allocator type;
92 static type get(const Allocator& a) { return a; }
93};
94
92f5a8d4
TL
95template <typename T, typename Purpose>
96struct get_recycling_allocator<std::allocator<T>, Purpose>
b32b8144 97{
92f5a8d4 98 typedef recycling_allocator<T, Purpose> type;
b32b8144
FG
99 static type get(const std::allocator<T>&) { return type(); }
100};
101
102} // namespace detail
103} // namespace asio
104} // namespace boost
105
106#include <boost/asio/detail/pop_options.hpp>
107
108#endif // BOOST_ASIO_DETAIL_RECYCLING_ALLOCATOR_HPP