File indexing completed on 2026-05-03 07:59:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_DETAIL_SPIN_SEMAPHORE_HPP
0012 #define BOOST_INTERPROCESS_DETAIL_SPIN_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/detail/atomic.hpp>
0026 #include <boost/interprocess/detail/os_thread_functions.hpp>
0027 #include <boost/interprocess/sync/detail/common_algorithms.hpp>
0028 #include <boost/interprocess/sync/detail/locks.hpp>
0029 #include <boost/cstdint.hpp>
0030
0031 namespace boost {
0032 namespace interprocess {
0033 namespace ipcdetail {
0034
0035 class spin_semaphore
0036 {
0037 spin_semaphore(const spin_semaphore &);
0038 spin_semaphore &operator=(const spin_semaphore &);
0039
0040 public:
0041 spin_semaphore(unsigned int initialCount);
0042 ~spin_semaphore();
0043
0044 void post();
0045 void wait();
0046 bool try_wait();
0047 template<class TimePoint> bool timed_wait(const TimePoint &abs_time);
0048
0049
0050 private:
0051 volatile boost::uint32_t m_count;
0052 };
0053
0054
0055 inline spin_semaphore::~spin_semaphore()
0056 {}
0057
0058 inline spin_semaphore::spin_semaphore(unsigned int initialCount)
0059 { ipcdetail::atomic_write32(&this->m_count, boost::uint32_t(initialCount)); }
0060
0061 inline void spin_semaphore::post()
0062 {
0063 ipcdetail::atomic_inc32(&m_count);
0064 }
0065
0066 inline void spin_semaphore::wait()
0067 {
0068 ipcdetail::lock_to_wait<spin_semaphore> lw(*this);
0069 return ipcdetail::try_based_lock(lw);
0070 }
0071
0072 inline bool spin_semaphore::try_wait()
0073 {
0074 return ipcdetail::atomic_add_unless32(&m_count, boost::uint32_t(-1), boost::uint32_t(0));
0075 }
0076
0077 template<class TimePoint>
0078 inline bool spin_semaphore::timed_wait(const TimePoint &abs_time)
0079 {
0080 ipcdetail::lock_to_wait<spin_semaphore> lw(*this);
0081 return ipcdetail::try_based_timed_lock(lw, abs_time);
0082 }
0083
0084
0085
0086
0087
0088
0089 }
0090 }
0091 }
0092
0093 #include <boost/interprocess/detail/config_end.hpp>
0094
0095 #endif