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