File indexing completed on 2025-09-16 08:37:09
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_MANAGED_SHARED_MEMORY_HPP
0012 #define BOOST_INTERPROCESS_MANAGED_SHARED_MEMORY_HPP
0013
0014 #ifndef BOOST_CONFIG_HPP
0015 # include <boost/config.hpp>
0016 #endif
0017 #
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 # pragma once
0020 #endif
0021
0022 #include <boost/interprocess/detail/config_begin.hpp>
0023 #include <boost/interprocess/detail/workaround.hpp>
0024
0025 #include <boost/interprocess/detail/managed_memory_impl.hpp>
0026 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
0027 #include <boost/interprocess/shared_memory_object.hpp>
0028 #include <boost/interprocess/creation_tags.hpp>
0029 #include <boost/interprocess/permissions.hpp>
0030
0031
0032 #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
0033 #include <boost/interprocess/sync/mutex_family.hpp>
0034
0035 namespace boost {
0036 namespace interprocess {
0037
0038 namespace ipcdetail {
0039
0040 template
0041 <
0042 class CharType,
0043 class AllocationAlgorithm,
0044 template<class IndexConfig> class IndexType
0045 >
0046 struct shmem_open_or_create
0047 {
0048 static const std::size_t segment_manager_alignment = boost::move_detail::alignment_of
0049 < segment_manager
0050 < CharType
0051 , AllocationAlgorithm
0052 , IndexType>
0053 >::value;
0054 static const std::size_t final_segment_manager_alignment
0055 = segment_manager_alignment > AllocationAlgorithm::Alignment
0056 ? segment_manager_alignment : AllocationAlgorithm::Alignment;
0057
0058 typedef ipcdetail::managed_open_or_create_impl
0059 < shared_memory_object
0060 , final_segment_manager_alignment
0061 , true
0062 , false> type;
0063 };
0064
0065 }
0066
0067
0068
0069
0070 template
0071 <
0072 class CharType,
0073 class AllocationAlgorithm,
0074 template<class IndexConfig> class IndexType
0075 >
0076 class basic_managed_shared_memory
0077 : public ipcdetail::basic_managed_memory_impl
0078 < CharType, AllocationAlgorithm, IndexType
0079 , ipcdetail::shmem_open_or_create<CharType, AllocationAlgorithm, IndexType>::type::ManagedOpenOrCreateUserOffset>
0080 , private ipcdetail::shmem_open_or_create<CharType, AllocationAlgorithm, IndexType>::type
0081 {
0082 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0083 typedef typename ipcdetail::shmem_open_or_create
0084 < CharType
0085 , AllocationAlgorithm
0086 , IndexType>::type base2_t;
0087 typedef ipcdetail::basic_managed_memory_impl
0088 <CharType, AllocationAlgorithm, IndexType,
0089 base2_t::ManagedOpenOrCreateUserOffset> base_t;
0090
0091 typedef ipcdetail::create_open_func<base_t> create_open_func_t;
0092
0093 basic_managed_shared_memory *get_this_pointer()
0094 { return this; }
0095
0096 public:
0097 typedef shared_memory_object device_type;
0098 typedef typename base_t::size_type size_type;
0099
0100 private:
0101 typedef typename base_t::char_ptr_holder_t char_ptr_holder_t;
0102 BOOST_MOVABLE_BUT_NOT_COPYABLE(basic_managed_shared_memory)
0103 #endif
0104
0105 public:
0106
0107
0108
0109
0110
0111
0112
0113 ~basic_managed_shared_memory()
0114 {}
0115
0116
0117
0118 basic_managed_shared_memory()
0119 {}
0120
0121
0122
0123 basic_managed_shared_memory(create_only_t, const char *name,
0124 size_type size, const void *addr = 0, const permissions& perm = permissions())
0125 : base_t()
0126 , base2_t(create_only, name, size, read_write, addr,
0127 create_open_func_t(get_this_pointer(), ipcdetail::DoCreate), perm)
0128 {}
0129
0130
0131
0132
0133
0134 basic_managed_shared_memory (open_or_create_t,
0135 const char *name, size_type size,
0136 const void *addr = 0, const permissions& perm = permissions())
0137 : base_t()
0138 , base2_t(open_or_create, name, size, read_write, addr,
0139 create_open_func_t(get_this_pointer(),
0140 ipcdetail::DoOpenOrCreate), perm)
0141 {}
0142
0143
0144
0145
0146 basic_managed_shared_memory (open_copy_on_write_t, const char* name,
0147 const void *addr = 0)
0148 : base_t()
0149 , base2_t(open_only, name, copy_on_write, addr,
0150 create_open_func_t(get_this_pointer(),
0151 ipcdetail::DoOpen))
0152 {}
0153
0154
0155
0156
0157 basic_managed_shared_memory (open_read_only_t, const char* name,
0158 const void *addr = 0)
0159 : base_t()
0160 , base2_t(open_only, name, read_only, addr,
0161 create_open_func_t(get_this_pointer(),
0162 ipcdetail::DoOpen))
0163 {}
0164
0165
0166
0167 basic_managed_shared_memory (open_only_t, const char* name,
0168 const void *addr = 0)
0169 : base_t()
0170 , base2_t(open_only, name, read_write, addr,
0171 create_open_func_t(get_this_pointer(),
0172 ipcdetail::DoOpen))
0173 {}
0174
0175 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0176
0177
0178
0179
0180
0181
0182 basic_managed_shared_memory(create_only_t, const wchar_t *name,
0183 size_type size, const void *addr = 0, const permissions& perm = permissions())
0184 : base_t()
0185 , base2_t(create_only, name, size, read_write, addr,
0186 create_open_func_t(get_this_pointer(), ipcdetail::DoCreate), perm)
0187 {}
0188
0189
0190
0191
0192
0193
0194
0195
0196 basic_managed_shared_memory (open_or_create_t,
0197 const wchar_t *name, size_type size,
0198 const void *addr = 0, const permissions& perm = permissions())
0199 : base_t()
0200 , base2_t(open_or_create, name, size, read_write, addr,
0201 create_open_func_t(get_this_pointer(),
0202 ipcdetail::DoOpenOrCreate), perm)
0203 {}
0204
0205
0206
0207
0208
0209
0210
0211 basic_managed_shared_memory (open_copy_on_write_t, const wchar_t* name,
0212 const void *addr = 0)
0213 : base_t()
0214 , base2_t(open_only, name, copy_on_write, addr,
0215 create_open_func_t(get_this_pointer(),
0216 ipcdetail::DoOpen))
0217 {}
0218
0219
0220
0221
0222
0223
0224
0225 basic_managed_shared_memory (open_read_only_t, const wchar_t* name,
0226 const void *addr = 0)
0227 : base_t()
0228 , base2_t(open_only, name, read_only, addr,
0229 create_open_func_t(get_this_pointer(),
0230 ipcdetail::DoOpen))
0231 {}
0232
0233
0234
0235
0236
0237
0238 basic_managed_shared_memory (open_only_t, const wchar_t* name,
0239 const void *addr = 0)
0240 : base_t()
0241 , base2_t(open_only, name, read_write, addr,
0242 create_open_func_t(get_this_pointer(),
0243 ipcdetail::DoOpen))
0244 {}
0245
0246 #endif
0247
0248
0249
0250 basic_managed_shared_memory(BOOST_RV_REF(basic_managed_shared_memory) moved)
0251 {
0252 basic_managed_shared_memory tmp;
0253 this->swap(moved);
0254 tmp.swap(moved);
0255 }
0256
0257
0258
0259 basic_managed_shared_memory &operator=(BOOST_RV_REF(basic_managed_shared_memory) moved)
0260 {
0261 basic_managed_shared_memory tmp(boost::move(moved));
0262 this->swap(tmp);
0263 return *this;
0264 }
0265
0266
0267
0268 void swap(basic_managed_shared_memory &other)
0269 {
0270 base_t::swap(other);
0271 base2_t::swap(other);
0272 }
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282 static bool grow(const char *shmname, size_type extra_bytes)
0283 {
0284 return base_t::template grow
0285 <basic_managed_shared_memory>(shmname, extra_bytes);
0286 }
0287
0288
0289
0290
0291
0292 static bool shrink_to_fit(const char *shmname)
0293 {
0294 return base_t::template shrink_to_fit
0295 <basic_managed_shared_memory>(shmname);
0296 }
0297
0298 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308 static bool grow(const wchar_t *shmname, size_type extra_bytes)
0309 {
0310 return base_t::template grow
0311 <basic_managed_shared_memory>(shmname, extra_bytes);
0312 }
0313
0314
0315
0316
0317
0318
0319
0320
0321 static bool shrink_to_fit(const wchar_t *shmname)
0322 {
0323 return base_t::template shrink_to_fit
0324 <basic_managed_shared_memory>(shmname);
0325 }
0326
0327 #endif
0328
0329 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0330
0331
0332
0333
0334 template <class T>
0335 std::pair<T*, size_type> find (char_ptr_holder_t name)
0336 {
0337 if(base2_t::get_mapped_region().get_mode() == read_only){
0338 return base_t::template find_no_lock<T>(name);
0339 }
0340 else{
0341 return base_t::template find<T>(name);
0342 }
0343 }
0344
0345 #endif
0346 };
0347
0348 #ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0349
0350
0351
0352 typedef basic_managed_shared_memory
0353 <char
0354 ,rbtree_best_fit<mutex_family>
0355 ,iset_index>
0356 managed_shared_memory;
0357
0358
0359
0360 typedef basic_managed_shared_memory
0361 <wchar_t
0362 ,rbtree_best_fit<mutex_family>
0363 ,iset_index>
0364 wmanaged_shared_memory;
0365
0366
0367
0368 typedef basic_managed_shared_memory
0369 <char
0370 ,rbtree_best_fit<mutex_family, void*>
0371 ,iset_index>
0372 fixed_managed_shared_memory;
0373
0374
0375
0376 typedef basic_managed_shared_memory
0377 <wchar_t
0378 ,rbtree_best_fit<mutex_family, void*>
0379 ,iset_index>
0380 wfixed_managed_shared_memory;
0381
0382
0383 #endif
0384
0385 }
0386 }
0387
0388 #include <boost/interprocess/detail/config_end.hpp>
0389
0390 #endif
0391