|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r85854 - in trunk: boost/thread libs/thread/test/sync/mutual_exclusion/sync_bounded_queue libs/thread/test/sync/mutual_exclusion/sync_queue
From: vicente.botet_at_[hidden]
Date: 2013-09-23 12:44:26
Author: viboes
Date: 2013-09-23 12:44:26 EDT (Mon, 23 Sep 2013)
New Revision: 85854
URL: http://svn.boost.org/trac/boost/changeset/85854
Log:
Thread: fix some move semantic issues on sync_queue and sync_bounded_queue and add tests.
Text files modified:
trunk/boost/thread/sync_bounded_queue.hpp | 12 +-
trunk/boost/thread/sync_queue.hpp | 8 +-
trunk/libs/thread/test/sync/mutual_exclusion/sync_bounded_queue/single_thread_pass.cpp | 53 +++++++++++++
trunk/libs/thread/test/sync/mutual_exclusion/sync_queue/single_thread_pass.cpp | 153 ++++++++++++++++++++++++++++++++++++++-
4 files changed, 213 insertions(+), 13 deletions(-)
Modified: trunk/boost/thread/sync_bounded_queue.hpp
==============================================================================
--- trunk/boost/thread/sync_bounded_queue.hpp Mon Sep 23 11:30:22 2013 (r85853)
+++ trunk/boost/thread/sync_bounded_queue.hpp 2013-09-23 12:44:26 EDT (Mon, 23 Sep 2013) (r85854)
@@ -31,7 +31,9 @@
struct no_block_tag{};
BOOST_CONSTEXPR_OR_CONST no_block_tag no_block = {};
- struct sync_queue_is_closed : std::exception {};
+ struct sync_queue_is_closed : std::exception
+ {
+ };
template <typename ValueType>
class sync_bounded_queue
@@ -529,7 +531,7 @@
try
{
unique_lock<mutex> lk(mtx_);
- return try_push(elem, lk);
+ return try_push(boost::move(elem), lk);
}
catch (...)
{
@@ -548,7 +550,7 @@
{
return false;
}
- return try_push(elem, lk);
+ return try_push(boost::move(elem), lk);
}
catch (...)
{
@@ -563,7 +565,7 @@
try
{
unique_lock<mutex> lk(mtx_);
- push_at(elem, wait_until_not_full(lk), lk);
+ push_at(boost::move(elem), wait_until_not_full(lk), lk);
}
catch (...)
{
@@ -575,7 +577,7 @@
template <typename ValueType>
sync_bounded_queue<ValueType>& operator<<(sync_bounded_queue<ValueType>& sbq, BOOST_THREAD_RV_REF(ValueType) elem)
{
- sbq.push(boost::forward<ValueType>(elem));
+ sbq.push(boost::move(elem));
return sbq;
}
Modified: trunk/boost/thread/sync_queue.hpp
==============================================================================
--- trunk/boost/thread/sync_queue.hpp Mon Sep 23 11:30:22 2013 (r85853)
+++ trunk/boost/thread/sync_queue.hpp 2013-09-23 12:44:26 EDT (Mon, 23 Sep 2013) (r85854)
@@ -432,7 +432,7 @@
bool sync_queue<ValueType>::try_push(BOOST_THREAD_RV_REF(ValueType) elem, unique_lock<mutex>& lk)
{
throw_if_closed(lk);
- push(boost::forward<ValueType>(elem), lk);
+ push(boost::move(elem), lk);
return true;
}
@@ -442,7 +442,7 @@
try
{
unique_lock<mutex> lk(mtx_);
- return try_push(boost::forward<ValueType>(elem), lk);
+ return try_push(boost::move(elem), lk);
}
catch (...)
{
@@ -461,7 +461,7 @@
{
return false;
}
- return try_push(boost::forward<ValueType>(elem), lk);
+ return try_push(boost::move(elem), lk);
}
catch (...)
{
@@ -489,7 +489,7 @@
template <typename ValueType>
sync_queue<ValueType>& operator<<(sync_queue<ValueType>& sbq, BOOST_THREAD_RV_REF(ValueType) elem)
{
- sbq.push(boost::forward<ValueType>(elem));
+ sbq.push(boost::move(elem));
return sbq;
}
Modified: trunk/libs/thread/test/sync/mutual_exclusion/sync_bounded_queue/single_thread_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/mutual_exclusion/sync_bounded_queue/single_thread_pass.cpp Mon Sep 23 11:30:22 2013 (r85853)
+++ trunk/libs/thread/test/sync/mutual_exclusion/sync_bounded_queue/single_thread_pass.cpp 2013-09-23 12:44:26 EDT (Mon, 23 Sep 2013) (r85854)
@@ -15,6 +15,16 @@
#include <boost/detail/lightweight_test.hpp>
+class non_copyable
+{
+ BOOST_THREAD_MOVABLE_ONLY(non_copyable)
+
+ public:
+ non_copyable(){}
+ non_copyable(BOOST_RV_REF(non_copyable)) {}
+ non_copyable& operator=(BOOST_RV_REF(non_copyable)) { return *this; }
+};
+
int main()
{
@@ -57,6 +67,16 @@
}
{
// empty queue push rvalue succeeds
+ boost::sync_bounded_queue<non_copyable> q(2);
+ non_copyable nc;
+ q.push(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::sync_bounded_queue<int> q(2);
q.push(1);
q.push(2);
@@ -85,6 +105,16 @@
BOOST_TEST(! q.closed());
}
{
+ // empty queue try_push rvalue succeeds
+ boost::sync_bounded_queue<non_copyable> q(2);
+ non_copyable nc;
+ BOOST_TEST(q.try_push(boost::move(nc)));
+ BOOST_TEST(! q.empty());
+ BOOST_TEST(! q.full());
+ BOOST_TEST_EQ(q.size(), 1u);
+ BOOST_TEST(! q.closed());
+ }
+ {
// empty queue try_push value succeeds
boost::sync_bounded_queue<int> q(2);
int i;
@@ -104,6 +134,16 @@
BOOST_TEST(! q.closed());
}
{
+ // empty queue try_push rvalue succeeds
+ boost::sync_bounded_queue<non_copyable> q(2);
+ non_copyable nc;
+ BOOST_TEST(q.try_push(boost::no_block, 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 succeed
boost::sync_bounded_queue<int> q(2);
q.push(1);
@@ -117,6 +157,19 @@
}
{
// 1-element queue pull succeed
+ boost::sync_bounded_queue<non_copyable> q(2);
+ non_copyable nc;
+ q.push(boost::move(nc));
+ non_copyable nc2;
+ q.pull(nc2);
+ //BOOST_TEST_EQ(nc, nc2, 1);
+ BOOST_TEST(q.empty());
+ BOOST_TEST(! q.full());
+ BOOST_TEST_EQ(q.size(), 0u);
+ BOOST_TEST(! q.closed());
+ }
+ {
+ // 1-element queue pull succeed
boost::sync_bounded_queue<int> q(2);
q.push(1);
int i = q.pull();
Modified: trunk/libs/thread/test/sync/mutual_exclusion/sync_queue/single_thread_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/mutual_exclusion/sync_queue/single_thread_pass.cpp Mon Sep 23 11:30:22 2013 (r85853)
+++ trunk/libs/thread/test/sync/mutual_exclusion/sync_queue/single_thread_pass.cpp 2013-09-23 12:44:26 EDT (Mon, 23 Sep 2013) (r85854)
@@ -15,6 +15,16 @@
#include <boost/detail/lightweight_test.hpp>
+class non_copyable
+{
+ BOOST_THREAD_MOVABLE_ONLY(non_copyable)
+
+ public:
+ non_copyable(){}
+ non_copyable(BOOST_RV_REF(non_copyable)) {}
+ non_copyable& operator=(BOOST_RV_REF(non_copyable)) { return *this; }
+};
+
int main()
{
@@ -46,7 +56,7 @@
BOOST_TEST(! q.closed());
}
{
- // empty queue push rvalue succeeds
+ // empty queue push rvalue/copyable succeeds
boost::sync_queue<int> q;
q.push(1);
BOOST_TEST(! q.empty());
@@ -55,6 +65,38 @@
BOOST_TEST(! q.closed());
}
{
+ // empty queue push lvalue/copyable succeeds
+ boost::sync_queue<int> q;
+ 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::sync_queue<non_copyable> q;
+ q.push(non_copyable());
+ 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::sync_queue<non_copyable> q;
+ non_copyable nc;
+ q.push(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::sync_queue<int> q;
q.push(1);
@@ -65,7 +107,7 @@
BOOST_TEST(! q.closed());
}
{
- // empty queue push value succeeds
+ // empty queue push lvalue succeeds
boost::sync_queue<int> q;
int i;
q.push(i);
@@ -75,7 +117,16 @@
BOOST_TEST(! q.closed());
}
{
- // empty queue try_push rvalue succeeds
+ // empty queue try_push rvalue/copyable succeeds
+ boost::sync_queue<int> q;
+ BOOST_TEST(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::sync_queue<int> q;
BOOST_TEST(q.try_push(1));
BOOST_TEST(! q.empty());
@@ -83,8 +134,30 @@
BOOST_TEST_EQ(q.size(), 1u);
BOOST_TEST(! q.closed());
}
+#if 0
+ {
+ // empty queue try_push rvalue/non-copyable succeeds
+ boost::sync_queue<non_copyable> q;
+ BOOST_TEST(q.try_push(non_copyable()));
+ BOOST_TEST(! q.empty());
+ BOOST_TEST(! q.full());
+ BOOST_TEST_EQ(q.size(), 1u);
+ BOOST_TEST(! q.closed());
+ }
+#endif
+ {
+ // empty queue try_push rvalue/non-copyable succeeds
+ boost::sync_queue<non_copyable> q;
+ non_copyable nc;
+ BOOST_TEST(q.try_push(boost::move(nc)));
+ BOOST_TEST(! q.empty());
+ BOOST_TEST(! q.full());
+ BOOST_TEST_EQ(q.size(), 1u);
+ BOOST_TEST(! q.closed());
+ }
+
{
- // empty queue try_push value succeeds
+ // empty queue try_push lvalue succeeds
boost::sync_queue<int> q;
int i;
BOOST_TEST(q.try_push(i));
@@ -102,6 +175,27 @@
BOOST_TEST_EQ(q.size(), 1u);
BOOST_TEST(! q.closed());
}
+#if 0
+ {
+ // empty queue try_push rvalue/non-copyable succeeds
+ boost::sync_queue<non_copyable> q;
+ BOOST_TEST(q.try_push(boost::no_block, non_copyable()));
+ BOOST_TEST(! q.empty());
+ BOOST_TEST(! q.full());
+ BOOST_TEST_EQ(q.size(), 1u);
+ BOOST_TEST(! q.closed());
+ }
+#endif
+ {
+ // empty queue try_push rvalue/non-copyable succeeds
+ boost::sync_queue<non_copyable> q;
+ non_copyable nc;
+ BOOST_TEST(q.try_push(boost::no_block, 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 succeed
boost::sync_queue<int> q;
@@ -116,6 +210,19 @@
}
{
// 1-element queue pull succeed
+ boost::sync_queue<non_copyable> q;
+ non_copyable nc1;
+ q.push(boost::move(nc1));
+ non_copyable nc2;
+ 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 succeed
boost::sync_queue<int> q;
q.push(1);
int i = q.pull();
@@ -126,6 +233,18 @@
BOOST_TEST(! q.closed());
}
{
+ // 1-element queue pull succeed
+ boost::sync_queue<non_copyable> q;
+ non_copyable nc1;
+ q.push(boost::move(nc1));
+ non_copyable nc = q.pull();
+ //BOOST_TEST_EQ(nc, 1);
+ BOOST_TEST(q.empty());
+ BOOST_TEST(! q.full());
+ BOOST_TEST_EQ(q.size(), 0u);
+ BOOST_TEST(! q.closed());
+ }
+ {
// 1-element queue try_pull succeed
boost::sync_queue<int> q;
q.push(1);
@@ -139,6 +258,19 @@
}
{
// 1-element queue try_pull succeed
+ boost::sync_queue<non_copyable> q;
+ non_copyable nc1;
+ q.push(boost::move(nc1));
+ non_copyable nc;
+ BOOST_TEST(q.try_pull(nc));
+ //BOOST_TEST_EQ(nc, 1);
+ BOOST_TEST(q.empty());
+ BOOST_TEST(! q.full());
+ BOOST_TEST_EQ(q.size(), 0u);
+ BOOST_TEST(! q.closed());
+ }
+ {
+ // 1-element queue try_pull succeed
boost::sync_queue<int> q;
q.push(1);
int i;
@@ -151,6 +283,19 @@
}
{
// 1-element queue try_pull succeed
+ boost::sync_queue<non_copyable> q;
+ non_copyable nc1;
+ q.push(boost::move(nc1));
+ non_copyable nc;
+ BOOST_TEST(q.try_pull(boost::no_block, nc));
+ //BOOST_TEST_EQ(nc, 1);
+ BOOST_TEST(q.empty());
+ BOOST_TEST(! q.full());
+ BOOST_TEST_EQ(q.size(), 0u);
+ BOOST_TEST(! q.closed());
+ }
+ {
+ // 1-element queue try_pull succeed
boost::sync_queue<int> q;
q.push(1);
boost::shared_ptr<int> i = q.try_pull();
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk