Chris@16
|
1 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
2 //
|
Chris@16
|
3 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
|
Chris@16
|
4 // Software License, Version 1.0. (See accompanying file
|
Chris@16
|
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
6 //
|
Chris@16
|
7 // See http://www.boost.org/libs/interprocess for documentation.
|
Chris@16
|
8 //
|
Chris@16
|
9 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
10
|
Chris@16
|
11 #ifndef BOOST_INTERPROCESS_MANAGED_EXTERNAL_BUFFER_HPP
|
Chris@16
|
12 #define BOOST_INTERPROCESS_MANAGED_EXTERNAL_BUFFER_HPP
|
Chris@16
|
13
|
Chris@101
|
14 #ifndef BOOST_CONFIG_HPP
|
Chris@101
|
15 # include <boost/config.hpp>
|
Chris@101
|
16 #endif
|
Chris@101
|
17 #
|
Chris@101
|
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
|
Chris@16
|
19 # pragma once
|
Chris@16
|
20 #endif
|
Chris@16
|
21
|
Chris@16
|
22 #include <boost/interprocess/detail/config_begin.hpp>
|
Chris@16
|
23 #include <boost/interprocess/detail/workaround.hpp>
|
Chris@16
|
24 #include <boost/interprocess/creation_tags.hpp>
|
Chris@16
|
25 #include <boost/interprocess/detail/managed_memory_impl.hpp>
|
Chris@101
|
26 #include <boost/move/utility_core.hpp>
|
Chris@16
|
27 #include <boost/assert.hpp>
|
Chris@16
|
28 //These includes needed to fulfill default template parameters of
|
Chris@16
|
29 //predeclarations in interprocess_fwd.hpp
|
Chris@16
|
30 #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
|
Chris@16
|
31 #include <boost/interprocess/sync/mutex_family.hpp>
|
Chris@16
|
32 #include <boost/interprocess/indexes/iset_index.hpp>
|
Chris@16
|
33
|
Chris@16
|
34 //!\file
|
Chris@16
|
35 //!Describes a named user memory allocation user class.
|
Chris@16
|
36
|
Chris@16
|
37 namespace boost {
|
Chris@16
|
38 namespace interprocess {
|
Chris@16
|
39
|
Chris@16
|
40 //!A basic user memory named object creation class. Inherits all
|
Chris@16
|
41 //!basic functionality from
|
Chris@16
|
42 //!basic_managed_memory_impl<CharType, AllocationAlgorithm, IndexType>*/
|
Chris@16
|
43 template
|
Chris@16
|
44 <
|
Chris@16
|
45 class CharType,
|
Chris@16
|
46 class AllocationAlgorithm,
|
Chris@16
|
47 template<class IndexConfig> class IndexType
|
Chris@16
|
48 >
|
Chris@16
|
49 class basic_managed_external_buffer
|
Chris@16
|
50 : public ipcdetail::basic_managed_memory_impl <CharType, AllocationAlgorithm, IndexType>
|
Chris@16
|
51 {
|
Chris@101
|
52 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
|
Chris@16
|
53 typedef ipcdetail::basic_managed_memory_impl
|
Chris@16
|
54 <CharType, AllocationAlgorithm, IndexType> base_t;
|
Chris@16
|
55 BOOST_MOVABLE_BUT_NOT_COPYABLE(basic_managed_external_buffer)
|
Chris@101
|
56 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
|
Chris@16
|
57
|
Chris@16
|
58 public:
|
Chris@16
|
59 typedef typename base_t::size_type size_type;
|
Chris@16
|
60
|
Chris@16
|
61 //!Default constructor. Does nothing.
|
Chris@16
|
62 //!Useful in combination with move semantics
|
Chris@16
|
63 basic_managed_external_buffer()
|
Chris@16
|
64 {}
|
Chris@16
|
65
|
Chris@16
|
66 //!Creates and places the segment manager. This can throw
|
Chris@16
|
67 basic_managed_external_buffer
|
Chris@16
|
68 (create_only_t, void *addr, size_type size)
|
Chris@16
|
69 {
|
Chris@16
|
70 //Check if alignment is correct
|
Chris@16
|
71 BOOST_ASSERT((0 == (((std::size_t)addr) & (AllocationAlgorithm::Alignment - size_type(1u)))));
|
Chris@16
|
72 if(!base_t::create_impl(addr, size)){
|
Chris@16
|
73 throw interprocess_exception("Could not initialize buffer in basic_managed_external_buffer constructor");
|
Chris@16
|
74 }
|
Chris@16
|
75 }
|
Chris@16
|
76
|
Chris@16
|
77 //!Creates and places the segment manager. This can throw
|
Chris@16
|
78 basic_managed_external_buffer
|
Chris@16
|
79 (open_only_t, void *addr, size_type size)
|
Chris@16
|
80 {
|
Chris@16
|
81 //Check if alignment is correct
|
Chris@16
|
82 BOOST_ASSERT((0 == (((std::size_t)addr) & (AllocationAlgorithm::Alignment - size_type(1u)))));
|
Chris@16
|
83 if(!base_t::open_impl(addr, size)){
|
Chris@16
|
84 throw interprocess_exception("Could not initialize buffer in basic_managed_external_buffer constructor");
|
Chris@16
|
85 }
|
Chris@16
|
86 }
|
Chris@16
|
87
|
Chris@16
|
88 //!Moves the ownership of "moved"'s managed memory to *this. Does not throw
|
Chris@16
|
89 basic_managed_external_buffer(BOOST_RV_REF(basic_managed_external_buffer) moved)
|
Chris@16
|
90 {
|
Chris@16
|
91 this->swap(moved);
|
Chris@16
|
92 }
|
Chris@16
|
93
|
Chris@16
|
94 //!Moves the ownership of "moved"'s managed memory to *this. Does not throw
|
Chris@16
|
95 basic_managed_external_buffer &operator=(BOOST_RV_REF(basic_managed_external_buffer) moved)
|
Chris@16
|
96 {
|
Chris@16
|
97 basic_managed_external_buffer tmp(boost::move(moved));
|
Chris@16
|
98 this->swap(tmp);
|
Chris@16
|
99 return *this;
|
Chris@16
|
100 }
|
Chris@16
|
101
|
Chris@16
|
102 void grow(size_type extra_bytes)
|
Chris@16
|
103 { base_t::grow(extra_bytes); }
|
Chris@16
|
104
|
Chris@16
|
105 //!Swaps the ownership of the managed heap memories managed by *this and other.
|
Chris@16
|
106 //!Never throws.
|
Chris@16
|
107 void swap(basic_managed_external_buffer &other)
|
Chris@16
|
108 { base_t::swap(other); }
|
Chris@16
|
109 };
|
Chris@16
|
110
|
Chris@101
|
111 #ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
|
Chris@101
|
112
|
Chris@101
|
113 //!Typedef for a default basic_managed_external_buffer
|
Chris@101
|
114 //!of narrow characters
|
Chris@101
|
115 typedef basic_managed_external_buffer
|
Chris@101
|
116 <char
|
Chris@101
|
117 ,rbtree_best_fit<null_mutex_family>
|
Chris@101
|
118 ,iset_index>
|
Chris@101
|
119 managed_external_buffer;
|
Chris@101
|
120
|
Chris@101
|
121 //!Typedef for a default basic_managed_external_buffer
|
Chris@101
|
122 //!of wide characters
|
Chris@101
|
123 typedef basic_managed_external_buffer
|
Chris@101
|
124 <wchar_t
|
Chris@101
|
125 ,rbtree_best_fit<null_mutex_family>
|
Chris@101
|
126 ,iset_index>
|
Chris@101
|
127 wmanaged_external_buffer;
|
Chris@101
|
128
|
Chris@101
|
129 #endif //#ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
|
Chris@101
|
130
|
Chris@16
|
131 } //namespace interprocess {
|
Chris@16
|
132 } //namespace boost {
|
Chris@16
|
133
|
Chris@16
|
134 #include <boost/interprocess/detail/config_end.hpp>
|
Chris@16
|
135
|
Chris@16
|
136 #endif //BOOST_INTERPROCESS_MANAGED_EXTERNAL_BUFFER_HPP
|
Chris@16
|
137
|