File indexing completed on 2025-01-18 09:38:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_POSIX_NAMED_CONDITION_HPP
0012 #define BOOST_INTERPROCESS_POSIX_NAMED_CONDITION_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
0025 #include <boost/interprocess/sync/posix/semaphore_wrapper.hpp>
0026
0027 namespace boost {
0028 namespace interprocess {
0029
0030 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0031 namespace ipcdetail{ class interprocess_tester; }
0032 #endif
0033
0034 namespace ipcdetail {
0035
0036 class posix_named_semaphore
0037 {
0038 posix_named_semaphore();
0039 posix_named_semaphore(const posix_named_semaphore&);
0040 posix_named_semaphore &operator= (const posix_named_semaphore &);
0041
0042 public:
0043 posix_named_semaphore
0044 (create_only_t, const char *name, unsigned int initialCount, const permissions &perm = permissions())
0045 { semaphore_open(mp_sem, DoCreate, name, initialCount, perm); }
0046
0047 posix_named_semaphore(open_or_create_t, const char *name, unsigned int initialCount, const permissions &perm = permissions())
0048 { semaphore_open(mp_sem, DoOpenOrCreate, name, initialCount, perm); }
0049
0050 posix_named_semaphore(open_only_t, const char *name)
0051 { semaphore_open(mp_sem, DoOpen, name); }
0052
0053 ~posix_named_semaphore()
0054 {
0055 if(mp_sem != BOOST_INTERPROCESS_POSIX_SEM_FAILED)
0056 semaphore_close(mp_sem);
0057 }
0058
0059 void post()
0060 { semaphore_post(mp_sem); }
0061
0062 void wait()
0063 { semaphore_wait(mp_sem); }
0064
0065 bool try_wait()
0066 { return semaphore_try_wait(mp_sem); }
0067
0068 template<class TimePoint>
0069 bool timed_wait(const TimePoint &abs_time)
0070 { return semaphore_timed_wait(mp_sem, abs_time); }
0071
0072 static bool remove(const char *name)
0073 { return semaphore_unlink(name); }
0074
0075 private:
0076 friend class ipcdetail::interprocess_tester;
0077 void dont_close_on_destruction()
0078 { mp_sem = BOOST_INTERPROCESS_POSIX_SEM_FAILED; }
0079
0080 sem_t *mp_sem;
0081 };
0082
0083 }
0084 }
0085 }
0086
0087 #include <boost/interprocess/detail/config_end.hpp>
0088
0089 #endif