diff --git a/example/producer_consumer.cpp b/example/producer_consumer.cpp index 47003c356..51979b6c7 100644 --- a/example/producer_consumer.cpp +++ b/example/producer_consumer.cpp @@ -22,17 +22,17 @@ typedef std::ostream the_ostream; typedef std::istream the_istream; #endif -#include +#include -void producer(the_ostream &mos, boost::sync_deque & sbq) +void producer(the_ostream &mos, boost::sync_queue & sbq) { using namespace boost; try { for(int i=0; ;++i) { - sbq.push_back(i); + sbq.push(i); //sbq << i; - mos << "push_back(" << i << ") "<< sbq.size()<<"\n"; + mos << "push(" << i << ") "<< sbq.size()<<"\n"; this_thread::sleep_for(chrono::milliseconds(200)); } } @@ -48,14 +48,14 @@ void producer(the_ostream &mos, boost::sync_deque & sbq) void consumer( the_ostream &mos, - boost::sync_deque & sbq) + boost::sync_queue & sbq) { using namespace boost; try { for(int i=0; ;++i) { int r; - sbq.pull_front(r); + sbq.pull(r); //sbq >> r; mos << i << " pull(" << r << ") "<< sbq.size()<<"\n"; @@ -71,14 +71,14 @@ void consumer( mos << "exception !!!\n"; } } -void consumer2(the_ostream &mos, boost::sync_deque & sbq) +void consumer2(the_ostream &mos, boost::sync_queue & sbq) { using namespace boost; try { for(int i=0; ;++i) { int r; - queue_op_status st = sbq.try_pull_front(r); + queue_op_status st = sbq.try_pull(r); if (queue_op_status::closed == st) break; if (queue_op_status::success == st) { mos << i << " pull(" << r << ")\n"; @@ -91,16 +91,16 @@ void consumer2(the_ostream &mos, boost::sync_deque & sbq) mos << "exception !!!\n"; } } -void consumer3(the_ostream &mos, boost::sync_deque & sbq) +void consumer3(the_ostream &mos, boost::sync_queue & sbq) { using namespace boost; try { for(int i=0; ;++i) { int r; - queue_op_status res = sbq.wait_pull_front(r); + queue_op_status res = sbq.wait_pull(r); if (res==queue_op_status::closed) break; - mos << i << " wait_pull_front(" << r << ")\n"; + mos << i << " wait_pull(" << r << ")\n"; this_thread::sleep_for(chrono::milliseconds(250)); } } @@ -126,7 +126,7 @@ int main() //the_istream &mcin = std::cin; #endif - sync_deque sbq; + sync_queue sbq; { mcout << "begin of main" << std::endl; diff --git a/example/producer_consumer2.cpp b/example/producer_consumer2.cpp index a96568abd..9e3ad976c 100644 --- a/example/producer_consumer2.cpp +++ b/example/producer_consumer2.cpp @@ -21,7 +21,7 @@ typedef std::ostream the_ostream; typedef std::istream the_istream; #endif -#include +#include #include #include #include @@ -129,7 +129,7 @@ int main() //the_istream &mcin = std::cin; #endif - queue_adaptor > sbq; + queue_adaptor > sbq; { mcout << "begin of main" << std::endl; diff --git a/include/boost/thread/concurrent_queues/deque_adaptor.hpp b/include/boost/thread/concurrent_queues/deque_adaptor.hpp new file mode 100644 index 000000000..2dca03bfa --- /dev/null +++ b/include/boost/thread/concurrent_queues/deque_adaptor.hpp @@ -0,0 +1,209 @@ +#ifndef BOOST_THREAD_CONCURRENT_DEQUE_ADAPTOR_HPP +#define BOOST_THREAD_CONCURRENT_DEQUE_ADAPTOR_HPP + +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Vicente J. Botet Escriba 2014. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/thread for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include + +#include + +namespace boost +{ +namespace concurrent +{ +namespace detail +{ + + template + class deque_adaptor_copyable_only : + public boost::deque_base + { + Queue queue; + public: + typedef typename Queue::value_type value_type; + typedef std::size_t size_type; + + // Constructors/Assignment/Destructors + deque_adaptor_copyable_only() {} + + // Observers + bool empty() const { return queue.empty(); } + bool full() const { return queue.full(); } + size_type size() const { return queue.size(); } + bool closed() const { return queue.closed(); } + + // Modifiers + void close() { queue.close(); } + + void push_back(const value_type& x) { queue.push_back(x); } + + void pull_front(value_type& x) { queue.pull_front(x); }; + value_type pull_front() { return queue.pull_front(); } + + queue_op_status try_push_back(const value_type& x) { return queue.try_push_back(x); } + queue_op_status try_pull_front(value_type& x) { return queue.try_pull_front(x); } + + queue_op_status nonblocking_push_back(const value_type& x) { return queue.nonblocking_push_back(x); } + queue_op_status nonblocking_pull_front(value_type& x) { return queue.nonblocking_pull_front(x); } + + queue_op_status wait_push_back(const value_type& x) { return queue.wait_push_back(x); } + queue_op_status wait_pull_front(value_type& x) { return queue.wait_pull_front(x); } + + }; + template + class deque_adaptor_movable_only : + public boost::deque_base + { + Queue queue; + public: + typedef typename Queue::value_type value_type; + typedef std::size_t size_type; + + // Constructors/Assignment/Destructors + + deque_adaptor_movable_only() {} + + // Observers + bool empty() const { return queue.empty(); } + bool full() const { return queue.full(); } + size_type size() const { return queue.size(); } + bool closed() const { return queue.closed(); } + + // Modifiers + void close() { queue.close(); } + + + void pull_front(value_type& x) { queue.pull_front(x); }; + // enable_if is_nothrow_copy_movable + value_type pull_front() { return queue.pull_front(); } + + queue_op_status try_pull_front(value_type& x) { return queue.try_pull_front(x); } + + queue_op_status nonblocking_pull_front(value_type& x) { return queue.nonblocking_pull_front(x); } + + queue_op_status wait_pull_front(value_type& x) { return queue.wait_pull_front(x); } + + void push_back(BOOST_THREAD_RV_REF(value_type) x) { queue.push_back(boost::move(x)); } + queue_op_status try_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push_back(boost::move(x)); } + queue_op_status nonblocking_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push_back(boost::move(x)); } + queue_op_status wait_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push_back(boost::move(x)); } + }; + + template + class deque_adaptor_copyable_and_movable : + public boost::deque_base + { + Queue queue; + public: + typedef typename Queue::value_type value_type; + typedef std::size_t size_type; + + // Constructors/Assignment/Destructors + + deque_adaptor_copyable_and_movable() {} + + // Observers + bool empty() const { return queue.empty(); } + bool full() const { return queue.full(); } + size_type size() const { return queue.size(); } + bool closed() const { return queue.closed(); } + + // Modifiers + void close() { queue.close(); } + + + void push_back(const value_type& x) { queue.push_back(x); } + + void pull_front(value_type& x) { queue.pull_front(x); }; + // enable_if is_nothrow_copy_movable + value_type pull_front() { return queue.pull_front(); } + + queue_op_status try_push_back(const value_type& x) { return queue.try_push_back(x); } + queue_op_status try_pull_front(value_type& x) { return queue.try_pull_front(x); } + + queue_op_status nonblocking_push_back(const value_type& x) { return queue.nonblocking_push_back(x); } + queue_op_status nonblocking_pull_front(value_type& x) { return queue.nonblocking_pull_front(x); } + + queue_op_status wait_push_back(const value_type& x) { return queue.wait_push_back(x); } + queue_op_status wait_pull_front(value_type& x) { return queue.wait_pull_front(x); } + + void push_back(BOOST_THREAD_RV_REF(value_type) x) { queue.push_back(boost::move(x)); } + queue_op_status try_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push_back(boost::move(x)); } + queue_op_status nonblocking_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push_back(boost::move(x)); } + queue_op_status wait_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push_back(boost::move(x)); } + }; + + + template ::value, + bool Movable = true +#else + bool Copyable = std::is_copy_constructible::value && std::is_copy_assignable::value, + bool Movable = std::is_move_constructible::value && std::is_move_assignable::value +#endif // __GNUC__ +#elif defined _MSC_VER +#if _MSC_VER < 1700 + bool Copyable = is_copy_constructible::value, + bool Movable = true +#else + bool Copyable = std::is_copy_constructible::value && std::is_copy_assignable::value, + bool Movable = std::is_move_constructible::value && std::is_move_assignable::value +#endif // _MSC_VER +#else + bool Copyable = std::is_copy_constructible::value && std::is_copy_assignable::value, + bool Movable = std::is_move_constructible::value && std::is_move_assignable::value +#endif +#else + bool Copyable = is_copy_constructible::value, + bool Movable = has_move_emulation_enabled::value +#endif + > + struct deque_adaptor; + + template + struct deque_adaptor { + typedef deque_adaptor_copyable_and_movable type; + }; + template + struct deque_adaptor { + typedef deque_adaptor_copyable_only type; + }; + template + struct deque_adaptor { + typedef deque_adaptor_movable_only type; + }; + +} + + template + class deque_adaptor : + public detail::deque_adaptor::type + { + public: + typedef typename Queue::value_type value_type; + typedef std::size_t size_type; + // Constructors/Assignment/Destructors + virtual ~deque_adaptor() {}; + }; +} +using concurrent::deque_adaptor; + +} + +#include + +#endif diff --git a/include/boost/thread/concurrent_queues/deque_base.hpp b/include/boost/thread/concurrent_queues/deque_base.hpp new file mode 100644 index 000000000..9bc9cdd61 --- /dev/null +++ b/include/boost/thread/concurrent_queues/deque_base.hpp @@ -0,0 +1,202 @@ +#ifndef BOOST_THREAD_CONCURRENT_DEQUE_BASE_HPP +#define BOOST_THREAD_CONCURRENT_DEQUE_BASE_HPP + +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Vicente J. Botet Escriba 2014. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/thread for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + + +#include + +namespace boost +{ +namespace concurrent +{ +namespace detail +{ + + template + class deque_base_copyable_only + { + public: + typedef ValueType value_type; + typedef std::size_t size_type; + + // Constructors/Assignment/Destructors + virtual ~deque_base_copyable_only() {}; + + // Observers + virtual bool empty() const = 0; + virtual bool full() const = 0; + virtual size_type size() const = 0; + virtual bool closed() const = 0; + + // Modifiers + virtual void close() = 0; + + virtual void push_back(const value_type& x) = 0; + + virtual void pull_front(value_type&) = 0; + virtual value_type pull_front() = 0; + + virtual queue_op_status try_push_back(const value_type& x) = 0; + virtual queue_op_status try_pull_front(value_type&) = 0; + + virtual queue_op_status nonblocking_push_back(const value_type& x) = 0; + virtual queue_op_status nonblocking_pull_front(value_type&) = 0; + + virtual queue_op_status wait_push_back(const value_type& x) = 0; + virtual queue_op_status wait_pull_front(ValueType& elem) = 0; + + }; + + template + class deque_base_movable_only + { + public: + typedef ValueType value_type; + typedef std::size_t size_type; + // Constructors/Assignment/Destructors + virtual ~deque_base_movable_only() {}; + + // Observers + virtual bool empty() const = 0; + virtual bool full() const = 0; + virtual size_type size() const = 0; + virtual bool closed() const = 0; + + // Modifiers + virtual void close() = 0; + + virtual void pull_front(value_type&) = 0; + // enable_if is_nothrow_movable + virtual value_type pull_front() = 0; + + virtual queue_op_status try_pull_front(value_type&) = 0; + + virtual queue_op_status nonblocking_pull_front(value_type&) = 0; + + virtual queue_op_status wait_pull_front(ValueType& elem) = 0; + + virtual void push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; + virtual queue_op_status try_push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; + virtual queue_op_status nonblocking_push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; + virtual queue_op_status wait_push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; + }; + + + template + class deque_base_copyable_and_movable + { + public: + typedef ValueType value_type; + typedef std::size_t size_type; + // Constructors/Assignment/Destructors + virtual ~deque_base_copyable_and_movable() {}; + + + // Observers + virtual bool empty() const = 0; + virtual bool full() const = 0; + virtual size_type size() const = 0; + virtual bool closed() const = 0; + + // Modifiers + virtual void close() = 0; + + virtual void push_back(const value_type& x) = 0; + + virtual void pull_front(value_type&) = 0; + // enable_if is_nothrow_copy_movable + virtual value_type pull_front() = 0; + + virtual queue_op_status try_push_back(const value_type& x) = 0; + virtual queue_op_status try_pull_front(value_type&) = 0; + + virtual queue_op_status nonblocking_push_back(const value_type& x) = 0; + virtual queue_op_status nonblocking_pull_front(value_type&) = 0; + + virtual queue_op_status wait_push_back(const value_type& x) = 0; + virtual queue_op_status wait_pull_front(ValueType& elem) = 0; + + virtual void push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; + virtual queue_op_status try_push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; + virtual queue_op_status nonblocking_push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; + virtual queue_op_status wait_push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; + }; + + template ::value, + bool Movable = true +#else + bool Copyable = std::is_copy_constructible::value && std::is_copy_assignable::value, + bool Movable = std::is_move_constructible::value && std::is_move_assignable::value +#endif // __GNUC__ +#elif defined _MSC_VER +#if _MSC_VER < 1700 + bool Copyable = is_copy_constructible::value, + bool Movable = true +#else + bool Copyable = std::is_copy_constructible::value && std::is_copy_assignable::value, + bool Movable = std::is_move_constructible::value && std::is_move_assignable::value +#endif // _MSC_VER +#else + bool Copyable = std::is_copy_constructible::value && std::is_copy_assignable::value, + bool Movable = std::is_move_constructible::value && std::is_move_assignable::value +#endif +#else + bool Copyable = is_copy_constructible::value, + bool Movable = has_move_emulation_enabled::value +#endif + > + struct deque_base; + + template + struct deque_base { + typedef deque_base_copyable_and_movable type; + }; + template + struct deque_base { + typedef deque_base_copyable_only type; + }; + template + struct deque_base { + typedef deque_base_movable_only type; + }; + +} + + template + class deque_base : + public detail::deque_base::type + { + public: + typedef ValueType value_type; + typedef std::size_t size_type; + // Constructors/Assignment/Destructors + virtual ~deque_base() {}; + }; + +} +using concurrent::deque_base; + +} + +#include + +#endif diff --git a/include/boost/thread/concurrent_queues/deque_views.hpp b/include/boost/thread/concurrent_queues/deque_views.hpp new file mode 100644 index 000000000..5715fb88c --- /dev/null +++ b/include/boost/thread/concurrent_queues/deque_views.hpp @@ -0,0 +1,165 @@ +#ifndef BOOST_THREAD_QUEUE_VIEWS_HPP +#define BOOST_THREAD_QUEUE_VIEWS_HPP + +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Vicente J. Botet Escriba 2014. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/thread for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include + +#include + +namespace boost +{ +namespace concurrent +{ + + template + class deque_back_view + { + Queue* queue; + public: + typedef typename Queue::value_type value_type; + typedef typename Queue::size_type size_type; + + // Constructors/Assignment/Destructors + deque_back_view(Queue& q) BOOST_NOEXCEPT : queue(&q) {} + + // Observers + bool empty() const { return queue->empty(); } + bool full() const { return queue->full(); } + size_type size() const { return queue->size(); } + bool closed() const { return queue->closed(); } + + // Modifiers + void close() { queue->close(); } + + void push(const value_type& x) { queue->push_back(x); } + + void pull(value_type& x) { queue->pull_back(x); } + // enable_if is_nothrow_copy_movable + value_type pull() { return queue->pull_back(); } + + queue_op_status try_push(const value_type& x) { return queue->try_push_back(x); } + + queue_op_status try_pull(value_type& x) { return queue->try_pull_back(x); } + + queue_op_status nonblocking_push(const value_type& x) { return queue->nonblocking_push_back(x); } + + queue_op_status nonblocking_pull(value_type& x) { return queue->nonblocking_pull_back(x); } + + queue_op_status wait_push(const value_type& x) { return queue->wait_push_back(x); } + queue_op_status wait_pull(value_type& x) { return queue->wait_pull_back(x); } + + void push(BOOST_THREAD_RV_REF(value_type) x) { queue->push_back(boost::move(x)); } + queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->try_push_back(boost::move(x)); } + queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->nonblocking_push_back(boost::move(x)); } + queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->wait_push_back(boost::move(x)); } + }; + + template + class deque_front_view + { + Queue* queue; + public: + typedef typename Queue::value_type value_type; + typedef typename Queue::size_type size_type; + + // Constructors/Assignment/Destructors + deque_front_view(Queue& q) BOOST_NOEXCEPT : queue(&q) {} + + // Observers + bool empty() const { return queue->empty(); } + bool full() const { return queue->full(); } + size_type size() const { return queue->size(); } + bool closed() const { return queue->closed(); } + + // Modifiers + void close() { queue->close(); } + + void push(const value_type& x) { queue->push_front(x); } + + void pull(value_type& x) { queue->pull_front(x); }; + // enable_if is_nothrow_copy_movable + value_type pull() { return queue->pull_front(); } + + queue_op_status try_push(const value_type& x) { return queue->try_push_front(x); } + + queue_op_status try_pull(value_type& x) { return queue->try_pull_front(x); } + + queue_op_status nonblocking_push(const value_type& x) { return queue->nonblocking_push_front(x); } + + queue_op_status nonblocking_pull(value_type& x) { return queue->nonblocking_pull_front(x); } + + queue_op_status wait_push(const value_type& x) { return queue->wait_push_front(x); } + queue_op_status wait_pull(value_type& x) { return queue->wait_pull_front(x); } + void push(BOOST_THREAD_RV_REF(value_type) x) { queue->push_front(forward(x)); } + queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->try_push_front(forward(x)); } + queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->nonblocking_push_front(forward(x)); } + queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->wait_push_front(forward(x)); } + + }; + +#if ! defined BOOST_NO_CXX11_TEMPLATE_ALIASES + + template + using deque_back = deque_back_view > ; + template + using deque_front = deque_front_view > ; + +#else + + template + struct deque_back : deque_back_view > + { + typedef deque_back_view > base_type; + deque_back(deque_base& q) BOOST_NOEXCEPT : base_type(q) {} + }; + template + struct deque_front : deque_front_view > + { + typedef deque_front_view > base_type; + deque_front(deque_base& q) BOOST_NOEXCEPT : base_type(q) {} + + }; + +#endif + +// template +// deque_back_view back(Queue & q) { return deque_back_view(q); } +// template +// deque_front_view front(Queue & q) { return deque_front_view(q); } +//#if 0 +// template +// deque_back back(deque_base & q) { return deque_back(q); } +// template +// deque_front front(deque_base & q) { return deque_front(q); } +//#else +// template +// typename deque_back::type back(deque_base & q) { return typename deque_back::type(q); } +// template +// typename deque_front::type front(deque_base & q) { return typename deque_front::type(q); } +//#endif +} + +using concurrent::deque_back_view; +using concurrent::deque_front_view; +using concurrent::deque_back; +using concurrent::deque_front; +//using concurrent::back; +//using concurrent::front; + +} + +#include + +#endif diff --git a/include/boost/thread/concurrent_queues/queue_adaptor.hpp b/include/boost/thread/concurrent_queues/queue_adaptor.hpp index c729276f9..79286d0c8 100644 --- a/include/boost/thread/concurrent_queues/queue_adaptor.hpp +++ b/include/boost/thread/concurrent_queues/queue_adaptor.hpp @@ -46,19 +46,19 @@ namespace detail // Modifiers void close() { queue.close(); } - void push_back(const value_type& x) { queue.push_back(x); } + void push(const value_type& x) { queue.push(x); } - void pull_front(value_type& x) { queue.pull_front(x); }; - value_type pull_front() { return queue.pull_front(); } + void pull(value_type& x) { queue.pull(x); }; + value_type pull() { return queue.pull(); } - queue_op_status try_push_back(const value_type& x) { return queue.try_push_back(x); } - queue_op_status try_pull_front(value_type& x) { return queue.try_pull_front(x); } + queue_op_status try_push(const value_type& x) { return queue.try_push(x); } + queue_op_status try_pull(value_type& x) { return queue.try_pull(x); } - queue_op_status nonblocking_push_back(const value_type& x) { return queue.nonblocking_push_back(x); } - queue_op_status nonblocking_pull_front(value_type& x) { return queue.nonblocking_pull_front(x); } + queue_op_status nonblocking_push(const value_type& x) { return queue.nonblocking_push(x); } + queue_op_status nonblocking_pull(value_type& x) { return queue.nonblocking_pull(x); } - queue_op_status wait_push_back(const value_type& x) { return queue.wait_push_back(x); } - queue_op_status wait_pull_front(value_type& x) { return queue.wait_pull_front(x); } + queue_op_status wait_push(const value_type& x) { return queue.wait_push(x); } + queue_op_status wait_pull(value_type& x) { return queue.wait_pull(x); } }; template @@ -84,20 +84,20 @@ namespace detail void close() { queue.close(); } - void pull_front(value_type& x) { queue.pull_front(x); }; + void pull(value_type& x) { queue.pull(x); }; // enable_if is_nothrow_copy_movable - value_type pull_front() { return queue.pull_front(); } + value_type pull() { return queue.pull(); } - queue_op_status try_pull_front(value_type& x) { return queue.try_pull_front(x); } + queue_op_status try_pull(value_type& x) { return queue.try_pull(x); } - queue_op_status nonblocking_pull_front(value_type& x) { return queue.nonblocking_pull_front(x); } + queue_op_status nonblocking_pull(value_type& x) { return queue.nonblocking_pull(x); } - queue_op_status wait_pull_front(value_type& x) { return queue.wait_pull_front(x); } + queue_op_status wait_pull(value_type& x) { return queue.wait_pull(x); } - void push_back(BOOST_THREAD_RV_REF(value_type) x) { queue.push_back(boost::move(x)); } - queue_op_status try_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push_back(boost::move(x)); } - queue_op_status nonblocking_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push_back(boost::move(x)); } - queue_op_status wait_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push_back(boost::move(x)); } + void push(BOOST_THREAD_RV_REF(value_type) x) { queue.push(boost::move(x)); } + queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push(boost::move(x)); } + queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push(boost::move(x)); } + queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push(boost::move(x)); } }; template @@ -123,25 +123,25 @@ namespace detail void close() { queue.close(); } - void push_back(const value_type& x) { queue.push_back(x); } + void push(const value_type& x) { queue.push(x); } - void pull_front(value_type& x) { queue.pull_front(x); }; + void pull(value_type& x) { queue.pull(x); }; // enable_if is_nothrow_copy_movable - value_type pull_front() { return queue.pull_front(); } + value_type pull() { return queue.pull(); } - queue_op_status try_push_back(const value_type& x) { return queue.try_push_back(x); } - queue_op_status try_pull_front(value_type& x) { return queue.try_pull_front(x); } + queue_op_status try_push(const value_type& x) { return queue.try_push(x); } + queue_op_status try_pull(value_type& x) { return queue.try_pull(x); } - queue_op_status nonblocking_push_back(const value_type& x) { return queue.nonblocking_push_back(x); } - queue_op_status nonblocking_pull_front(value_type& x) { return queue.nonblocking_pull_front(x); } + queue_op_status nonblocking_push(const value_type& x) { return queue.nonblocking_push(x); } + queue_op_status nonblocking_pull(value_type& x) { return queue.nonblocking_pull(x); } - queue_op_status wait_push_back(const value_type& x) { return queue.wait_push_back(x); } - queue_op_status wait_pull_front(value_type& x) { return queue.wait_pull_front(x); } + queue_op_status wait_push(const value_type& x) { return queue.wait_push(x); } + queue_op_status wait_pull(value_type& x) { return queue.wait_pull(x); } - void push_back(BOOST_THREAD_RV_REF(value_type) x) { queue.push_back(boost::move(x)); } - queue_op_status try_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push_back(boost::move(x)); } - queue_op_status nonblocking_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push_back(boost::move(x)); } - queue_op_status wait_push_back(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push_back(boost::move(x)); } + void push(BOOST_THREAD_RV_REF(value_type) x) { queue.push(boost::move(x)); } + queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.try_push(boost::move(x)); } + queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.nonblocking_push(boost::move(x)); } + queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue.wait_push(boost::move(x)); } }; diff --git a/include/boost/thread/concurrent_queues/queue_base.hpp b/include/boost/thread/concurrent_queues/queue_base.hpp index 5ed14fd39..fce6d18da 100755 --- a/include/boost/thread/concurrent_queues/queue_base.hpp +++ b/include/boost/thread/concurrent_queues/queue_base.hpp @@ -46,19 +46,19 @@ namespace detail // Modifiers virtual void close() = 0; - virtual void push_back(const value_type& x) = 0; + virtual void push(const value_type& x) = 0; - virtual void pull_front(value_type&) = 0; - virtual value_type pull_front() = 0; + virtual void pull(value_type&) = 0; + virtual value_type pull() = 0; - virtual queue_op_status try_push_back(const value_type& x) = 0; - virtual queue_op_status try_pull_front(value_type&) = 0; + virtual queue_op_status try_push(const value_type& x) = 0; + virtual queue_op_status try_pull(value_type&) = 0; - virtual queue_op_status nonblocking_push_back(const value_type& x) = 0; - virtual queue_op_status nonblocking_pull_front(value_type&) = 0; + virtual queue_op_status nonblocking_push(const value_type& x) = 0; + virtual queue_op_status nonblocking_pull(value_type&) = 0; - virtual queue_op_status wait_push_back(const value_type& x) = 0; - virtual queue_op_status wait_pull_front(ValueType& elem) = 0; + virtual queue_op_status wait_push(const value_type& x) = 0; + virtual queue_op_status wait_pull(ValueType& elem) = 0; }; @@ -80,20 +80,20 @@ namespace detail // Modifiers virtual void close() = 0; - virtual void pull_front(value_type&) = 0; + virtual void pull(value_type&) = 0; // enable_if is_nothrow_movable - virtual value_type pull_front() = 0; + virtual value_type pull() = 0; - virtual queue_op_status try_pull_front(value_type&) = 0; + virtual queue_op_status try_pull(value_type&) = 0; - virtual queue_op_status nonblocking_pull_front(value_type&) = 0; + virtual queue_op_status nonblocking_pull(value_type&) = 0; - virtual queue_op_status wait_pull_front(ValueType& elem) = 0; + virtual queue_op_status wait_pull(ValueType& elem) = 0; - virtual void push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; - virtual queue_op_status try_push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; - virtual queue_op_status nonblocking_push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; - virtual queue_op_status wait_push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; + virtual void push(BOOST_THREAD_RV_REF(value_type) x) = 0; + virtual queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) = 0; + virtual queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) = 0; + virtual queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) = 0; }; @@ -116,25 +116,25 @@ namespace detail // Modifiers virtual void close() = 0; - virtual void push_back(const value_type& x) = 0; + virtual void push(const value_type& x) = 0; - virtual void pull_front(value_type&) = 0; + virtual void pull(value_type&) = 0; // enable_if is_nothrow_copy_movable - virtual value_type pull_front() = 0; + virtual value_type pull() = 0; - virtual queue_op_status try_push_back(const value_type& x) = 0; - virtual queue_op_status try_pull_front(value_type&) = 0; + virtual queue_op_status try_push(const value_type& x) = 0; + virtual queue_op_status try_pull(value_type&) = 0; - virtual queue_op_status nonblocking_push_back(const value_type& x) = 0; - virtual queue_op_status nonblocking_pull_front(value_type&) = 0; + virtual queue_op_status nonblocking_push(const value_type& x) = 0; + virtual queue_op_status nonblocking_pull(value_type&) = 0; - virtual queue_op_status wait_push_back(const value_type& x) = 0; - virtual queue_op_status wait_pull_front(ValueType& elem) = 0; + virtual queue_op_status wait_push(const value_type& x) = 0; + virtual queue_op_status wait_pull(ValueType& elem) = 0; - virtual void push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; - virtual queue_op_status try_push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; - virtual queue_op_status nonblocking_push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; - virtual queue_op_status wait_push_back(BOOST_THREAD_RV_REF(value_type) x) = 0; + virtual void push(BOOST_THREAD_RV_REF(value_type) x) = 0; + virtual queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) = 0; + virtual queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) = 0; + virtual queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) = 0; }; template close(); } - void push(const value_type& x) { queue->push_back(x); } + void push(const value_type& x) { queue->push(x); } - void pull(value_type& x) { queue->pull_back(x); } - // enable_if is_nothrow_copy_movable - value_type pull() { return queue->pull_back(); } - - queue_op_status try_push(const value_type& x) { return queue->try_push_back(x); } - - queue_op_status try_pull(value_type& x) { return queue->try_pull_back(x); } - - queue_op_status nonblocking_push(const value_type& x) { return queue->nonblocking_push_back(x); } - - queue_op_status nonblocking_pull(value_type& x) { return queue->nonblocking_pull_back(x); } + queue_op_status try_push(const value_type& x) { return queue->try_push(x); } - queue_op_status wait_push(const value_type& x) { return queue->wait_push_back(x); } - queue_op_status wait_pull(value_type& x) { return queue->wait_pull_back(x); } + queue_op_status nonblocking_push(const value_type& x) { return queue->nonblocking_push(x); } + queue_op_status wait_push(const value_type& x) { return queue->wait_push(x); } - void push(BOOST_THREAD_RV_REF(value_type) x) { queue->push_back(boost::move(x)); } - queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->try_push_back(boost::move(x)); } - queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->nonblocking_push_back(boost::move(x)); } - queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->wait_push_back(boost::move(x)); } + void push(BOOST_THREAD_RV_REF(value_type) x) { queue->push(boost::move(x)); } + queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->try_push(boost::move(x)); } + queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->nonblocking_push(boost::move(x)); } + queue_op_status wait_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->wait_push(boost::move(x)); } }; template @@ -88,20 +78,20 @@ namespace concurrent void push(const value_type& x) { queue->push_front(x); } - void pull(value_type& x) { queue->pull_front(x); }; + void pull(value_type& x) { queue->pull(x); }; // enable_if is_nothrow_copy_movable - value_type pull() { return queue->pull_front(); } + value_type pull() { return queue->pull(); } queue_op_status try_push(const value_type& x) { return queue->try_push_front(x); } - queue_op_status try_pull(value_type& x) { return queue->try_pull_front(x); } + queue_op_status try_pull(value_type& x) { return queue->try_pull(x); } queue_op_status nonblocking_push(const value_type& x) { return queue->nonblocking_push_front(x); } - queue_op_status nonblocking_pull(value_type& x) { return queue->nonblocking_pull_front(x); } + queue_op_status nonblocking_pull(value_type& x) { return queue->nonblocking_pull(x); } queue_op_status wait_push(const value_type& x) { return queue->wait_push_front(x); } - queue_op_status wait_pull(value_type& x) { return queue->wait_pull_front(x); } + queue_op_status wait_pull(value_type& x) { return queue->wait_pull(x); } void push(BOOST_THREAD_RV_REF(value_type) x) { queue->push_front(forward(x)); } queue_op_status try_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->try_push_front(forward(x)); } queue_op_status nonblocking_push(BOOST_THREAD_RV_REF(value_type) x) { return queue->nonblocking_push_front(forward(x)); } diff --git a/include/boost/thread/executors/basic_thread_pool.hpp b/include/boost/thread/executors/basic_thread_pool.hpp index 2cf4e475e..64ba1e90e 100644 --- a/include/boost/thread/executors/basic_thread_pool.hpp +++ b/include/boost/thread/executors/basic_thread_pool.hpp @@ -5,7 +5,7 @@ // // 2013/09 Vicente J. Botet Escriba // Adapt to boost from CCIA C++11 implementation -// first implementation of a simple pool thread using a vector of threads and a sync_deque. +// first implementation of a simple pool thread using a vector of threads and a sync_queue. #ifndef BOOST_THREAD_EXECUTORS_BASIC_THREAD_POOL_HPP #define BOOST_THREAD_EXECUTORS_BASIC_THREAD_POOL_HPP @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include @@ -36,7 +36,7 @@ namespace executors typedef csbl::vector thread_vector; /// the thread safe work queue - concurrent::sync_deque work_queue; + concurrent::sync_queue work_queue; /// A move aware vector thread_vector threads; @@ -51,7 +51,7 @@ namespace executors try { work task; - if (work_queue.try_pull_front(task) == queue_op_status::success) + if (work_queue.try_pull(task) == queue_op_status::success) { task(); return true; @@ -87,7 +87,7 @@ namespace executors for(;;) { work task; - queue_op_status st = work_queue.wait_pull_front(task); + queue_op_status st = work_queue.wait_pull(task); if (st == queue_op_status::closed) return; task(); } @@ -269,18 +269,18 @@ namespace executors template void submit(Closure & closure) { - work_queue.push_back(work(closure)); + work_queue.push(work(closure)); } #endif void submit(void (*closure)()) { - work_queue.push_back(work(closure)); + work_queue.push(work(closure)); } template void submit(BOOST_THREAD_RV_REF(Closure) closure) { - work_queue.push_back(work(boost::forward(closure))); + work_queue.push(work(boost::forward(closure))); } /** diff --git a/include/boost/thread/executors/loop_executor.hpp b/include/boost/thread/executors/loop_executor.hpp index ec3a9c79c..e9eadadf9 100644 --- a/include/boost/thread/executors/loop_executor.hpp +++ b/include/boost/thread/executors/loop_executor.hpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include @@ -31,7 +31,7 @@ namespace executors typedef executors::work work; private: /// the thread safe work queue - concurrent::sync_deque work_queue; + concurrent::sync_queue work_queue; public: /** @@ -44,7 +44,7 @@ namespace executors work task; try { - if (work_queue.try_pull_front(task) == queue_op_status::success) + if (work_queue.try_pull(task) == queue_op_status::success) { task(); return true; @@ -143,18 +143,18 @@ namespace executors template void submit(Closure & closure) { - work_queue.push_back(work(closure)); + work_queue.push(work(closure)); } #endif void submit(void (*closure)()) { - work_queue.push_back(work(closure)); + work_queue.push(work(closure)); } template void submit(BOOST_THREAD_RV_REF(Closure) closure) { - work_queue.push_back(work(boost::forward(closure))); + work_queue.push(work(boost::forward(closure))); } /** @@ -179,7 +179,7 @@ namespace executors */ void run_queued_closures() { - sync_deque::underlying_queue_type q = work_queue.underlying_queue(); + sync_queue::underlying_queue_type q = work_queue.underlying_queue(); while (! q.empty()) { work& task = q.front(); diff --git a/include/boost/thread/executors/serial_executor.hpp b/include/boost/thread/executors/serial_executor.hpp index a5430e0ac..3728e6ca0 100644 --- a/include/boost/thread/executors/serial_executor.hpp +++ b/include/boost/thread/executors/serial_executor.hpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include @@ -33,7 +33,7 @@ namespace executors typedef scoped_thread<> thread_t; /// the thread safe work queue - concurrent::sync_deque work_queue; + concurrent::sync_queue work_queue; generic_executor_ref ex; thread_t thr; @@ -64,7 +64,7 @@ namespace executors work task; try { - if (work_queue.try_pull_front(task) == queue_op_status::success) + if (work_queue.try_pull(task) == queue_op_status::success) { boost::promise p; try_executing_one_task tmp(task,p); @@ -165,18 +165,18 @@ namespace executors template void submit(Closure & closure) { - work_queue.push_back(work(closure)); + work_queue.push(work(closure)); } #endif void submit(void (*closure)()) { - work_queue.push_back(work(closure)); + work_queue.push(work(closure)); } template void submit(BOOST_THREAD_RV_REF(Closure) closure) { - work_queue.push_back(work(boost::forward(closure))); + work_queue.push(work(boost::forward(closure))); } /** diff --git a/include/boost/thread/thread_pool.hpp b/include/boost/thread/thread_pool.hpp index 538b49399..4d2dcbea3 100644 --- a/include/boost/thread/thread_pool.hpp +++ b/include/boost/thread/thread_pool.hpp @@ -5,7 +5,7 @@ // // 2013/09 Vicente J. Botet Escriba // Adapt to boost from CCIA C++11 implementation -// first implementation of a simple pool thread using a vector of threads and a sync_deque. +// first implementation of a simple pool thread using a vector of threads and a sync_queue. #ifndef BOOST_THREAD_THREAD_POOL_HPP #define BOOST_THREAD_THREAD_POOL_HPP diff --git a/include/boost/thread/user_scheduler.hpp b/include/boost/thread/user_scheduler.hpp index 9323c1f75..e33d4df73 100644 --- a/include/boost/thread/user_scheduler.hpp +++ b/include/boost/thread/user_scheduler.hpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include @@ -26,7 +26,7 @@ namespace boost typedef thread_detail::work work; /// the thread safe work queue - sync_deque work_queue; + sync_queue work_queue; public: /** @@ -39,7 +39,7 @@ namespace boost work task; try { - if (work_queue.try_pull_front(task) == queue_op_status::success) + if (work_queue.try_pull(task) == queue_op_status::success) { task(); return true; @@ -144,23 +144,23 @@ namespace boost void submit(Closure & closure) { work w ((closure)); - work_queue.push_back(boost::move(w)); + work_queue.push(boost::move(w)); //work_queue.push(work(closure)); // todo check why this doesn't work } #endif void submit(void (*closure)()) { work w ((closure)); - work_queue.push_back(boost::move(w)); - //work_queue.push_back(work(closure)); // todo check why this doesn't work + work_queue.push(boost::move(w)); + //work_queue.push(work(closure)); // todo check why this doesn't work } template void submit(BOOST_THREAD_RV_REF(Closure) closure) { work w =boost::move(closure); - work_queue.push_back(boost::move(w)); - //work_queue.push_back(work(boost::move(closure))); // todo check why this doesn't work + work_queue.push(boost::move(w)); + //work_queue.push(work(boost::move(closure))); // todo check why this doesn't work } /** @@ -184,7 +184,7 @@ namespace boost */ void run_queued_closures() { - sync_deque::underlying_queue_type q = work_queue.underlying_queue(); + sync_queue::underlying_queue_type q = work_queue.underlying_queue(); while (q.empty()) { work task = q.front(); diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index fdbc7e73a..60bb69269 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -713,6 +713,12 @@ rule thread-compile ( sources : reqs * : name ) #[ thread-run2-noit ./sync/mutual_exclusion/queue_views/multi_thread_pass.cpp : queue_views__multi_thread_p ] ; + test-suite ts_deque_views + : + [ thread-run2-noit ./sync/mutual_exclusion/deque_views/single_thread_pass.cpp : deque_views__single_thread_p ] + #[ thread-run2-noit ./sync/mutual_exclusion/deque_views/multi_thread_pass.cpp : deque_views__multi_thread_p ] + ; + #explicit ts_this_thread ; test-suite ts_this_thread : diff --git a/test/sync/mutual_exclusion/deque_views/single_thread_pass.cpp b/test/sync/mutual_exclusion/deque_views/single_thread_pass.cpp new file mode 100644 index 000000000..96e8e268d --- /dev/null +++ b/test/sync/mutual_exclusion/deque_views/single_thread_pass.cpp @@ -0,0 +1,455 @@ +// Copyright (C) 2014 Vicente J. Botet Escriba +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// + +// class sync_deque + +// sync_deque(); + +#define BOOST_THREAD_VERSION 4 +//#define BOOST_THREAD_QUEUE_DEPRECATE_OLD + +#include +#include +#include + +#include +#include + +class non_copyable +{ + BOOST_THREAD_MOVABLE_ONLY(non_copyable) + int val; +public: + non_copyable(int v) : val(v){} + non_copyable(BOOST_RV_REF(non_copyable) x): val(x.val) {} + non_copyable& operator=(BOOST_RV_REF(non_copyable) x) { val=x.val; return *this; } + bool operator==(non_copyable const& x) const {return val==x.val;} + template + friend OSTREAM& operator <<(OSTREAM& os, non_copyable const&x ) + { + os << x.val; + return os; + } + +}; + +#if defined BOOST_NO_CXX11_RVALUE_REFERENCES +BOOST_STATIC_ASSERT( ! boost::is_copy_constructible::value ); +BOOST_STATIC_ASSERT( boost::has_move_emulation_enabled::value ); +#endif + +int main() +{ + + { + // default queue invariants + boost::deque_adaptor > sq; + boost::deque_back q(sq); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // default queue invariants + boost::deque_adaptor > sq; + boost::deque_front q(sq); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + + + { + // empty queue try_pull fails + boost::deque_adaptor > sq; + boost::deque_front q(sq); + int i; + BOOST_TEST( boost::queue_op_status::empty == q.try_pull(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push rvalue/copyable succeeds + boost::deque_adaptor > sq; + boost::deque_back q(sq); + q.push(1); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push lvalue/copyable succeeds + boost::deque_adaptor > sq; + boost::deque_back q(sq); + int i; + q.push(i); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + + +#if 0 + { + // empty queue push rvalue/non_copyable succeeds + boost::deque_adaptor > sq; + boost::deque_back q(sq); + q.push(non_copyable(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + { + // empty queue push rvalue/non_copyable succeeds + boost::deque_adaptor > q; + //boost::sync_deque q; + //boost::deque_back q(sq); + non_copyable nc(1); + q.push_back(boost::move(nc)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + + { + // empty queue push rvalue succeeds + boost::deque_adaptor > sq; + boost::deque_back q(sq); + q.push(1); + q.push(2); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 2u); + BOOST_TEST(! q.closed()); + } + { + // empty queue push lvalue succeeds + boost::deque_adaptor > sq; + boost::deque_back q(sq); + int i; + q.push(i); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue/copyable succeeds + boost::deque_adaptor > sq; + boost::deque_back q(sq); + BOOST_TEST(boost::queue_op_status::success == q.try_push(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue/copyable succeeds + boost::deque_adaptor > sq; + boost::deque_back q(sq); + BOOST_TEST(boost::queue_op_status::success == q.try_push(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + +#if 0 + { + // empty queue try_push rvalue/non-copyable succeeds + boost::deque_adaptor > sq; + boost::deque_back q(sq); + non_copyable nc(1); + BOOST_TEST(boost::queue_op_status::success == q.try_push(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + + { + // empty queue try_push lvalue succeeds + boost::deque_adaptor > sq; + boost::deque_back q(sq); + int i; + BOOST_TEST(boost::queue_op_status::success == q.try_push(i)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // empty queue try_push rvalue succeeds + boost::deque_adaptor > sq; + boost::deque_back q(sq); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(1)); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + + +#if 0 + { + // empty queue nonblocking_push_back rvalue/non-copyable succeeds + boost::deque_adaptor > sq; + boost::deque_back q(sq); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(non_copyable(1))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } +#endif + { + // empty queue nonblocking_push_back rvalue/non-copyable succeeds + boost::deque_adaptor > sq; + boost::deque_back q(sq); + non_copyable nc(1); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(boost::move(nc))); + BOOST_TEST(! q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 1u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull_front succeed + boost::deque_adaptor > sq; + boost::deque_front q(sq); + sq.push_back(1); + int i; + q.pull(i); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull_front succeed + boost::deque_adaptor > sq; + boost::deque_front q(sq); + non_copyable nc1(1); + sq.push_back(boost::move(nc1)); + non_copyable nc2(2); + q.pull(nc2); + BOOST_TEST_EQ(nc1, nc2); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull_front succeed + boost::deque_adaptor > sq; + boost::deque_front q(sq); + sq.push_back(1); + int i = q.pull(); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue pull_front succeed + boost::deque_adaptor > sq; + boost::deque_front q(sq); + non_copyable nc1(1); + sq.push_back(boost::move(nc1)); + non_copyable nc = q.pull(); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue try_pull_front succeed + boost::deque_adaptor > sq; + boost::deque_front q(sq); + sq.push_back(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.try_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue try_pull_front succeed + boost::deque_adaptor > sq; + boost::deque_front q(sq); + non_copyable nc1(1); + sq.push_back(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.try_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue nonblocking_pull_front succeed + boost::deque_adaptor > sq; + boost::deque_front q(sq); + sq.push_back(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue nonblocking_pull_front succeed + boost::deque_adaptor > sq; + boost::deque_front q(sq); + non_copyable nc1(1); + sq.push_back(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue wait_pull_front succeed + boost::deque_adaptor > sq; + boost::deque_front q(sq); + non_copyable nc1(1); + sq.push_back(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue wait_pull_front succeed + boost::deque_adaptor > sq; + boost::deque_front q(sq); + sq.push_back(1); + int i; + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + { + // 1-element queue wait_pull_front succeed + boost::deque_adaptor > sq; + boost::deque_front q(sq); + non_copyable nc1(1); + sq.push_back(boost::move(nc1)); + non_copyable nc(2); + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(nc)); + BOOST_TEST_EQ(nc, nc1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(! q.closed()); + } + + { + // closed invariants + boost::deque_adaptor > sq; + boost::deque_back q(sq); + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed invariants + boost::deque_adaptor > sq; + boost::deque_front q(sq); + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed queue push fails + boost::deque_adaptor > sq; + boost::deque_back q(sq); + q.close(); + try { + q.push(1); + BOOST_TEST(false); + } catch (...) { + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + } + { + // 1-element closed queue pull succeed + boost::deque_adaptor > sq; + boost::deque_front q(sq); + sq.push_back(1); + q.close(); + int i; + q.pull(i); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // 1-element closed queue wait_pull_front succeed + boost::deque_adaptor > sq; + boost::deque_front q(sq); + sq.push_back(1); + q.close(); + int i; + BOOST_TEST(boost::queue_op_status::success == q.wait_pull(i)); + BOOST_TEST_EQ(i, 1); + BOOST_TEST(q.empty()); + BOOST_TEST(! q.full()); + BOOST_TEST_EQ(q.size(), 0u); + BOOST_TEST(q.closed()); + } + { + // closed empty queue wait_pull_front fails + boost::deque_adaptor > sq; + boost::deque_front q(sq); + q.close(); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + int i; + BOOST_TEST(boost::queue_op_status::closed == q.wait_pull(i)); + BOOST_TEST(q.empty()); + BOOST_TEST(q.closed()); + } + return boost::report_errors(); +} + diff --git a/test/sync/mutual_exclusion/queue_views/single_thread_pass.cpp b/test/sync/mutual_exclusion/queue_views/single_thread_pass.cpp index e9cfe10cc..41cf1cf3a 100644 --- a/test/sync/mutual_exclusion/queue_views/single_thread_pass.cpp +++ b/test/sync/mutual_exclusion/queue_views/single_thread_pass.cpp @@ -3,16 +3,16 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// +// -// class sync_deque +// class sync_queue -// sync_deque(); +// sync_queue(); #define BOOST_THREAD_VERSION 4 //#define BOOST_THREAD_QUEUE_DEPRECATE_OLD -#include +#include #include #include @@ -47,7 +47,7 @@ int main() { // default queue invariants - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_back q(sq); BOOST_TEST(q.empty()); BOOST_TEST(! q.full()); @@ -56,7 +56,7 @@ int main() } { // default queue invariants - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_front q(sq); BOOST_TEST(q.empty()); BOOST_TEST(! q.full()); @@ -67,7 +67,7 @@ int main() { // empty queue try_pull fails - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_front q(sq); int i; BOOST_TEST( boost::queue_op_status::empty == q.try_pull(i)); @@ -78,7 +78,7 @@ int main() } { // empty queue push rvalue/copyable succeeds - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_back q(sq); q.push(1); BOOST_TEST(! q.empty()); @@ -88,7 +88,7 @@ int main() } { // empty queue push lvalue/copyable succeeds - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_back q(sq); int i; q.push(i); @@ -102,7 +102,7 @@ int main() #if 0 { // empty queue push rvalue/non_copyable succeeds - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_back q(sq); q.push(non_copyable(1)); BOOST_TEST(! q.empty()); @@ -113,11 +113,11 @@ int main() #endif { // empty queue push rvalue/non_copyable succeeds - boost::queue_adaptor > q; - //boost::sync_deque q; + boost::queue_adaptor > q; + //boost::sync_queue q; //boost::queue_back q(sq); non_copyable nc(1); - q.push_back(boost::move(nc)); + q.push(boost::move(nc)); BOOST_TEST(! q.empty()); BOOST_TEST(! q.full()); BOOST_TEST_EQ(q.size(), 1u); @@ -126,7 +126,7 @@ int main() { // empty queue push rvalue succeeds - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_back q(sq); q.push(1); q.push(2); @@ -137,7 +137,7 @@ int main() } { // empty queue push lvalue succeeds - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_back q(sq); int i; q.push(i); @@ -148,7 +148,7 @@ int main() } { // empty queue try_push rvalue/copyable succeeds - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_back q(sq); BOOST_TEST(boost::queue_op_status::success == q.try_push(1)); BOOST_TEST(! q.empty()); @@ -158,7 +158,7 @@ int main() } { // empty queue try_push rvalue/copyable succeeds - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_back q(sq); BOOST_TEST(boost::queue_op_status::success == q.try_push(1)); BOOST_TEST(! q.empty()); @@ -170,7 +170,7 @@ int main() #if 0 { // empty queue try_push rvalue/non-copyable succeeds - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_back q(sq); non_copyable nc(1); BOOST_TEST(boost::queue_op_status::success == q.try_push(boost::move(nc))); @@ -183,7 +183,7 @@ int main() { // empty queue try_push lvalue succeeds - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_back q(sq); int i; BOOST_TEST(boost::queue_op_status::success == q.try_push(i)); @@ -194,7 +194,7 @@ int main() } { // empty queue try_push rvalue succeeds - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_back q(sq); BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(1)); BOOST_TEST(! q.empty()); @@ -206,8 +206,8 @@ int main() #if 0 { - // empty queue nonblocking_push_back rvalue/non-copyable succeeds - boost::queue_adaptor > sq; + // empty queue nonblocking_push rvalue/non-copyable succeeds + boost::queue_adaptor > sq; boost::queue_back q(sq); BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(non_copyable(1))); BOOST_TEST(! q.empty()); @@ -217,8 +217,8 @@ int main() } #endif { - // empty queue nonblocking_push_back rvalue/non-copyable succeeds - boost::queue_adaptor > sq; + // empty queue nonblocking_push rvalue/non-copyable succeeds + boost::queue_adaptor > sq; boost::queue_back q(sq); non_copyable nc(1); BOOST_TEST(boost::queue_op_status::success == q.nonblocking_push(boost::move(nc))); @@ -228,10 +228,10 @@ int main() BOOST_TEST(! q.closed()); } { - // 1-element queue pull_front succeed - boost::queue_adaptor > sq; + // 1-element queue pull succeed + boost::queue_adaptor > sq; boost::queue_front q(sq); - sq.push_back(1); + sq.push(1); int i; q.pull(i); BOOST_TEST_EQ(i, 1); @@ -241,11 +241,11 @@ int main() BOOST_TEST(! q.closed()); } { - // 1-element queue pull_front succeed - boost::queue_adaptor > sq; + // 1-element queue pull succeed + boost::queue_adaptor > sq; boost::queue_front q(sq); non_copyable nc1(1); - sq.push_back(boost::move(nc1)); + sq.push(boost::move(nc1)); non_copyable nc2(2); q.pull(nc2); BOOST_TEST_EQ(nc1, nc2); @@ -255,10 +255,10 @@ int main() BOOST_TEST(! q.closed()); } { - // 1-element queue pull_front succeed - boost::queue_adaptor > sq; + // 1-element queue pull succeed + boost::queue_adaptor > sq; boost::queue_front q(sq); - sq.push_back(1); + sq.push(1); int i = q.pull(); BOOST_TEST_EQ(i, 1); BOOST_TEST(q.empty()); @@ -267,11 +267,11 @@ int main() BOOST_TEST(! q.closed()); } { - // 1-element queue pull_front succeed - boost::queue_adaptor > sq; + // 1-element queue pull succeed + boost::queue_adaptor > sq; boost::queue_front q(sq); non_copyable nc1(1); - sq.push_back(boost::move(nc1)); + sq.push(boost::move(nc1)); non_copyable nc = q.pull(); BOOST_TEST_EQ(nc, nc1); BOOST_TEST(q.empty()); @@ -280,10 +280,10 @@ int main() BOOST_TEST(! q.closed()); } { - // 1-element queue try_pull_front succeed - boost::queue_adaptor > sq; + // 1-element queue try_pull succeed + boost::queue_adaptor > sq; boost::queue_front q(sq); - sq.push_back(1); + sq.push(1); int i; BOOST_TEST(boost::queue_op_status::success == q.try_pull(i)); BOOST_TEST_EQ(i, 1); @@ -293,11 +293,11 @@ int main() BOOST_TEST(! q.closed()); } { - // 1-element queue try_pull_front succeed - boost::queue_adaptor > sq; + // 1-element queue try_pull succeed + boost::queue_adaptor > sq; boost::queue_front q(sq); non_copyable nc1(1); - sq.push_back(boost::move(nc1)); + sq.push(boost::move(nc1)); non_copyable nc(2); BOOST_TEST(boost::queue_op_status::success == q.try_pull(nc)); BOOST_TEST_EQ(nc, nc1); @@ -307,10 +307,10 @@ int main() BOOST_TEST(! q.closed()); } { - // 1-element queue nonblocking_pull_front succeed - boost::queue_adaptor > sq; + // 1-element queue nonblocking_pull succeed + boost::queue_adaptor > sq; boost::queue_front q(sq); - sq.push_back(1); + sq.push(1); int i; BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull(i)); BOOST_TEST_EQ(i, 1); @@ -320,11 +320,11 @@ int main() BOOST_TEST(! q.closed()); } { - // 1-element queue nonblocking_pull_front succeed - boost::queue_adaptor > sq; + // 1-element queue nonblocking_pull succeed + boost::queue_adaptor > sq; boost::queue_front q(sq); non_copyable nc1(1); - sq.push_back(boost::move(nc1)); + sq.push(boost::move(nc1)); non_copyable nc(2); BOOST_TEST(boost::queue_op_status::success == q.nonblocking_pull(nc)); BOOST_TEST_EQ(nc, nc1); @@ -334,11 +334,11 @@ int main() BOOST_TEST(! q.closed()); } { - // 1-element queue wait_pull_front succeed - boost::queue_adaptor > sq; + // 1-element queue wait_pull succeed + boost::queue_adaptor > sq; boost::queue_front q(sq); non_copyable nc1(1); - sq.push_back(boost::move(nc1)); + sq.push(boost::move(nc1)); non_copyable nc(2); BOOST_TEST(boost::queue_op_status::success == q.wait_pull(nc)); BOOST_TEST_EQ(nc, nc1); @@ -348,10 +348,10 @@ int main() BOOST_TEST(! q.closed()); } { - // 1-element queue wait_pull_front succeed - boost::queue_adaptor > sq; + // 1-element queue wait_pull succeed + boost::queue_adaptor > sq; boost::queue_front q(sq); - sq.push_back(1); + sq.push(1); int i; BOOST_TEST(boost::queue_op_status::success == q.wait_pull(i)); BOOST_TEST_EQ(i, 1); @@ -361,11 +361,11 @@ int main() BOOST_TEST(! q.closed()); } { - // 1-element queue wait_pull_front succeed - boost::queue_adaptor > sq; + // 1-element queue wait_pull succeed + boost::queue_adaptor > sq; boost::queue_front q(sq); non_copyable nc1(1); - sq.push_back(boost::move(nc1)); + sq.push(boost::move(nc1)); non_copyable nc(2); BOOST_TEST(boost::queue_op_status::success == q.wait_pull(nc)); BOOST_TEST_EQ(nc, nc1); @@ -377,7 +377,7 @@ int main() { // closed invariants - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_back q(sq); q.close(); BOOST_TEST(q.empty()); @@ -387,7 +387,7 @@ int main() } { // closed invariants - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_front q(sq); q.close(); BOOST_TEST(q.empty()); @@ -397,7 +397,7 @@ int main() } { // closed queue push fails - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_back q(sq); q.close(); try { @@ -412,9 +412,9 @@ int main() } { // 1-element closed queue pull succeed - boost::queue_adaptor > sq; + boost::queue_adaptor > sq; boost::queue_front q(sq); - sq.push_back(1); + sq.push(1); q.close(); int i; q.pull(i); @@ -425,10 +425,10 @@ int main() BOOST_TEST(q.closed()); } { - // 1-element closed queue wait_pull_front succeed - boost::queue_adaptor > sq; + // 1-element closed queue wait_pull succeed + boost::queue_adaptor > sq; boost::queue_front q(sq); - sq.push_back(1); + sq.push(1); q.close(); int i; BOOST_TEST(boost::queue_op_status::success == q.wait_pull(i)); @@ -439,8 +439,8 @@ int main() BOOST_TEST(q.closed()); } { - // closed empty queue wait_pull_front fails - boost::queue_adaptor > sq; + // closed empty queue wait_pull fails + boost::queue_adaptor > sq; boost::queue_front q(sq); q.close(); BOOST_TEST(q.empty());