|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r84597 - in trunk: boost/thread libs/thread/test libs/thread/test/sync/futures/packaged_task
From: vicente.botet_at_[hidden]
Date: 2013-06-01 10:27:17
Author: viboes
Date: 2013-06-01 10:27:16 EDT (Sat, 01 Jun 2013)
New Revision: 84597
URL: http://svn.boost.org/trac/boost/changeset/84597
Log:
Thread: fix packaged_task<void()> issue and add tests.
Text files modified:
trunk/boost/thread/future.hpp | 16 -----
trunk/libs/thread/test/sync/futures/packaged_task/func_ctor_pass.cpp | 95 +++++++++++++++++++++++++++++++++++++++
trunk/libs/thread/test/test_8596.cpp | 44 ++++++++++++++++++
3 files changed, 139 insertions(+), 16 deletions(-)
Modified: trunk/boost/thread/future.hpp
==============================================================================
--- trunk/boost/thread/future.hpp (original)
+++ trunk/boost/thread/future.hpp 2013-06-01 10:27:16 EDT (Sat, 01 Jun 2013)
@@ -2334,18 +2334,12 @@
task_shared_state(task_shared_state&);
public:
F f;
-#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- task_shared_state(BOOST_THREAD_RV_REF(F) f_):
- f(boost::forward<F>(f_))
- {}
-#else
task_shared_state(F const& f_):
f(f_)
{}
task_shared_state(BOOST_THREAD_RV_REF(F) f_):
- f(boost::move(f_)) // TODO forward
+ f(boost::move(f_))
{}
-#endif
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
void do_apply(BOOST_THREAD_RV_REF(ArgTypes) ... args)
@@ -2588,18 +2582,12 @@
task_shared_state(task_shared_state&);
public:
F f;
-#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- task_shared_state(BOOST_THREAD_RV_REF(F) f_):
- f(boost::forward<F>(f_))
- {}
-#else
task_shared_state(F const& f_):
f(f_)
{}
task_shared_state(BOOST_THREAD_RV_REF(F) f_):
- f(boost::move(f_)) // TODO forward
+ f(boost::move(f_))
{}
-#endif
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
void do_apply(BOOST_THREAD_RV_REF(ArgTypes) ... args)
Modified: trunk/libs/thread/test/sync/futures/packaged_task/func_ctor_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/futures/packaged_task/func_ctor_pass.cpp (original)
+++ trunk/libs/thread/test/sync/futures/packaged_task/func_ctor_pass.cpp 2013-06-01 10:27:16 EDT (Sat, 01 Jun 2013)
@@ -26,23 +26,32 @@
#if BOOST_THREAD_VERSION == 4
#define BOOST_THREAD_DETAIL_SIGNATURE double()
+#define BOOST_THREAD_DETAIL_VOID_SIGNATURE void()
#else
#define BOOST_THREAD_DETAIL_SIGNATURE double
+#define BOOST_THREAD_DETAIL_VOID_SIGNATURE void
#endif
#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK
#if defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
#define BOOST_THREAD_DETAIL_SIGNATURE_2 double(int, char)
#define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5 + 3 +'a'
+#define BOOST_THREAD_DETAIL_VOID_SIGNATURE_2 void(int)
#else
#define BOOST_THREAD_DETAIL_SIGNATURE_2 double()
#define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5
+#define BOOST_THREAD_DETAIL_VOID_SIGNATURE_2 void()
#endif
#else
#define BOOST_THREAD_DETAIL_SIGNATURE_2 double
#define BOOST_THREAD_DETAIL_SIGNATURE_2_RES 5
+#define BOOST_THREAD_DETAIL_VOID_SIGNATURE_2 void
#endif
+void void_fct()
+{
+ return;
+}
double fct()
{
return 5.0;
@@ -95,6 +104,8 @@
{
}
+ void operator()(int) const
+ { }
long operator()() const
{ return data_;}
long operator()(long i, long j) const
@@ -134,6 +145,8 @@
{
}
+ void operator()(int) const
+ { }
long operator()() const
{ return data_;}
long operator()(long i, long j) const
@@ -170,6 +183,8 @@
{
}
+ void operator()(int) const
+ { }
long operator()() const
{ return data_;}
long operator()(long i, long j) const
@@ -180,6 +195,7 @@
int main()
{
{
+ A::reset();
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p(BOOST_THREAD_MAKE_RV_REF(A(5)));
BOOST_TEST(p.valid());
boost::future<double> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
@@ -204,7 +220,6 @@
BOOST_TEST_EQ(A::n_copies, 1);
BOOST_TEST_EQ(A::n_moves, 0);
}
-
{
A::reset();
const A a(5);
@@ -217,6 +232,37 @@
BOOST_TEST_EQ(A::n_copies, 1);
BOOST_TEST_EQ(A::n_moves, 0);
}
+#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
+ {
+ A::reset();
+ boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE_2> p(BOOST_THREAD_MAKE_RV_REF(A(5)));
+ BOOST_TEST(p.valid());
+ boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
+ p(1);
+ BOOST_TEST(A::n_copies == 0);
+ BOOST_TEST_EQ(A::n_moves, 1);
+ }
+ {
+ A::reset();
+ A a(5);
+ boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE_2> p(a);
+ BOOST_TEST(p.valid());
+ boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
+ p(1);
+ BOOST_TEST_EQ(A::n_copies, 1);
+ BOOST_TEST_EQ(A::n_moves, 0);
+ }
+ {
+ A::reset();
+ const A a(5);
+ boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE_2> p(a);
+ BOOST_TEST(p.valid());
+ boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
+ p(1);
+ BOOST_TEST_EQ(A::n_copies, 1);
+ BOOST_TEST_EQ(A::n_moves, 0);
+ }
+#endif
{
M::reset();
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE_2> p(BOOST_THREAD_MAKE_RV_REF(M(5)));
@@ -241,7 +287,25 @@
BOOST_TEST(f.get() == 5.0);
BOOST_TEST_EQ(M::n_moves, 1);
}
-
+#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
+ {
+ M::reset();
+ boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE_2> p(BOOST_THREAD_MAKE_RV_REF(M(5)));
+ BOOST_TEST(p.valid());
+ boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
+ p(1);
+ BOOST_TEST_EQ(M::n_moves, 1);
+ }
+ {
+ M::reset();
+ M a(5);
+ boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE_2> p(boost::move(a));
+ BOOST_TEST(p.valid());
+ boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
+ p(1);
+ BOOST_TEST_EQ(M::n_moves, 1);
+ }
+#endif
{
C::reset();
C a(5);
@@ -265,6 +329,33 @@
BOOST_TEST(f.get() == 5.0);
BOOST_TEST_EQ(C::n_copies, 1);
}
+#if defined BOOST_THREAD_PROVIDES_SIGNATURE_PACKAGED_TASK && defined(BOOST_THREAD_PROVIDES_VARIADIC_THREAD)
+ {
+ C::reset();
+ C a(5);
+ boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE_2> p(a);
+ BOOST_TEST(p.valid());
+ boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
+ p(1);
+ BOOST_TEST_EQ(C::n_copies, 1);
+ }
+
+ {
+ C::reset();
+ const C a(5);
+ boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE_2> p(a);
+ BOOST_TEST(p.valid());
+ boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
+ p(1);
+ BOOST_TEST_EQ(C::n_copies, 1);
+ }
+#endif
+ {
+ boost::packaged_task<BOOST_THREAD_DETAIL_VOID_SIGNATURE> p(void_fct);
+ BOOST_TEST(p.valid());
+ boost::future<void> f = BOOST_THREAD_MAKE_RV_REF(p.get_future());
+ p();
+ }
{
boost::packaged_task<BOOST_THREAD_DETAIL_SIGNATURE> p(fct);
BOOST_TEST(p.valid());
Modified: trunk/libs/thread/test/test_8596.cpp
==============================================================================
--- trunk/libs/thread/test/test_8596.cpp (original)
+++ trunk/libs/thread/test/test_8596.cpp 2013-06-01 10:27:16 EDT (Sat, 01 Jun 2013)
@@ -6,6 +6,8 @@
#define BOOST_THREAD_VERSION 4
#include <iostream>
+#include <functional>
+#include <future>
#include <boost/thread.hpp>
#include <boost/shared_ptr.hpp>
@@ -26,6 +28,17 @@
return result;
}
+struct MyFunc
+{
+ MyFunc(MyFunc const&) = delete;
+ MyFunc& operator=(MyFunc const&) = delete;
+ MyFunc() {};
+ MyFunc(MyFunc &&) {};
+ MyFunc& operator=(MyFunc &&) { return *this;};
+ void operator()()const {}
+};
+
+
int main()
{
boost::packaged_task<int()>* p(schedule(f));
@@ -34,5 +47,36 @@
boost::future<int> fut = p->get_future();
std::cout << "The answer to the ultimate question: " << fut.get() << std::endl;
+ {
+ boost::function<void()> f;
+ MyFunc mf;
+
+ boost::packaged_task<void()> t1(f);
+ boost::packaged_task<void()> t2(boost::move(mf));
+ }
+// {
+// MyFunc mf;
+// //std::packaged_task<void()> t1(mf);
+// //std::function<void()> f1(std::move(mf));
+// std::function<void()> f1;
+// f1 = std::move(mf);
+//
+// //std::function<void()> f2((std::packaged_task<void()>(mf)));
+// }
+// {
+// MyFunc mf;
+// std::packaged_task<void()> t1(mf);
+//
+// std::function<void()> f2(std::move(t1));
+// }
+// {
+// MyFunc mf;
+// boost::packaged_task<void()> t1(mf);
+//
+// std::function<void()> f2(boost::move(t1));
+// }
+
return 0;
}
+
+
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