]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/interprocess/sync/interprocess_condition_any.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / interprocess / sync / interprocess_condition_any.hpp
CommitLineData
7c673cae
FG
1//////////////////////////////////////////////////////////////////////////////
2//
3// (C) Copyright Ion Gaztanaga 2012-2012. Distributed under the Boost
4// Software License, Version 1.0. (See accompanying file
5// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6//
7// See http://www.boost.org/libs/interprocess for documentation.
8//
9//////////////////////////////////////////////////////////////////////////////
10
11#ifndef BOOST_INTERPROCESS_CONDITION_ANY_HPP
12#define BOOST_INTERPROCESS_CONDITION_ANY_HPP
13
14#ifndef BOOST_CONFIG_HPP
15# include <boost/config.hpp>
16#endif
17#
18#if defined(BOOST_HAS_PRAGMA_ONCE)
19# pragma once
20#endif
21
22#if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
23
24#include <boost/interprocess/detail/config_begin.hpp>
25#include <boost/interprocess/detail/workaround.hpp>
26
1e59de90 27#include <boost/interprocess/sync/cv_status.hpp>
7c673cae
FG
28#include <boost/interprocess/sync/interprocess_mutex.hpp>
29#include <boost/interprocess/sync/interprocess_condition.hpp>
30#include <boost/interprocess/exceptions.hpp>
31#include <boost/interprocess/sync/detail/condition_any_algorithm.hpp>
32
33#endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
34
35//!\file
36//!Describes process-shared variables interprocess_condition_any class
37
38namespace boost {
7c673cae
FG
39namespace interprocess {
40
41//!This class is a condition variable that can be placed in shared memory or
42//!memory mapped files.
43//!
44//!The interprocess_condition_any class is a generalization of interprocess_condition.
45//!Whereas interprocess_condition works only on Locks with mutex_type == interprocess_mutex
46//!interprocess_condition_any can operate on any user-defined lock that meets the BasicLockable
47//!requirements (lock()/unlock() member functions).
48//!
49//!Unlike std::condition_variable_any in C++11, it is NOT safe to invoke the destructor if all
50//!threads have been only notified. It is required that they have exited their respective wait
51//!functions.
52class interprocess_condition_any
53{
54 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
55 //Non-copyable
56 interprocess_condition_any(const interprocess_condition_any &);
57 interprocess_condition_any &operator=(const interprocess_condition_any &);
58
59 class members
60 {
61 public:
62 typedef interprocess_condition condvar_type;
63 typedef interprocess_mutex mutex_type;
64
65 condvar_type &get_condvar() { return m_cond; }
66 mutex_type &get_mutex() { return m_mut; }
67
68 private:
69 condvar_type m_cond;
70 mutex_type m_mut;
71 };
72
73 ipcdetail::condition_any_wrapper<members> m_cond;
74
75 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
76 public:
77 //!Constructs a interprocess_condition_any. On error throws interprocess_exception.
78 interprocess_condition_any(){}
79
80 //!Destroys *this
81 //!liberating system resources.
82 ~interprocess_condition_any(){}
83
84 //!If there is a thread waiting on *this, change that
85 //!thread's state to ready. Otherwise there is no effect.
86 void notify_one()
87 { m_cond.notify_one(); }
88
89 //!Change the state of all threads waiting on *this to ready.
90 //!If there are no waiting threads, notify_all() has no effect.
91 void notify_all()
92 { m_cond.notify_all(); }
93
94 //!Releases the lock on the interprocess_mutex object associated with lock, blocks
95 //!the current thread of execution until readied by a call to
96 //!this->notify_one() or this->notify_all(), and then reacquires the lock.
97 template <typename L>
98 void wait(L& lock)
99 { m_cond.wait(lock); }
100
101 //!The same as:
102 //!while (!pred()) wait(lock)
103 template <typename L, typename Pr>
104 void wait(L& lock, Pr pred)
105 { m_cond.wait(lock, pred); }
106
107 //!Releases the lock on the interprocess_mutex object associated with lock, blocks
108 //!the current thread of execution until readied by a call to
109 //!this->notify_one() or this->notify_all(), or until time abs_time is reached,
110 //!and then reacquires the lock.
111 //!Returns: false if time abs_time is reached, otherwise true.
1e59de90
TL
112 template <typename L, class TimePoint>
113 bool timed_wait(L& lock, const TimePoint &abs_time)
7c673cae
FG
114 { return m_cond.timed_wait(lock, abs_time); }
115
116 //!The same as: while (!pred()) {
117 //! if (!timed_wait(lock, abs_time)) return pred();
118 //! } return true;
1e59de90
TL
119 template <typename L, class TimePoint, typename Pr>
120 bool timed_wait(L& lock, const TimePoint &abs_time, Pr pred)
7c673cae 121 { return m_cond.timed_wait(lock, abs_time, pred); }
1e59de90
TL
122
123 //!Same as `timed_wait`, but this function is modeled after the
124 //!standard library interface.
125 template <typename L, class TimePoint>
126 cv_status wait_until(L& lock, const TimePoint &abs_time)
127 { return this->timed_wait(lock, abs_time) ? cv_status::no_timeout : cv_status::timeout; }
128
129 //!Same as `timed_wait`, but this function is modeled after the
130 //!standard library interface.
131 template <typename L, class TimePoint, typename Pr>
132 bool wait_until(L& lock, const TimePoint &abs_time, Pr pred)
133 { return this->timed_wait(lock, abs_time, pred); }
134
135 //!Same as `timed_wait`, but this function is modeled after the
136 //!standard library interface and uses relative timeouts.
137 template <typename L, class Duration>
138 cv_status wait_for(L& lock, const Duration &dur)
139 { return this->wait_until(lock, ipcdetail::duration_to_ustime(dur)); }
140
141 //!Same as `timed_wait`, but this function is modeled after the
142 //!standard library interface and uses relative timeouts
143 template <typename L, class Duration, typename Pr>
144 bool wait_for(L& lock, const Duration &dur, Pr pred)
145 { return this->wait_until(lock, ipcdetail::duration_to_ustime(dur), pred); }
7c673cae
FG
146};
147
148} //namespace interprocess
149} // namespace boost
150
151#include <boost/interprocess/detail/config_end.hpp>
152
153#endif // BOOST_INTERPROCESS_CONDITION_ANY_HPP