]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/interprocess/include/boost/interprocess/sync/named_condition_any.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / interprocess / include / boost / interprocess / sync / named_condition_any.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2005-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_NAMED_CONDITION_ANY_HPP
12 #define BOOST_INTERPROCESS_NAMED_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 #include <boost/interprocess/detail/config_begin.hpp>
23 #include <boost/interprocess/detail/workaround.hpp>
24 #include <boost/interprocess/creation_tags.hpp>
25 #include <boost/interprocess/exceptions.hpp>
26 #include <boost/interprocess/detail/interprocess_tester.hpp>
27 #include <boost/interprocess/permissions.hpp>
28 #include <boost/interprocess/detail/posix_time_types_wrk.hpp>
29 #include <boost/interprocess/sync/detail/locks.hpp>
30 #if !defined(BOOST_INTERPROCESS_FORCE_GENERIC_EMULATION) && defined (BOOST_INTERPROCESS_WINDOWS)
31 #include <boost/interprocess/sync/windows/named_condition_any.hpp>
32 #define BOOST_INTERPROCESS_USE_WINDOWS
33 #else
34 #include <boost/interprocess/sync/shm/named_condition_any.hpp>
35 #endif
36
37 //!\file
38 //!Describes a named condition class for inter-process synchronization
39
40 namespace boost {
41 namespace interprocess {
42
43 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
44 namespace ipcdetail{ class interprocess_tester; }
45 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
46
47 //! A global condition variable that can be created by name.
48 //! This condition variable is designed to work with named_mutex and
49 //! can't be placed in shared memory or memory mapped files.
50 class named_condition_any
51 {
52 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
53 //Non-copyable
54 named_condition_any();
55 named_condition_any(const named_condition_any &);
56 named_condition_any &operator=(const named_condition_any &);
57 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
58 public:
59 //!Creates a global condition with a name.
60 //!If the condition can't be created throws interprocess_exception
61 named_condition_any(create_only_t, const char *name, const permissions &perm = permissions())
62 : m_cond(create_only_t(), name, perm)
63 {}
64
65 //!Opens or creates a global condition with a name.
66 //!If the condition is created, this call is equivalent to
67 //!named_condition_any(create_only_t, ... )
68 //!If the condition is already created, this call is equivalent
69 //!named_condition_any(open_only_t, ... )
70 //!Does not throw
71 named_condition_any(open_or_create_t, const char *name, const permissions &perm = permissions())
72 : m_cond(open_or_create_t(), name, perm)
73 {}
74
75 //!Opens a global condition with a name if that condition is previously
76 //!created. If it is not previously created this function throws
77 //!interprocess_exception.
78 named_condition_any(open_only_t, const char *name)
79 : m_cond(open_only_t(), name)
80 {}
81
82 //!Destroys *this and indicates that the calling process is finished using
83 //!the resource. The destructor function will deallocate
84 //!any system resources allocated by the system for use by this process for
85 //!this resource. The resource can still be opened again calling
86 //!the open constructor overload. To erase the resource from the system
87 //!use remove().
88 ~named_condition_any()
89 {}
90
91 //!If there is a thread waiting on *this, change that
92 //!thread's state to ready. Otherwise there is no effect.*/
93 void notify_one()
94 { m_cond.notify_one(); }
95
96 //!Change the state of all threads waiting on *this to ready.
97 //!If there are no waiting threads, notify_all() has no effect.
98 void notify_all()
99 { m_cond.notify_all(); }
100
101 //!Releases the lock on the named_mutex object associated with lock, blocks
102 //!the current thread of execution until readied by a call to
103 //!this->notify_one() or this->notify_all(), and then reacquires the lock.
104 template <typename L>
105 void wait(L& lock)
106 { return m_cond.wait(lock); }
107
108 //!The same as:
109 //!while (!pred()) wait(lock)
110 template <typename L, typename Pr>
111 void wait(L& lock, Pr pred)
112 { return m_cond.wait(lock, pred); }
113
114 //!Releases the lock on the named_mutex object associated with lock, blocks
115 //!the current thread of execution until readied by a call to
116 //!this->notify_one() or this->notify_all(), or until time abs_time is reached,
117 //!and then reacquires the lock.
118 //!Returns: false if time abs_time is reached, otherwise true.
119 template <typename L>
120 bool timed_wait(L& lock, const boost::posix_time::ptime &abs_time)
121 { return m_cond.timed_wait(lock, abs_time); }
122
123 //!The same as: while (!pred()) {
124 //! if (!timed_wait(lock, abs_time)) return pred();
125 //! } return true;
126 template <typename L, typename Pr>
127 bool timed_wait(L& lock, const boost::posix_time::ptime &abs_time, Pr pred)
128 { return m_cond.timed_wait(lock, abs_time, pred); }
129
130 //!Erases a named condition from the system.
131 //!Returns false on error. Never throws.
132 static bool remove(const char *name)
133 { return condition_any_type::remove(name); }
134
135 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
136 private:
137 #if defined(BOOST_INTERPROCESS_USE_WINDOWS)
138 typedef ipcdetail::windows_named_condition_any condition_any_type;
139 #else
140 typedef ipcdetail::shm_named_condition_any condition_any_type;
141 #endif
142 condition_any_type m_cond;
143
144 friend class ipcdetail::interprocess_tester;
145 void dont_close_on_destruction()
146 { ipcdetail::interprocess_tester::dont_close_on_destruction(m_cond); }
147 #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
148 };
149
150 } //namespace interprocess
151 } //namespace boost
152
153 #include <boost/interprocess/detail/config_end.hpp>
154
155 #endif // BOOST_INTERPROCESS_NAMED_CONDITION_ANY_HPP