queue_base.hpp 6.1 KB

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