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