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