File indexing completed on 2025-01-18 09:38:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_SHM_NAMED_MUTEX_HPP
0012 #define BOOST_INTERPROCESS_SHM_NAMED_MUTEX_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/creation_tags.hpp>
0025 #include <boost/interprocess/exceptions.hpp>
0026 #include <boost/interprocess/detail/interprocess_tester.hpp>
0027 #include <boost/interprocess/permissions.hpp>
0028
0029 #include <boost/interprocess/shared_memory_object.hpp>
0030 #include <boost/interprocess/sync/interprocess_mutex.hpp>
0031 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
0032 #include <boost/interprocess/sync/shm/named_creation_functor.hpp>
0033
0034
0035
0036
0037 namespace boost {
0038 namespace interprocess {
0039 namespace ipcdetail {
0040
0041 class named_condition;
0042
0043
0044
0045
0046 class shm_named_mutex
0047 {
0048 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0049
0050
0051 shm_named_mutex();
0052 shm_named_mutex(const shm_named_mutex &);
0053 shm_named_mutex &operator=(const shm_named_mutex &);
0054 friend class named_condition;
0055 #endif
0056
0057 public:
0058
0059
0060 shm_named_mutex(create_only_t, const char *name, const permissions &perm = permissions());
0061
0062
0063
0064
0065
0066
0067
0068 shm_named_mutex(open_or_create_t, const char *name, const permissions &perm = permissions());
0069
0070
0071
0072
0073 shm_named_mutex(open_only_t, const char *name);
0074
0075 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0076
0077
0078
0079 shm_named_mutex(create_only_t, const wchar_t *name, const permissions &perm = permissions());
0080
0081
0082
0083
0084
0085
0086
0087 shm_named_mutex(open_or_create_t, const wchar_t *name, const permissions &perm = permissions());
0088
0089
0090
0091
0092 shm_named_mutex(open_only_t, const wchar_t *name);
0093
0094 #endif
0095
0096
0097
0098
0099
0100
0101
0102 ~shm_named_mutex();
0103
0104
0105
0106 void unlock();
0107
0108
0109
0110 void lock();
0111
0112
0113
0114
0115 bool try_lock();
0116
0117
0118
0119
0120 template<class TimePoint>
0121 bool timed_lock(const TimePoint &abs_time);
0122
0123 template<class TimePoint> bool try_lock_until(const TimePoint &abs_time)
0124 { return this->timed_lock(abs_time); }
0125
0126 template<class Duration> bool try_lock_for(const Duration &dur)
0127 { return this->timed_lock(duration_to_ustime(dur)); }
0128
0129
0130
0131 static bool remove(const char *name);
0132
0133 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0134
0135
0136
0137 static bool remove(const wchar_t *name);
0138
0139 #endif
0140
0141 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0142 typedef interprocess_mutex internal_mutex_type;
0143 interprocess_mutex &internal_mutex()
0144 { return *static_cast<interprocess_mutex*>(m_shmem.get_user_address()); }
0145
0146 private:
0147 friend class ipcdetail::interprocess_tester;
0148 void dont_close_on_destruction();
0149 typedef ipcdetail::managed_open_or_create_impl<shared_memory_object, 0, true, false> open_create_impl_t;
0150 open_create_impl_t m_shmem;
0151 typedef ipcdetail::named_creation_functor<interprocess_mutex> construct_func_t;
0152 #endif
0153 };
0154
0155 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0156
0157 inline void shm_named_mutex::dont_close_on_destruction()
0158 { ipcdetail::interprocess_tester::dont_close_on_destruction(m_shmem); }
0159
0160 inline shm_named_mutex::~shm_named_mutex()
0161 {}
0162
0163 inline shm_named_mutex::shm_named_mutex(create_only_t, const char *name, const permissions &perm)
0164 : m_shmem (create_only_t()
0165 ,name
0166 ,sizeof(interprocess_mutex) +
0167 open_create_impl_t::ManagedOpenOrCreateUserOffset
0168 ,read_write
0169 ,0
0170 ,construct_func_t(ipcdetail::DoCreate)
0171 ,perm)
0172 {}
0173
0174 inline shm_named_mutex::shm_named_mutex(open_or_create_t, const char *name, const permissions &perm)
0175 : m_shmem (open_or_create_t()
0176 ,name
0177 ,sizeof(interprocess_mutex) +
0178 open_create_impl_t::ManagedOpenOrCreateUserOffset
0179 ,read_write
0180 ,0
0181 ,construct_func_t(ipcdetail::DoOpenOrCreate)
0182 ,perm)
0183 {}
0184
0185 inline shm_named_mutex::shm_named_mutex(open_only_t, const char *name)
0186 : m_shmem (open_only_t()
0187 ,name
0188 ,read_write
0189 ,0
0190 ,construct_func_t(ipcdetail::DoOpen))
0191 {}
0192
0193 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0194
0195 inline shm_named_mutex::shm_named_mutex(create_only_t, const wchar_t *name, const permissions &perm)
0196 : m_shmem (create_only_t()
0197 ,name
0198 ,sizeof(interprocess_mutex) +
0199 open_create_impl_t::ManagedOpenOrCreateUserOffset
0200 ,read_write
0201 ,0
0202 ,construct_func_t(ipcdetail::DoCreate)
0203 ,perm)
0204 {}
0205
0206 inline shm_named_mutex::shm_named_mutex(open_or_create_t, const wchar_t *name, const permissions &perm)
0207 : m_shmem (open_or_create_t()
0208 ,name
0209 ,sizeof(interprocess_mutex) +
0210 open_create_impl_t::ManagedOpenOrCreateUserOffset
0211 ,read_write
0212 ,0
0213 ,construct_func_t(ipcdetail::DoOpenOrCreate)
0214 ,perm)
0215 {}
0216
0217 inline shm_named_mutex::shm_named_mutex(open_only_t, const wchar_t *name)
0218 : m_shmem (open_only_t()
0219 ,name
0220 ,read_write
0221 ,0
0222 ,construct_func_t(ipcdetail::DoOpen))
0223 {}
0224
0225 #endif
0226
0227 inline void shm_named_mutex::lock()
0228 { this->internal_mutex().lock(); }
0229
0230 inline void shm_named_mutex::unlock()
0231 { this->internal_mutex().unlock(); }
0232
0233 inline bool shm_named_mutex::try_lock()
0234 { return this->internal_mutex().try_lock(); }
0235
0236 template<class TimePoint>
0237 inline bool shm_named_mutex::timed_lock(const TimePoint &abs_time)
0238 { return this->internal_mutex().timed_lock(abs_time); }
0239
0240 inline bool shm_named_mutex::remove(const char *name)
0241 { return shared_memory_object::remove(name); }
0242
0243 #if defined(BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES) || defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0244
0245 inline bool shm_named_mutex::remove(const wchar_t *name)
0246 { return shared_memory_object::remove(name); }
0247
0248 #endif
0249
0250 #endif
0251
0252 }
0253 }
0254 }
0255
0256 #include <boost/interprocess/detail/config_end.hpp>
0257
0258 #endif