Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86443 - trunk/boost/thread
From: vicente.botet_at_[hidden]
Date: 2013-10-26 06:23:00


Author: viboes
Date: 2013-10-26 06:23:00 EDT (Sat, 26 Oct 2013)
New Revision: 86443
URL: http://svn.boost.org/trac/boost/changeset/86443

Log:
Thread: Adapt barrier to new nullary_function.

Text files modified:
   trunk/boost/thread/barrier.hpp | 119 +++++++++++++++++++++++++--------------
   1 files changed, 75 insertions(+), 44 deletions(-)

Modified: trunk/boost/thread/barrier.hpp
==============================================================================
--- trunk/boost/thread/barrier.hpp Sat Oct 26 06:21:27 2013 (r86442)
+++ trunk/boost/thread/barrier.hpp 2013-10-26 06:23:00 EDT (Sat, 26 Oct 2013) (r86443)
@@ -18,11 +18,7 @@
 #include <boost/thread/condition_variable.hpp>
 #include <string>
 #include <stdexcept>
-#ifdef BOOST_NO_CXX11_HDR_FUNCTIONAL
-#include <boost/function.hpp>
-#else
-#include <functional>
-#endif
+#include <boost/thread/detail/nullary_function.hpp>
 #include <boost/type_traits/is_same.hpp>
 #include <boost/type_traits/is_void.hpp>
 #include <boost/utility/enable_if.hpp>
@@ -34,13 +30,8 @@
 {
   namespace thread_detail
   {
-#ifdef BOOST_NO_CXX11_HDR_FUNCTIONAL
- typedef function<void()> void_completion_function;
- typedef function<size_t()> size_completion_function;
-#else
- typedef std::function<void()> void_completion_function;
- typedef std::function<size_t()> size_completion_function;
-#endif
+ typedef detail::nullary_function<void()> void_completion_function;
+ typedef detail::nullary_function<size_t()> size_completion_function;
 
     struct default_barrier_reseter
     {
@@ -49,6 +40,17 @@
         size_(size)
       {
       }
+ BOOST_THREAD_MOVABLE(default_barrier_reseter)
+
+ default_barrier_reseter(default_barrier_reseter const& other) BOOST_NOEXCEPT :
+ size_(other.size_)
+ {
+ }
+ default_barrier_reseter(BOOST_THREAD_RV_REF(default_barrier_reseter) other) BOOST_NOEXCEPT :
+ size_(BOOST_THREAD_RV(other).size_)
+ {
+ }
+
       unsigned int operator()()
       {
         return size_;
@@ -60,15 +62,25 @@
       unsigned int size_;
       void_completion_function fct_;
       template <typename F>
-#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
       void_functor_barrier_reseter(unsigned int size, BOOST_THREAD_RV_REF(F) funct)
       : size_(size), fct_(boost::move(funct))
       {}
-#else
- void_functor_barrier_reseter(unsigned int size, F funct)
+ template <typename F>
+ void_functor_barrier_reseter(unsigned int size, F& funct)
       : size_(size), fct_(funct)
       {}
-#endif
+
+ BOOST_THREAD_MOVABLE(void_functor_barrier_reseter)
+
+ void_functor_barrier_reseter(void_functor_barrier_reseter const& other) BOOST_NOEXCEPT :
+ size_(other.size_), fct_(other.fct_)
+ {
+ }
+ void_functor_barrier_reseter(BOOST_THREAD_RV_REF(void_functor_barrier_reseter) other) BOOST_NOEXCEPT :
+ size_(BOOST_THREAD_RV(other).size_), fct_(BOOST_THREAD_RV(other).fct_)
+ {
+ }
+
       unsigned int operator()()
       {
         fct_();
@@ -83,6 +95,16 @@
         size_(size), fct_(funct)
       {
       }
+ BOOST_THREAD_MOVABLE(void_fct_ptr_barrier_reseter)
+
+ void_fct_ptr_barrier_reseter(void_fct_ptr_barrier_reseter const& other) BOOST_NOEXCEPT :
+ size_(other.size_), fct_(other.fct_)
+ {
+ }
+ void_fct_ptr_barrier_reseter(BOOST_THREAD_RV_REF(void_fct_ptr_barrier_reseter) other) BOOST_NOEXCEPT :
+ size_(BOOST_THREAD_RV(other).size_), fct_(BOOST_THREAD_RV(other).fct_)
+ {
+ }
       unsigned int operator()()
       {
         fct_();
@@ -106,31 +128,37 @@
     BOOST_THREAD_NO_COPYABLE( barrier)
 
     explicit barrier(unsigned int count) :
- m_count(check_counter(count)), m_generation(0), fct_(thread_detail::default_barrier_reseter(count))
+ m_count(check_counter(count)), m_generation(0), fct_(BOOST_THREAD_MAKE_RV_REF(thread_detail::default_barrier_reseter(count)))
     {
     }
 
     template <typename F>
     barrier(
         unsigned int count,
-#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
         BOOST_THREAD_RV_REF(F) funct,
-#else
- F funct,
-#endif
         typename enable_if<
         typename is_void<typename result_of<F>::type>::type, dummy*
>::type=0
     )
     : m_count(check_counter(count)),
- m_generation(0),
- fct_(thread_detail::void_functor_barrier_reseter(count,
-#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
- boost::move(funct)
-#else
- funct
-#endif
- )
+ m_generation(0),
+ fct_(BOOST_THREAD_MAKE_RV_REF(thread_detail::void_functor_barrier_reseter(count,
+ boost::move(funct)))
+ )
+ {
+ }
+ template <typename F>
+ barrier(
+ unsigned int count,
+ F &funct,
+ typename enable_if<
+ typename is_void<typename result_of<F>::type>::type, dummy*
+ >::type=0
+ )
+ : m_count(check_counter(count)),
+ m_generation(0),
+ fct_(BOOST_THREAD_MAKE_RV_REF(thread_detail::void_functor_barrier_reseter(count,
+ funct))
     )
     {
     }
@@ -138,40 +166,43 @@
     template <typename F>
     barrier(
         unsigned int count,
-#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
         BOOST_THREAD_RV_REF(F) funct,
-#else
- F funct,
-#endif
         typename enable_if<
         typename is_same<typename result_of<F>::type, unsigned int>::type, dummy*
>::type=0
     )
     : m_count(check_counter(count)),
- m_generation(0),
- fct_(
-#ifndef BOOST_NO_CXX11_HDR_FUNCTIONAL
- boost::move(funct)
-#else
- funct
-#endif
+ m_generation(0),
+ fct_(boost::move(funct))
+ {
+ }
+ template <typename F>
+ barrier(
+ unsigned int count,
+ F& funct,
+ typename enable_if<
+ typename is_same<typename result_of<F>::type, unsigned int>::type, dummy*
+ >::type=0
     )
+ : m_count(check_counter(count)),
+ m_generation(0),
+ fct_(funct)
     {
     }
 
     barrier(unsigned int count, void(*funct)()) :
       m_count(check_counter(count)), m_generation(0),
       fct_(funct
- ? thread_detail::size_completion_function(thread_detail::void_fct_ptr_barrier_reseter(count, funct))
- : thread_detail::size_completion_function(thread_detail::default_barrier_reseter(count))
+ ? BOOST_THREAD_MAKE_RV_REF(thread_detail::size_completion_function(BOOST_THREAD_MAKE_RV_REF(thread_detail::void_fct_ptr_barrier_reseter(count, funct))))
+ : BOOST_THREAD_MAKE_RV_REF(thread_detail::size_completion_function(BOOST_THREAD_MAKE_RV_REF(thread_detail::default_barrier_reseter(count))))
       )
     {
     }
     barrier(unsigned int count, unsigned int(*funct)()) :
       m_count(check_counter(count)), m_generation(0),
       fct_(funct
- ? thread_detail::size_completion_function(funct)
- : thread_detail::size_completion_function(thread_detail::default_barrier_reseter(count))
+ ? BOOST_THREAD_MAKE_RV_REF(thread_detail::size_completion_function(funct))
+ : BOOST_THREAD_MAKE_RV_REF(thread_detail::size_completion_function(BOOST_THREAD_MAKE_RV_REF(thread_detail::default_barrier_reseter(count))))
       )
     {
     }


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