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_MUTEX_HPP
0012 #define BOOST_INTERPROCESS_POSIX_NAMED_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/exceptions.hpp>
0026 #include <boost/interprocess/detail/interprocess_tester.hpp>
0027 #include <boost/interprocess/permissions.hpp>
0028
0029 #include <boost/interprocess/sync/posix/named_semaphore.hpp>
0030
0031 namespace boost {
0032 namespace interprocess {
0033 namespace ipcdetail {
0034
0035 class named_condition;
0036
0037 class posix_named_mutex
0038 {
0039 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0040
0041 posix_named_mutex();
0042 posix_named_mutex(const posix_named_mutex &);
0043 posix_named_mutex &operator=(const posix_named_mutex &);
0044 friend class named_condition;
0045 #endif
0046
0047 public:
0048 posix_named_mutex(create_only_t, const char *name, const permissions &perm = permissions());
0049
0050 posix_named_mutex(open_or_create_t, const char *name, const permissions &perm = permissions());
0051
0052 posix_named_mutex(open_only_t, const char *name);
0053
0054 ~posix_named_mutex();
0055
0056 void unlock();
0057 void lock();
0058 bool try_lock();
0059
0060 template<class TimePoint>
0061 bool timed_lock(const TimePoint &abs_time);
0062
0063 template<class TimePoint>
0064 bool try_lock_until(const TimePoint &abs_time)
0065 { return this->timed_lock(abs_time); }
0066
0067 template<class Duration>
0068 bool try_lock_for(const Duration &dur)
0069 { return this->timed_lock(duration_to_ustime(dur)); }
0070
0071 static bool remove(const char *name);
0072
0073 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0074 private:
0075 friend class interprocess_tester;
0076 void dont_close_on_destruction();
0077
0078 posix_named_semaphore m_sem;
0079 #endif
0080 };
0081
0082 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0083
0084 inline posix_named_mutex::posix_named_mutex(create_only_t, const char *name, const permissions &perm)
0085 : m_sem(create_only, name, 1, perm)
0086 {}
0087
0088 inline posix_named_mutex::posix_named_mutex(open_or_create_t, const char *name, const permissions &perm)
0089 : m_sem(open_or_create, name, 1, perm)
0090 {}
0091
0092 inline posix_named_mutex::posix_named_mutex(open_only_t, const char *name)
0093 : m_sem(open_only, name)
0094 {}
0095
0096 inline void posix_named_mutex::dont_close_on_destruction()
0097 { interprocess_tester::dont_close_on_destruction(m_sem); }
0098
0099 inline posix_named_mutex::~posix_named_mutex()
0100 {}
0101
0102 inline void posix_named_mutex::lock()
0103 { m_sem.wait(); }
0104
0105 inline void posix_named_mutex::unlock()
0106 { m_sem.post(); }
0107
0108 inline bool posix_named_mutex::try_lock()
0109 { return m_sem.try_wait(); }
0110
0111 template<class TimePoint>
0112 inline bool posix_named_mutex::timed_lock(const TimePoint &abs_time)
0113 { return m_sem.timed_wait(abs_time); }
0114
0115 inline bool posix_named_mutex::remove(const char *name)
0116 { return posix_named_semaphore::remove(name); }
0117
0118 #endif
0119
0120 }
0121 }
0122 }
0123
0124 #include <boost/interprocess/detail/config_end.hpp>
0125
0126 #endif