]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/interprocess/managed_heap_memory.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / interprocess / managed_heap_memory.hpp
CommitLineData
7c673cae
FG
1//////////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright Ion Gaztanaga 2005-2012. 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/interprocess for documentation.
8//
9//////////////////////////////////////////////////////////////////////////////
10
11#ifndef BOOST_INTERPROCESS_MANAGED_HEAP_MEMORY_HPP
12#define BOOST_INTERPROCESS_MANAGED_HEAP_MEMORY_HPP
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/interprocess/detail/config_begin.hpp>
23#include <boost/interprocess/detail/workaround.hpp>
24#include <boost/interprocess/creation_tags.hpp>
25#include <boost/move/utility_core.hpp>
26#include <vector>
27#include <boost/interprocess/detail/managed_memory_impl.hpp>
28#include <boost/core/no_exceptions_support.hpp>
29//These includes needed to fulfill default template parameters of
30//predeclarations in interprocess_fwd.hpp
31#include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
32#include <boost/interprocess/sync/mutex_family.hpp>
33#include <boost/interprocess/indexes/iset_index.hpp>
34
35//!\file
36//!Describes a named heap memory allocation user class.
37
38namespace boost {
39namespace interprocess {
40
41//!A basic heap memory named object creation class. Initializes the
42//!heap memory segment. Inherits all basic functionality from
43//!basic_managed_memory_impl<CharType, AllocationAlgorithm, IndexType>*/
44template
45 <
46 class CharType,
47 class AllocationAlgorithm,
48 template<class IndexConfig> class IndexType
49 >
50class basic_managed_heap_memory
51 : public ipcdetail::basic_managed_memory_impl <CharType, AllocationAlgorithm, IndexType>
52{
53 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
54 private:
55
56 typedef ipcdetail::basic_managed_memory_impl
57 <CharType, AllocationAlgorithm, IndexType> base_t;
58 BOOST_MOVABLE_BUT_NOT_COPYABLE(basic_managed_heap_memory)
59 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
60
61 public: //functions
62 typedef typename base_t::size_type size_type;
63
64 //!Default constructor. Does nothing.
65 //!Useful in combination with move semantics
1e59de90
TL
66 basic_managed_heap_memory() BOOST_NOEXCEPT
67 {}
7c673cae
FG
68
69 //!Destructor. Liberates the heap memory holding the managed data.
70 //!Never throws.
71 ~basic_managed_heap_memory()
72 { this->priv_close(); }
73
74 //!Creates heap memory and initializes the segment manager.
75 //!This can throw.
76 basic_managed_heap_memory(size_type size)
77 : m_heapmem(size, char(0))
78 {
79 if(!base_t::create_impl(&m_heapmem[0], size)){
80 this->priv_close();
81 throw interprocess_exception("Could not initialize heap in basic_managed_heap_memory constructor");
82 }
83 }
84
85 //!Moves the ownership of "moved"'s managed memory to *this. Does not throw
1e59de90 86 basic_managed_heap_memory(BOOST_RV_REF(basic_managed_heap_memory) moved) BOOST_NOEXCEPT
7c673cae
FG
87 { this->swap(moved); }
88
89 //!Moves the ownership of "moved"'s managed memory to *this. Does not throw
1e59de90 90 basic_managed_heap_memory &operator=(BOOST_RV_REF(basic_managed_heap_memory) moved) BOOST_NOEXCEPT
7c673cae
FG
91 {
92 basic_managed_heap_memory tmp(boost::move(moved));
93 this->swap(tmp);
94 return *this;
95 }
96
97 //!Tries to resize internal heap memory so that
98 //!we have room for more objects.
99 //!WARNING: If memory is reallocated, all the objects will
100 //!be binary-copied to the new buffer. To be able to use
101 //!this function, all pointers constructed in this buffer
102 //!must be offset pointers. Otherwise, the result is undefined.
103 //!Returns true if the growth has been successful, so you will
104 //!have some extra bytes to allocate new objects. If returns
105 //!false, the heap allocation has failed.
106 bool grow(size_type extra_bytes)
107 {
108 //If memory is reallocated, data will
109 //be automatically copied
110 BOOST_TRY{
111 m_heapmem.resize(m_heapmem.size()+extra_bytes);
112 }
113 BOOST_CATCH(...){
114 return false;
115 }
116 BOOST_CATCH_END
117
118 //Grow always works
119 base_t::close_impl();
120 base_t::open_impl(&m_heapmem[0], m_heapmem.size());
121 base_t::grow(extra_bytes);
122 return true;
123 }
124
125 //!Swaps the ownership of the managed heap memories managed by *this and other.
126 //!Never throws.
1e59de90 127 void swap(basic_managed_heap_memory &other) BOOST_NOEXCEPT
7c673cae
FG
128 {
129 base_t::swap(other);
130 m_heapmem.swap(other.m_heapmem);
131 }
132
133 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
134 private:
135 //!Frees resources. Never throws.
136 void priv_close()
137 {
138 base_t::destroy_impl();
139 std::vector<char>().swap(m_heapmem);
140 }
141
142 std::vector<char> m_heapmem;
143 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
144};
145
146#ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
147
148//!Typedef for a default basic_managed_heap_memory
149//!of narrow characters
150typedef basic_managed_heap_memory
151 <char
152 ,rbtree_best_fit<null_mutex_family>
153 ,iset_index>
154managed_heap_memory;
155
156//!Typedef for a default basic_managed_heap_memory
157//!of wide characters
158typedef basic_managed_heap_memory
159 <wchar_t
160 ,rbtree_best_fit<null_mutex_family>
161 ,iset_index>
162wmanaged_heap_memory;
163
164#endif //#ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
165
166} //namespace interprocess {
167} //namespace boost {
168
169#include <boost/interprocess/detail/config_end.hpp>
170
171#endif //BOOST_INTERPROCESS_MANAGED_HEAP_MEMORY_HPP
172