]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/container/include/boost/container/detail/block_list.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / container / include / boost / container / detail / block_list.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2015-2015. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/container for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10
11 #ifndef BOOST_CONTAINER_DETAIL_BLOCK_LIST_HEADER
12 #define BOOST_CONTAINER_DETAIL_BLOCK_LIST_HEADER
13
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
16 #endif
17
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
19 # pragma once
20 #endif
21
22 #include <boost/container/detail/config_begin.hpp>
23 #include <boost/container/detail/workaround.hpp>
24 #include <boost/container/container_fwd.hpp>
25 #include <boost/container/pmr/memory_resource.hpp>
26 #include <boost/container/throw_exception.hpp>
27 #include <boost/intrusive/circular_list_algorithms.hpp>
28 #include <boost/move/detail/type_traits.hpp>
29 #include <boost/assert.hpp>
30
31 #include <cstddef>
32
33 namespace boost {
34 namespace container {
35 namespace pmr {
36
37 struct list_node
38 {
39 list_node *next;
40 list_node *previous;
41 };
42
43 struct list_node_traits
44 {
45 typedef list_node node;
46 typedef list_node* node_ptr;
47 typedef const list_node* const_node_ptr;
48
49 static node_ptr get_next(const_node_ptr n)
50 { return n->next; }
51
52 static node_ptr get_previous(const_node_ptr n)
53 { return n->previous; }
54
55 static void set_next(const node_ptr & n, const node_ptr & next)
56 { n->next = next; }
57
58 static void set_previous(const node_ptr & n, const node_ptr & previous)
59 { n->previous = previous; }
60 };
61
62 struct block_list_header
63 : public list_node
64 {
65 std::size_t size;
66 };
67
68 typedef bi::circular_list_algorithms<list_node_traits> list_algo;
69
70
71 template<class DerivedFromBlockListHeader = block_list_header>
72 class block_list_base
73 {
74 list_node m_list;
75
76 static const std::size_t MaxAlignMinus1 = memory_resource::max_align-1u;
77
78 public:
79
80 static const std::size_t header_size = std::size_t(sizeof(DerivedFromBlockListHeader) + MaxAlignMinus1) & std::size_t(~MaxAlignMinus1);
81
82 explicit block_list_base()
83 { list_algo::init_header(&m_list); }
84
85 #if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
86 block_list_base(const block_list_base&) = delete;
87 block_list_base operator=(const block_list_base&) = delete;
88 #else
89 private:
90 block_list_base (const block_list_base&);
91 block_list_base operator=(const block_list_base&);
92 public:
93 #endif
94
95 ~block_list_base()
96 {}
97
98 void *allocate(std::size_t size, memory_resource &mr)
99 {
100 if((size_t(-1) - header_size) < size)
101 throw_bad_alloc();
102 void *p = mr.allocate(size+header_size);
103 block_list_header &mb = *::new((void*)p) DerivedFromBlockListHeader;
104 mb.size = size+header_size;
105 list_algo::link_after(&m_list, &mb);
106 return (char *)p + header_size;
107 }
108
109 void deallocate(void *p, memory_resource &mr) BOOST_NOEXCEPT
110 {
111 DerivedFromBlockListHeader *pheader = static_cast<DerivedFromBlockListHeader*>
112 (static_cast<void*>((char*)p - header_size));
113 list_algo::unlink(pheader);
114 const std::size_t size = pheader->size;
115 static_cast<DerivedFromBlockListHeader*>(pheader)->~DerivedFromBlockListHeader();
116 mr.deallocate(pheader, size, memory_resource::max_align);
117 }
118
119 void release(memory_resource &mr) BOOST_NOEXCEPT
120 {
121 list_node *n = list_algo::node_traits::get_next(&m_list);
122 while(n != &m_list){
123 DerivedFromBlockListHeader &d = static_cast<DerivedFromBlockListHeader&>(*n);
124 n = list_algo::node_traits::get_next(n);
125 std::size_t size = d.size;
126 d.~DerivedFromBlockListHeader();
127 mr.deallocate(reinterpret_cast<char*>(&d), size, memory_resource::max_align);
128 }
129 list_algo::init_header(&m_list);
130 }
131 };
132
133 } //namespace pmr {
134 } //namespace container {
135 } //namespace boost {
136
137 #include <boost/container/detail/config_end.hpp>
138
139 #endif //BOOST_CONTAINER_DETAIL_BLOCK_LIST_HEADER