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