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