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_WINDOWS_SHARED_MEMORY_HPP
0012 #define BOOST_INTERPROCESS_MANAGED_WINDOWS_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 #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/windows_shared_memory.hpp>
0028 #include <boost/interprocess/permissions.hpp>
0029 #include <boost/move/utility_core.hpp>
0030
0031
0032 #include <boost/interprocess/mem_algo/rbtree_best_fit.hpp>
0033 #include <boost/interprocess/sync/mutex_family.hpp>
0034 #include <boost/interprocess/indexes/iset_index.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 wshmem_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 < windows_shared_memory
0061 , final_segment_manager_alignment
0062 , false
0063 , false> type;
0064 };
0065
0066
0067 }
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 template
0081 <
0082 class CharType,
0083 class AllocationAlgorithm,
0084 template<class IndexConfig> class IndexType
0085 >
0086 class basic_managed_windows_shared_memory
0087 : public ipcdetail::basic_managed_memory_impl
0088 < CharType, AllocationAlgorithm, IndexType
0089 , ipcdetail::wshmem_open_or_create
0090 <CharType, AllocationAlgorithm, IndexType>::type::ManagedOpenOrCreateUserOffset>
0091 {
0092 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0093 private:
0094 typedef ipcdetail::basic_managed_memory_impl
0095 < CharType, AllocationAlgorithm, IndexType
0096 , ipcdetail::wshmem_open_or_create
0097 <CharType, AllocationAlgorithm, IndexType>::type::ManagedOpenOrCreateUserOffset> base_t;
0098 typedef ipcdetail::create_open_func<base_t> create_open_func_t;
0099
0100 basic_managed_windows_shared_memory *get_this_pointer()
0101 { return this; }
0102
0103 private:
0104 typedef typename base_t::char_ptr_holder_t char_ptr_holder_t;
0105 BOOST_MOVABLE_BUT_NOT_COPYABLE(basic_managed_windows_shared_memory)
0106 #endif
0107
0108 public:
0109 typedef typename base_t::size_type size_type;
0110
0111
0112
0113 basic_managed_windows_shared_memory() BOOST_NOEXCEPT
0114 {}
0115
0116
0117
0118 basic_managed_windows_shared_memory
0119 (create_only_t, const char *name,
0120 size_type size, const void *addr = 0, const permissions &perm = permissions())
0121 : m_wshm(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_windows_shared_memory
0130 (open_or_create_t,
0131 const char *name, size_type size,
0132 const void *addr = 0,
0133 const permissions &perm = permissions())
0134 : m_wshm(open_or_create, name, size, read_write, addr,
0135 create_open_func_t(get_this_pointer(),
0136 ipcdetail::DoOpenOrCreate), perm)
0137 {}
0138
0139
0140
0141 basic_managed_windows_shared_memory
0142 (open_only_t, const char* name, const void *addr = 0)
0143 : m_wshm(open_only, name, read_write, addr,
0144 create_open_func_t(get_this_pointer(),
0145 ipcdetail::DoOpen))
0146 {}
0147
0148
0149
0150
0151 basic_managed_windows_shared_memory
0152 (open_copy_on_write_t, const char* name, const void *addr = 0)
0153 : m_wshm(open_only, name, copy_on_write, addr,
0154 create_open_func_t(get_this_pointer(), ipcdetail::DoOpen))
0155 {}
0156
0157
0158
0159
0160 basic_managed_windows_shared_memory
0161 (open_read_only_t, const char* name, const void *addr = 0)
0162 : base_t()
0163 , m_wshm(open_only, name, read_only, addr,
0164 create_open_func_t(get_this_pointer(), ipcdetail::DoOpen))
0165 {}
0166
0167
0168
0169
0170
0171 basic_managed_windows_shared_memory
0172 (open_or_create_t,
0173 const wchar_t *name, size_type size,
0174 const void *addr = 0,
0175 const permissions &perm = permissions())
0176 : m_wshm(open_or_create, name, size, read_write, addr,
0177 create_open_func_t(get_this_pointer(),
0178 ipcdetail::DoOpenOrCreate), perm)
0179 {}
0180
0181
0182
0183 basic_managed_windows_shared_memory
0184 (open_only_t, const wchar_t* name, const void *addr = 0)
0185 : m_wshm(open_only, name, read_write, addr,
0186 create_open_func_t(get_this_pointer(),
0187 ipcdetail::DoOpen))
0188 {}
0189
0190
0191
0192
0193 basic_managed_windows_shared_memory
0194 (open_copy_on_write_t, const wchar_t* name, const void *addr = 0)
0195 : m_wshm(open_only, name, copy_on_write, addr,
0196 create_open_func_t(get_this_pointer(), ipcdetail::DoOpen))
0197 {}
0198
0199
0200
0201
0202 basic_managed_windows_shared_memory
0203 (open_read_only_t, const wchar_t* name, const void *addr = 0)
0204 : base_t()
0205 , m_wshm(open_only, name, read_only, addr,
0206 create_open_func_t(get_this_pointer(), ipcdetail::DoOpen))
0207 {}
0208
0209
0210
0211 basic_managed_windows_shared_memory
0212 (BOOST_RV_REF(basic_managed_windows_shared_memory) moved) BOOST_NOEXCEPT
0213 { this->swap(moved); }
0214
0215
0216
0217 basic_managed_windows_shared_memory &operator=(BOOST_RV_REF(basic_managed_windows_shared_memory) moved) BOOST_NOEXCEPT
0218 {
0219 basic_managed_windows_shared_memory tmp(boost::move(moved));
0220 this->swap(tmp);
0221 return *this;
0222 }
0223
0224
0225
0226
0227
0228
0229 ~basic_managed_windows_shared_memory()
0230 {}
0231
0232
0233
0234 void swap(basic_managed_windows_shared_memory &other) BOOST_NOEXCEPT
0235 {
0236 base_t::swap(other);
0237 m_wshm.swap(other.m_wshm);
0238 }
0239
0240 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0241
0242
0243
0244
0245 template <class T>
0246 std::pair<T*, size_type> find (char_ptr_holder_t name)
0247 {
0248 if(m_wshm.get_mapped_region().get_mode() == read_only){
0249 return base_t::template find_no_lock<T>(name);
0250 }
0251 else{
0252 return base_t::template find<T>(name);
0253 }
0254 }
0255
0256 private:
0257 typename ipcdetail::wshmem_open_or_create
0258 <CharType, AllocationAlgorithm, IndexType>::type m_wshm;
0259 #endif
0260 };
0261
0262 #ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0263
0264
0265
0266 typedef basic_managed_windows_shared_memory
0267 <char
0268 ,rbtree_best_fit<mutex_family>
0269 ,iset_index>
0270 managed_windows_shared_memory;
0271
0272
0273
0274 typedef basic_managed_windows_shared_memory
0275 <wchar_t
0276 ,rbtree_best_fit<mutex_family>
0277 ,iset_index>
0278 wmanaged_windows_shared_memory;
0279
0280 #endif
0281
0282
0283 }
0284 }
0285
0286 #include <boost/interprocess/detail/config_end.hpp>
0287
0288 #endif