Chris@102
|
1 #ifndef BOOST_THREAD_QUEUE_ADAPTOR_HPP
|
Chris@102
|
2 #define BOOST_THREAD_QUEUE_ADAPTOR_HPP
|
Chris@102
|
3
|
Chris@102
|
4 //////////////////////////////////////////////////////////////////////////////
|
Chris@102
|
5 //
|
Chris@102
|
6 // (C) Copyright Vicente J. Botet Escriba 2014. Distributed under the Boost
|
Chris@102
|
7 // Software License, Version 1.0. (See accompanying file
|
Chris@102
|
8 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@102
|
9 //
|
Chris@102
|
10 // See http://www.boost.org/libs/thread for documentation.
|
Chris@102
|
11 //
|
Chris@102
|
12 //////////////////////////////////////////////////////////////////////////////
|
Chris@102
|
13
|
Chris@102
|
14 #include <boost/thread/detail/config.hpp>
|
Chris@102
|
15 #include <boost/thread/detail/move.hpp>
|
Chris@102
|
16 #include <boost/thread/concurrent_queues/queue_op_status.hpp>
|
Chris@102
|
17 #include <boost/thread/concurrent_queues/queue_base.hpp>
|
Chris@102
|
18
|
Chris@102
|
19 #include <boost/config/abi_prefix.hpp>
|
Chris@102
|
20
|
Chris@102
|
21 namespace boost
|
Chris@102
|
22 {
|
Chris@102
|
23 namespace concurrent
|
Chris@102
|
24 {
|
Chris@102
|
25 namespace detail
|
Chris@102
|
26 {
|
Chris@102
|
27
|
Chris@102
|
28 template <typename Queue>
|
Chris@102
|
29 class queue_adaptor_copyable_only :
|
Chris@102
|
30 public boost::queue_base<typename Queue::value_type, typename Queue::size_type>
|
Chris@102
|
31 {
|
Chris@102
|
32 Queue queue;
|
Chris@102
|
33 public:
|
Chris@102
|
34 typedef typename Queue::value_type value_type;
|
Chris@102
|
35 typedef typename Queue::size_type size_type;
|
Chris@102
|
36
|
Chris@102
|
37 // Constructors/Assignment/Destructors
|
Chris@102
|
38 queue_adaptor_copyable_only() {}
|
Chris@102
|
39
|
Chris@102
|
40 // Observers
|
Chris@102
|
41 bool empty() const { return queue.empty(); }
|
Chris@102
|
42 bool full() const { return queue.full(); }
|
Chris@102
|
43 size_type size() const { return queue.size(); }
|
Chris@102
|
44 bool closed() const { return queue.closed(); }
|
Chris@102
|
45
|
Chris@102
|
46 // Modifiers
|
Chris@102
|
47 void close() { queue.close(); }
|
Chris@102
|
48
|
Chris@102
|
49 void push(const value_type& x) { queue.push(x); }
|
Chris@102
|
50
|
Chris@102
|
51 void pull(value_type& x) { queue.pull(x); };
|
Chris@102
|
52 value_type pull() { return queue.pull(); }
|
Chris@102
|
53
|
Chris@102
|
54 queue_op_status try_push(const value_type& x) { return queue.try_push(x); }
|
Chris@102
|
55 queue_op_status try_pull(value_type& x) { return queue.try_pull(x); }
|
Chris@102
|
56
|
Chris@102
|
57 queue_op_status nonblocking_push(const value_type& x) { return queue.nonblocking_push(x); }
|
Chris@102
|
58 queue_op_status nonblocking_pull(value_type& x) { return queue.nonblocking_pull(x); }
|
Chris@102
|
59
|
Chris@102
|
60 queue_op_status wait_push(const value_type& x) { return queue.wait_push(x); }
|
Chris@102
|
61 queue_op_status wait_pull(value_type& x) { return queue.wait_pull(x); }
|
Chris@102
|
62
|
Chris@102
|
63 };
|
Chris@102
|
64 template <typename Queue>
|
Chris@102
|
65 class queue_adaptor_movable_only :
|
Chris@102
|
66 public boost::queue_base<typename Queue::value_type, typename Queue::size_type>
|
Chris@102
|
67 {
|
Chris@102
|
68 Queue queue;
|
Chris@102
|
69 public:
|
Chris@102
|
70 typedef typename Queue::value_type value_type;
|
Chris@102
|
71 typedef typename Queue::size_type size_type;
|
Chris@102
|
72
|
Chris@102
|
73 // Constructors/Assignment/Destructors
|
Chris@102
|
74
|
Chris@102
|
75 queue_adaptor_movable_only() {}
|
Chris@102
|
76
|
Chris@102
|
77 // Observers
|
Chris@102
|
78 bool empty() const { return queue.empty(); }
|
Chris@102
|
79 bool full() const { return queue.full(); }
|
Chris@102
|
80 size_type size() const { return queue.size(); }
|
Chris@102
|
81 bool closed() const { return queue.closed(); }
|
Chris@102
|
82
|
Chris@102
|
83 // Modifiers
|
Chris@102
|
84 void close() { queue.close(); }
|
Chris@102
|
85
|
Chris@102
|
86
|
Chris@102
|
87 void pull(value_type& x) { queue.pull(x); };
|
Chris@102
|
88 // enable_if is_nothrow_copy_movable<value_type>
|
Chris@102
|
89 value_type pull() { return queue.pull(); }
|
Chris@102
|
90
|
Chris@102
|
91 queue_op_status try_pull(value_type& x) { return queue.try_pull(x); }
|
Chris@102
|
92
|
Chris@102
|
93 queue_op_status nonblocking_pull(value_type& x) { return queue.nonblocking_pull(x); }
|
Chris@102
|
94
|
Chris@102
|
95 queue_op_status wait_pull(value_type& x) { return queue.wait_pull(x); }
|
Chris@102
|
96
|
Chris@102
|
97 void push(BOOST_THREAD_RV_REF(value_type) x) { queue.push(boost::move(x)); }
|
Chris@102
|
98 queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push(boost::move(x)); }
|
Chris@102
|
99 queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push(boost::move(x)); }
|
Chris@102
|
100 queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push(boost::move(x)); }
|
Chris@102
|
101 };
|
Chris@102
|
102
|
Chris@102
|
103 template <typename Queue>
|
Chris@102
|
104 class queue_adaptor_copyable_and_movable :
|
Chris@102
|
105 public boost::queue_base<typename Queue::value_type, typename Queue::size_type>
|
Chris@102
|
106 {
|
Chris@102
|
107 Queue queue;
|
Chris@102
|
108 public:
|
Chris@102
|
109 typedef typename Queue::value_type value_type;
|
Chris@102
|
110 typedef typename Queue::size_type size_type;
|
Chris@102
|
111
|
Chris@102
|
112 // Constructors/Assignment/Destructors
|
Chris@102
|
113
|
Chris@102
|
114 queue_adaptor_copyable_and_movable() {}
|
Chris@102
|
115
|
Chris@102
|
116 // Observers
|
Chris@102
|
117 bool empty() const { return queue.empty(); }
|
Chris@102
|
118 bool full() const { return queue.full(); }
|
Chris@102
|
119 size_type size() const { return queue.size(); }
|
Chris@102
|
120 bool closed() const { return queue.closed(); }
|
Chris@102
|
121
|
Chris@102
|
122 // Modifiers
|
Chris@102
|
123 void close() { queue.close(); }
|
Chris@102
|
124
|
Chris@102
|
125
|
Chris@102
|
126 void push(const value_type& x) { queue.push(x); }
|
Chris@102
|
127
|
Chris@102
|
128 void pull(value_type& x) { queue.pull(x); };
|
Chris@102
|
129 // enable_if is_nothrow_copy_movable<value_type>
|
Chris@102
|
130 value_type pull() { return queue.pull(); }
|
Chris@102
|
131
|
Chris@102
|
132 queue_op_status try_push(const value_type& x) { return queue.try_push(x); }
|
Chris@102
|
133 queue_op_status try_pull(value_type& x) { return queue.try_pull(x); }
|
Chris@102
|
134
|
Chris@102
|
135 queue_op_status nonblocking_push(const value_type& x) { return queue.nonblocking_push(x); }
|
Chris@102
|
136 queue_op_status nonblocking_pull(value_type& x) { return queue.nonblocking_pull(x); }
|
Chris@102
|
137
|
Chris@102
|
138 queue_op_status wait_push(const value_type& x) { return queue.wait_push(x); }
|
Chris@102
|
139 queue_op_status wait_pull(value_type& x) { return queue.wait_pull(x); }
|
Chris@102
|
140
|
Chris@102
|
141 void push(BOOST_THREAD_RV_REF(value_type) x) { queue.push(boost::move(x)); }
|
Chris@102
|
142 queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push(boost::move(x)); }
|
Chris@102
|
143 queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push(boost::move(x)); }
|
Chris@102
|
144 queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push(boost::move(x)); }
|
Chris@102
|
145 };
|
Chris@102
|
146
|
Chris@102
|
147
|
Chris@102
|
148 template <class Q, class T,
|
Chris@102
|
149 #if ! defined BOOST_NO_CXX11_RVALUE_REFERENCES
|
Chris@102
|
150 #if defined __GNUC__ && ! defined __clang__
|
Chris@102
|
151 #if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5) || !defined(__GXX_EXPERIMENTAL_CXX0X__)
|
Chris@102
|
152 bool Copyable = is_copy_constructible<T>::value,
|
Chris@102
|
153 bool Movable = true
|
Chris@102
|
154 #else
|
Chris@102
|
155 bool Copyable = std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value,
|
Chris@102
|
156 bool Movable = std::is_move_constructible<T>::value && std::is_move_assignable<T>::value
|
Chris@102
|
157 #endif // __GNUC__
|
Chris@102
|
158 #elif defined _MSC_VER
|
Chris@102
|
159 #if _MSC_VER < 1700
|
Chris@102
|
160 bool Copyable = is_copy_constructible<T>::value,
|
Chris@102
|
161 bool Movable = true
|
Chris@102
|
162 #else
|
Chris@102
|
163 bool Copyable = std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value,
|
Chris@102
|
164 bool Movable = std::is_move_constructible<T>::value && std::is_move_assignable<T>::value
|
Chris@102
|
165 #endif // _MSC_VER
|
Chris@102
|
166 #else
|
Chris@102
|
167 bool Copyable = std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value,
|
Chris@102
|
168 bool Movable = std::is_move_constructible<T>::value && std::is_move_assignable<T>::value
|
Chris@102
|
169 #endif
|
Chris@102
|
170 #else
|
Chris@102
|
171 bool Copyable = is_copy_constructible<T>::value,
|
Chris@102
|
172 bool Movable = has_move_emulation_enabled<T>::value
|
Chris@102
|
173 #endif
|
Chris@102
|
174 >
|
Chris@102
|
175 struct queue_adaptor;
|
Chris@102
|
176
|
Chris@102
|
177 template <class Q, class T>
|
Chris@102
|
178 struct queue_adaptor<Q, T, true, true> {
|
Chris@102
|
179 typedef queue_adaptor_copyable_and_movable<Q> type;
|
Chris@102
|
180 };
|
Chris@102
|
181 template <class Q, class T>
|
Chris@102
|
182 struct queue_adaptor<Q, T, true, false> {
|
Chris@102
|
183 typedef queue_adaptor_copyable_only<Q> type;
|
Chris@102
|
184 };
|
Chris@102
|
185 template <class Q, class T>
|
Chris@102
|
186 struct queue_adaptor<Q, T, false, true> {
|
Chris@102
|
187 typedef queue_adaptor_movable_only<Q> type;
|
Chris@102
|
188 };
|
Chris@102
|
189
|
Chris@102
|
190 }
|
Chris@102
|
191
|
Chris@102
|
192 template <typename Queue>
|
Chris@102
|
193 class queue_adaptor :
|
Chris@102
|
194 public detail::queue_adaptor<Queue, typename Queue::value_type>::type
|
Chris@102
|
195 {
|
Chris@102
|
196 public:
|
Chris@102
|
197 typedef typename Queue::value_type value_type;
|
Chris@102
|
198 typedef typename Queue::size_type size_type;
|
Chris@102
|
199 // Constructors/Assignment/Destructors
|
Chris@102
|
200 virtual ~queue_adaptor() {};
|
Chris@102
|
201 };
|
Chris@102
|
202 }
|
Chris@102
|
203 using concurrent::queue_adaptor;
|
Chris@102
|
204
|
Chris@102
|
205 }
|
Chris@102
|
206
|
Chris@102
|
207 #include <boost/config/abi_suffix.hpp>
|
Chris@102
|
208
|
Chris@102
|
209 #endif
|