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