Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77877 - in trunk: boost/thread libs/thread/doc libs/thread/test/sync/futures/packaged_task
From: vicente.botet_at_[hidden]
Date: 2012-04-09 21:37:19


Author: viboes
Date: 2012-04-09 21:37:18 EDT (Mon, 09 Apr 2012)
New Revision: 77877
URL: http://svn.boost.org/trac/boost/changeset/77877

Log:
Thread: Added pt test constructor from const functor + pt allocator ctor free fct+ cleanup of other tests
Text files modified:
   trunk/boost/thread/future.hpp | 18 ++++++++++++++-
   trunk/libs/thread/doc/future_ref.qbk | 5 ++++
   trunk/libs/thread/test/sync/futures/packaged_task/alloc_ctor_pass.cpp | 45 ++++++++++++++++++++++++++++++++++++++++
   trunk/libs/thread/test/sync/futures/packaged_task/copy_assign_fail.cpp | 16 +------------
   trunk/libs/thread/test/sync/futures/packaged_task/default_ctor_pass.cpp | 13 ----------
   trunk/libs/thread/test/sync/futures/packaged_task/func_ctor_pass.cpp | 38 +++++++++++++++++++++++++++++++++
   6 files changed, 107 insertions(+), 28 deletions(-)

Modified: trunk/boost/thread/future.hpp
==============================================================================
--- trunk/boost/thread/future.hpp (original)
+++ trunk/boost/thread/future.hpp 2012-04-09 21:37:18 EDT (Mon, 09 Apr 2012)
@@ -20,6 +20,7 @@
 #include <boost/type_traits/is_fundamental.hpp>
 #include <boost/type_traits/is_convertible.hpp>
 #include <boost/type_traits/remove_reference.hpp>
+#include <boost/type_traits/remove_cv.hpp>
 #include <boost/mpl/if.hpp>
 #include <boost/config.hpp>
 #include <boost/throw_exception.hpp>
@@ -1811,7 +1812,9 @@
 #ifndef BOOST_NO_RVALUE_REFERENCES
         template <class F>
         explicit packaged_task(F&& f):
- task(new detail::task_object<R,typename remove_reference<F>::type>(boost::forward<F>(f))),future_obtained(false)
+ task(new detail::task_object<R,
+ typename remove_cv<typename remove_reference<F>::type>::type
+ >(boost::forward<F>(f))),future_obtained(false)
         {}
 #else
         template <class F>
@@ -1832,11 +1835,22 @@
 #endif
 
 #if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
+ template <class Allocator>
+ packaged_task(boost::allocator_arg_t, Allocator a, R(*f)())
+ {
+ typedef R(*FR)();
+ typedef typename Allocator::template rebind<detail::task_object<R,FR> >::other A2;
+ A2 a2(a);
+ typedef thread_detail::allocator_destructor<A2> D;
+
+ task = task_ptr(::new(a2.allocate(1)) detail::task_object<R,FR>(f), D(a2, 1) );
+ future_obtained = false;
+ }
 #ifndef BOOST_NO_RVALUE_REFERENCES
         template <class F, class Allocator>
         packaged_task(boost::allocator_arg_t, Allocator a, F&& f)
         {
- typedef typename remove_reference<F>::type FR;
+ typedef typename remove_cv<typename remove_reference<F>::type>::type FR;
           typedef typename Allocator::template rebind<detail::task_object<R,FR> >::other A2;
           A2 a2(a);
           typedef thread_detail::allocator_destructor<A2> D;

Modified: trunk/libs/thread/doc/future_ref.qbk
==============================================================================
--- trunk/libs/thread/doc/future_ref.qbk (original)
+++ trunk/libs/thread/doc/future_ref.qbk 2012-04-09 21:37:18 EDT (Mon, 09 Apr 2012)
@@ -969,12 +969,16 @@
 [[Throws:] [Any exceptions thrown by the copy (or move) constructor of `f`. `std::bad_alloc` if memory for the internal data
 structures could not be allocated.]]
 
+[[Notes:] [The R(*f)()) overload to allow passing a function without needing to use `&`.]]
+
 ]
 
 [endsect]
 
 [section:alloc_constructor Allocator Constructor]
 
+ template <class Allocator>
+ packaged_task(allocator_arg_t, Allocator a, R(*f)());
         template <class F, class Allocator>
         packaged_task(allocator_arg_t, Allocator a, F&& f);
 
@@ -989,6 +993,7 @@
 structures could not be allocated.]]
 
 [[Notes:] [Available only if BOOST_THREAD_FUTURE_USES_ALLOCATORS is defined.]]
+[[Notes:] [The R(*f)()) overload to allow passing a function without needing to use `&`.]]
 
 ]
 

Modified: trunk/libs/thread/test/sync/futures/packaged_task/alloc_ctor_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/futures/packaged_task/alloc_ctor_pass.cpp (original)
+++ trunk/libs/thread/test/sync/futures/packaged_task/alloc_ctor_pass.cpp 2012-04-09 21:37:18 EDT (Mon, 09 Apr 2012)
@@ -27,6 +27,15 @@
 #if defined BOOST_THREAD_PROVIDES_FUTURE_CTOR_ALLOCATORS
 #include <libs/thread/test/sync/futures/test_allocator.hpp>
 
+double fct()
+{
+ return 5.0;
+}
+long lfct()
+{
+ return 5;
+}
+
 class A
 {
   long data_;
@@ -131,6 +140,42 @@
   BOOST_TEST(A::n_copies > 0);
   BOOST_TEST(A::n_moves > 0);
   BOOST_TEST(test_alloc_base::count == 0);
+ A::n_copies = 0;
+ A::n_copies = 0;
+ {
+ const A a(5);
+ boost::packaged_task<double> p(boost::allocator_arg,
+ test_allocator<A>(), a);
+ BOOST_TEST(test_alloc_base::count > 0);
+ BOOST_TEST(p.valid());
+ boost::future<double> f = BOOST_EXPLICIT_MOVE(p.get_future());
+ //p(3, 'a');
+ p();
+ BOOST_TEST(f.get() == 5.0);
+ }
+ BOOST_TEST(A::n_copies > 0);
+ BOOST_TEST(A::n_moves > 0);
+ BOOST_TEST(test_alloc_base::count == 0);
+ {
+ boost::packaged_task<double> p(boost::allocator_arg,
+ test_allocator<A>(), fct);
+ BOOST_TEST(test_alloc_base::count > 0);
+ BOOST_TEST(p.valid());
+ boost::future<double> f = BOOST_EXPLICIT_MOVE(p.get_future());
+ //p(3, 'a');
+ p();
+ BOOST_TEST(f.get() == 5.0);
+ }
+ {
+ boost::packaged_task<double> p(boost::allocator_arg,
+ test_allocator<A>(), &lfct);
+ BOOST_TEST(test_alloc_base::count > 0);
+ BOOST_TEST(p.valid());
+ boost::future<double> f = BOOST_EXPLICIT_MOVE(p.get_future());
+ //p(3, 'a');
+ p();
+ BOOST_TEST(f.get() == 5.0);
+ }
 
   return boost::report_errors();
 }

Modified: trunk/libs/thread/test/sync/futures/packaged_task/copy_assign_fail.cpp
==============================================================================
--- trunk/libs/thread/test/sync/futures/packaged_task/copy_assign_fail.cpp (original)
+++ trunk/libs/thread/test/sync/futures/packaged_task/copy_assign_fail.cpp 2012-04-09 21:37:18 EDT (Mon, 09 Apr 2012)
@@ -37,22 +37,10 @@
 int main()
 {
   {
- boost::packaged_task<double(int, char)> p0(A(5));
- boost::packaged_task<double(int, char)> p;
+ boost::packaged_task<double> p0(A(5));
+ boost::packaged_task<double> p;
       p = p0;
-// BOOST_TEST(!p0.valid());
-// BOOST_TEST(p.valid());
-// boost::future<double> f = p.get_future();
-// p(3, 'a');
-// BOOST_TEST(f.get() == 105.0);
   }
-// {
-// boost::packaged_task<double(int, char)> p0;
-// boost::packaged_task<double(int, char)> p;
-// p = p0;
-// BOOST_TEST(!p0.valid());
-// BOOST_TEST(!p.valid());
-// }
 
   return boost::report_errors();
 }

Modified: trunk/libs/thread/test/sync/futures/packaged_task/default_ctor_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/futures/packaged_task/default_ctor_pass.cpp (original)
+++ trunk/libs/thread/test/sync/futures/packaged_task/default_ctor_pass.cpp 2012-04-09 21:37:18 EDT (Mon, 09 Apr 2012)
@@ -22,22 +22,11 @@
 #include <boost/thread/future.hpp>
 #include <boost/detail/lightweight_test.hpp>
 
-class A
-{
- long data_;
-
-public:
- explicit A(long i) : data_(i) {}
-
- long operator()() const {return data_;}
- long operator()(long i, long j) const {return data_ + i + j;}
-};
-
 
 int main()
 {
   {
- boost::packaged_task<A> p;
+ boost::packaged_task<int> p;
     BOOST_TEST(!p.valid());
 
   }

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 2012-04-09 21:37:18 EDT (Mon, 09 Apr 2012)
@@ -23,6 +23,15 @@
 #include <boost/thread/future.hpp>
 #include <boost/detail/lightweight_test.hpp>
 
+double fct()
+{
+ return 5.0;
+}
+long lfct()
+{
+ return 5;
+}
+
 class A
 {
     long data_;
@@ -113,6 +122,35 @@
       BOOST_TEST(A::n_moves > 0);
   }
 
+ A::n_copies = 0;
+ A::n_copies = 0;
+ {
+ const A a(5);
+ boost::packaged_task<double> p(a);
+ BOOST_TEST(p.valid());
+ boost::future<double> f = BOOST_EXPLICIT_MOVE(p.get_future());
+ //p(3, 'a');
+ p();
+ BOOST_TEST(f.get() == 5.0);
+ BOOST_TEST(A::n_copies > 0);
+ BOOST_TEST(A::n_moves > 0);
+ }
+ {
+ boost::packaged_task<double> p(fct);
+ BOOST_TEST(p.valid());
+ boost::future<double> f = BOOST_EXPLICIT_MOVE(p.get_future());
+ //p(3, 'a');
+ p();
+ BOOST_TEST(f.get() == 5.0);
+ }
+ {
+ boost::packaged_task<double> p(&lfct);
+ BOOST_TEST(p.valid());
+ boost::future<double> f = BOOST_EXPLICIT_MOVE(p.get_future());
+ //p(3, 'a');
+ p();
+ BOOST_TEST(f.get() == 5.0);
+ }
 
   return boost::report_errors();
 }


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