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