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