annotate DEPENDENCIES/generic/include/boost/interprocess/managed_xsi_shared_memory.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 //////////////////////////////////////////////////////////////////////////////
Chris@16 2 //
Chris@16 3 // (C) Copyright Ion Gaztanaga 2008-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_XSI_SHARED_MEMORY_HPP
Chris@16 12 #define BOOST_INTERPROCESS_MANAGED_XSI_SHARED_MEMORY_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
Chris@16 25 #if !defined(BOOST_INTERPROCESS_XSI_SHARED_MEMORY_OBJECTS)
Chris@16 26 #error "This header can't be used in operating systems without XSI (System V) shared memory support"
Chris@16 27 #endif
Chris@16 28
Chris@16 29 #include <boost/interprocess/detail/managed_memory_impl.hpp>
Chris@16 30 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
Chris@16 31 #include <boost/interprocess/detail/xsi_shared_memory_file_wrapper.hpp>
Chris@16 32 #include <boost/interprocess/creation_tags.hpp>
Chris@16 33 //These includes needed to fulfill default template parameters of
Chris@16 34 //predeclarations in interprocess_fwd.hpp
Chris@16 35 #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
Chris@16 36 #include <boost/interprocess/sync/mutex_family.hpp>
Chris@16 37 #include <boost/interprocess/indexes/iset_index.hpp>
Chris@16 38
Chris@16 39 namespace boost {
Chris@16 40
Chris@16 41 namespace interprocess {
Chris@16 42
Chris@16 43 namespace ipcdetail {
Chris@16 44
Chris@16 45 template<class AllocationAlgorithm>
Chris@16 46 struct xsishmem_open_or_create
Chris@16 47 {
Chris@16 48 typedef ipcdetail::managed_open_or_create_impl //!FileBased, StoreDevice
Chris@16 49 < xsi_shared_memory_file_wrapper, AllocationAlgorithm::Alignment, false, true> type;
Chris@16 50 };
Chris@16 51
Chris@16 52 } //namespace ipcdetail {
Chris@16 53
Chris@16 54 //!A basic X/Open System Interface (XSI) shared memory named object creation class. Initializes the
Chris@16 55 //!shared memory segment. Inherits all basic functionality from
Chris@16 56 //!basic_managed_memory_impl<CharType, AllocationAlgorithm, IndexType>
Chris@16 57 template
Chris@16 58 <
Chris@16 59 class CharType,
Chris@16 60 class AllocationAlgorithm,
Chris@16 61 template<class IndexConfig> class IndexType
Chris@16 62 >
Chris@16 63 class basic_managed_xsi_shared_memory
Chris@16 64 : public ipcdetail::basic_managed_memory_impl
Chris@16 65 <CharType, AllocationAlgorithm, IndexType
Chris@16 66 ,ipcdetail::xsishmem_open_or_create<AllocationAlgorithm>::type::ManagedOpenOrCreateUserOffset>
Chris@16 67 , private ipcdetail::xsishmem_open_or_create<AllocationAlgorithm>::type
Chris@16 68 {
Chris@101 69 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
Chris@16 70 public:
Chris@16 71 typedef xsi_shared_memory_file_wrapper device_type;
Chris@16 72
Chris@16 73 public:
Chris@16 74 typedef typename ipcdetail::xsishmem_open_or_create<AllocationAlgorithm>::type base2_t;
Chris@16 75 typedef ipcdetail::basic_managed_memory_impl
Chris@16 76 <CharType, AllocationAlgorithm, IndexType,
Chris@16 77 base2_t::ManagedOpenOrCreateUserOffset> base_t;
Chris@16 78
Chris@16 79 typedef ipcdetail::create_open_func<base_t> create_open_func_t;
Chris@16 80
Chris@16 81 basic_managed_xsi_shared_memory *get_this_pointer()
Chris@16 82 { return this; }
Chris@16 83
Chris@16 84 private:
Chris@16 85 typedef typename base_t::char_ptr_holder_t char_ptr_holder_t;
Chris@16 86 BOOST_MOVABLE_BUT_NOT_COPYABLE(basic_managed_xsi_shared_memory)
Chris@101 87 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
Chris@16 88
Chris@16 89 public: //functions
Chris@16 90 typedef typename base_t::size_type size_type;
Chris@16 91
Chris@16 92 //!Destroys *this and indicates that the calling process is finished using
Chris@16 93 //!the resource. The destructor function will deallocate
Chris@16 94 //!any system resources allocated by the system for use by this process for
Chris@16 95 //!this resource. The resource can still be opened again calling
Chris@16 96 //!the open constructor overload. To erase the resource from the system
Chris@16 97 //!use remove().
Chris@16 98 ~basic_managed_xsi_shared_memory()
Chris@16 99 {}
Chris@16 100
Chris@16 101 //!Default constructor. Does nothing.
Chris@16 102 //!Useful in combination with move semantics
Chris@16 103 basic_managed_xsi_shared_memory()
Chris@16 104 {}
Chris@16 105
Chris@16 106 //!Creates shared memory and creates and places the segment manager.
Chris@16 107 //!This can throw.
Chris@16 108 basic_managed_xsi_shared_memory(create_only_t, const xsi_key &key,
Chris@16 109 std::size_t size, const void *addr = 0, const permissions& perm = permissions())
Chris@16 110 : base_t()
Chris@16 111 , base2_t(create_only, key, size, read_write, addr,
Chris@16 112 create_open_func_t(get_this_pointer(), ipcdetail::DoCreate), perm)
Chris@16 113 {}
Chris@16 114
Chris@16 115 //!Creates shared memory and creates and places the segment manager if
Chris@16 116 //!segment was not created. If segment was created it connects to the
Chris@16 117 //!segment.
Chris@16 118 //!This can throw.
Chris@16 119 basic_managed_xsi_shared_memory (open_or_create_t,
Chris@16 120 const xsi_key &key, std::size_t size,
Chris@16 121 const void *addr = 0, const permissions& perm = permissions())
Chris@16 122 : base_t()
Chris@16 123 , base2_t(open_or_create, key, size, read_write, addr,
Chris@16 124 create_open_func_t(get_this_pointer(),
Chris@16 125 ipcdetail::DoOpenOrCreate), perm)
Chris@16 126 {}
Chris@16 127
Chris@16 128 //!Connects to a created shared memory and its segment manager.
Chris@16 129 //!in read-only mode.
Chris@16 130 //!This can throw.
Chris@16 131 basic_managed_xsi_shared_memory (open_read_only_t, const xsi_key &key,
Chris@16 132 const void *addr = 0)
Chris@16 133 : base_t()
Chris@16 134 , base2_t(open_only, key, read_only, addr,
Chris@16 135 create_open_func_t(get_this_pointer(),
Chris@16 136 ipcdetail::DoOpen))
Chris@16 137 {}
Chris@16 138
Chris@16 139 //!Connects to a created shared memory and its segment manager.
Chris@16 140 //!This can throw.
Chris@16 141 basic_managed_xsi_shared_memory (open_only_t, const xsi_key &key,
Chris@16 142 const void *addr = 0)
Chris@16 143 : base_t()
Chris@16 144 , base2_t(open_only, key, read_write, addr,
Chris@16 145 create_open_func_t(get_this_pointer(),
Chris@16 146 ipcdetail::DoOpen))
Chris@16 147 {}
Chris@16 148
Chris@16 149 //!Moves the ownership of "moved"'s managed memory to *this.
Chris@16 150 //!Does not throw
Chris@16 151 basic_managed_xsi_shared_memory(BOOST_RV_REF(basic_managed_xsi_shared_memory) moved)
Chris@16 152 {
Chris@16 153 basic_managed_xsi_shared_memory tmp;
Chris@16 154 this->swap(moved);
Chris@16 155 tmp.swap(moved);
Chris@16 156 }
Chris@16 157
Chris@16 158 //!Moves the ownership of "moved"'s managed memory to *this.
Chris@16 159 //!Does not throw
Chris@16 160 basic_managed_xsi_shared_memory &operator=(BOOST_RV_REF(basic_managed_xsi_shared_memory) moved)
Chris@16 161 {
Chris@16 162 basic_managed_xsi_shared_memory tmp(boost::move(moved));
Chris@16 163 this->swap(tmp);
Chris@16 164 return *this;
Chris@16 165 }
Chris@16 166
Chris@16 167 //!Swaps the ownership of the managed shared memories managed by *this and other.
Chris@16 168 //!Never throws.
Chris@16 169 void swap(basic_managed_xsi_shared_memory &other)
Chris@16 170 {
Chris@16 171 base_t::swap(other);
Chris@16 172 base2_t::swap(other);
Chris@16 173 }
Chris@16 174
Chris@16 175 //!Erases a XSI shared memory object identified by shmid
Chris@16 176 //!from the system.
Chris@16 177 //!Returns false on error. Never throws
Chris@16 178 static bool remove(int shmid)
Chris@16 179 { return device_type::remove(shmid); }
Chris@16 180
Chris@16 181 int get_shmid() const
Chris@16 182 { return base2_t::get_device().get_shmid(); }
Chris@16 183
Chris@101 184 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
Chris@16 185
Chris@16 186 //!Tries to find a previous named allocation address. Returns a memory
Chris@16 187 //!buffer and the object count. If not found returned pointer is 0.
Chris@16 188 //!Never throws.
Chris@16 189 template <class T>
Chris@16 190 std::pair<T*, std::size_t> find (char_ptr_holder_t name)
Chris@16 191 {
Chris@16 192 if(base2_t::get_mapped_region().get_mode() == read_only){
Chris@16 193 return base_t::template find_no_lock<T>(name);
Chris@16 194 }
Chris@16 195 else{
Chris@16 196 return base_t::template find<T>(name);
Chris@16 197 }
Chris@16 198 }
Chris@16 199
Chris@101 200 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
Chris@16 201 };
Chris@16 202
Chris@101 203 #ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
Chris@101 204
Chris@101 205 //!Typedef for a default basic_managed_xsi_shared_memory
Chris@101 206 //!of narrow characters
Chris@101 207 typedef basic_managed_xsi_shared_memory
Chris@101 208 <char
Chris@101 209 ,rbtree_best_fit<mutex_family>
Chris@101 210 ,iset_index>
Chris@101 211 managed_xsi_shared_memory;
Chris@101 212
Chris@101 213 //!Typedef for a default basic_managed_xsi_shared_memory
Chris@101 214 //!of wide characters
Chris@101 215 typedef basic_managed_xsi_shared_memory
Chris@101 216 <wchar_t
Chris@101 217 ,rbtree_best_fit<mutex_family>
Chris@101 218 ,iset_index>
Chris@101 219 wmanaged_xsi_shared_memory;
Chris@101 220
Chris@101 221 #endif //#ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
Chris@101 222
Chris@16 223 } //namespace interprocess {
Chris@16 224 } //namespace boost {
Chris@16 225
Chris@16 226 #include <boost/interprocess/detail/config_end.hpp>
Chris@16 227
Chris@16 228 #endif //BOOST_INTERPROCESS_MANAGED_XSI_SHARED_MEMORY_HPP
Chris@16 229