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