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