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