Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r77933 - in trunk: boost/thread/detail libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons
From: vicente.botet_at_[hidden]
Date: 2012-04-12 07:12:24


Author: viboes
Date: 2012-04-12 07:12:23 EDT (Thu, 12 Apr 2012)
New Revision: 77933
URL: http://svn.boost.org/trac/boost/changeset/77933

Log:
Thread: symplify additonaly the conditional code + fix some spurious regression errors
Text files modified:
   trunk/boost/thread/detail/thread.hpp | 156 ++++++---------------------------------
   trunk/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/time_point_pass.cpp | 2
   trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/duration_pass.cpp | 3
   3 files changed, 29 insertions(+), 132 deletions(-)

Modified: trunk/boost/thread/detail/thread.hpp
==============================================================================
--- trunk/boost/thread/detail/thread.hpp (original)
+++ trunk/boost/thread/detail/thread.hpp 2012-04-12 07:12:23 EDT (Thu, 12 Apr 2012)
@@ -64,37 +64,30 @@
             public detail::thread_data_base
         {
         public:
+ BOOST_THREAD_NO_COPYABLE(thread_data)
 #ifndef BOOST_NO_RVALUE_REFERENCES
- thread_data(F&& f_):
- f(boost::forward<F>(f_))
- {}
+ thread_data(BOOST_THREAD_RV_REF(F) f_):
+ f(boost::forward<F>(f_))
+ {}
 // This overloading must be removed if we want the packaged_task's tests to pass.
 // thread_data(F& f_):
 // f(f_)
 // {}
 #else
- thread_data(F f_):
- f(f_)
- {}
-#if defined BOOST_THREAD_USES_MOVE
- thread_data(boost::rv<F>& f_):
- f(f_)
+
+ thread_data(BOOST_THREAD_RV_REF(F) f_):
+ f(f_)
             {}
-#else
- thread_data(detail::thread_move_t<F> f_):
+ thread_data(F f_):
                 f(f_)
             {}
 #endif
-#endif
             void run()
             {
                 f();
             }
         private:
             F f;
-
- void operator=(thread_data&);
- thread_data(thread_data&);
         };
 
         template<typename F>
@@ -103,14 +96,11 @@
         {
         private:
             F& f;
-
- void operator=(thread_data&);
- thread_data(thread_data&);
         public:
+ BOOST_THREAD_NO_COPYABLE(thread_data)
             thread_data(boost::reference_wrapper<F> f_):
                 f(f_)
             {}
-
             void run()
             {
                 f();
@@ -123,13 +113,11 @@
         {
         private:
             F& f;
- void operator=(thread_data&);
- thread_data(thread_data&);
         public:
+ BOOST_THREAD_NO_COPYABLE(thread_data)
             thread_data(const boost::reference_wrapper<F> f_):
                 f(f_)
             {}
-
             void run()
             {
                 f();
@@ -174,22 +162,13 @@
         {
             return detail::thread_data_ptr(detail::heap_new<detail::thread_data<F> >(f));
         }
-#if defined BOOST_THREAD_USES_MOVE
- template<typename F>
- static inline detail::thread_data_ptr make_thread_info(boost::rv<F>& f)
- {
- return detail::thread_data_ptr(detail::heap_new<detail::thread_data<F> >(boost::move(f)));
- }
-
-#else
         template<typename F>
- static inline detail::thread_data_ptr make_thread_info(boost::detail::thread_move_t<F> f)
+ static inline detail::thread_data_ptr make_thread_info(BOOST_THREAD_RV_REF(F) f)
         {
             return detail::thread_data_ptr(detail::heap_new<detail::thread_data<F> >(f));
         }
 
 #endif
-#endif
         struct dummy;
     public:
 #if BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100)
@@ -243,11 +222,6 @@
             return *this;
         }
 
-// thread&& move()
-// {
-// return ::boost::move(*this);
-// }
-
 #else
 #ifdef BOOST_NO_SFINAE
         template <class F>
@@ -263,80 +237,44 @@
             start_thread(attrs);
         }
 #else
-#if defined BOOST_THREAD_USES_MOVE
         template <class F>
- explicit thread(F f,typename disable_if<boost::is_convertible<F&,boost::rv<F>& >, dummy* >::type=0):
+ explicit thread(F f,typename disable_if<boost::is_convertible<F&,BOOST_THREAD_RV_REF(F) >, dummy* >::type=0):
             thread_info(make_thread_info(f))
         {
             start_thread();
         }
         template <class F>
- thread(attributes& attrs, F f,typename disable_if<boost::is_convertible<F&,boost::rv<F>& >, dummy* >::type=0):
- thread_info(make_thread_info(f))
- {
- start_thread(attrs);
- }
-#else
- template <class F>
- explicit thread(F f,typename disable_if<boost::is_convertible<F&,detail::thread_move_t<F> >, dummy* >::type=0):
- thread_info(make_thread_info(f))
- {
- start_thread();
- }
- template <class F>
- thread(attributes& attrs, F f,typename disable_if<boost::is_convertible<F&,detail::thread_move_t<F> >, dummy* >::type=0):
+ thread(attributes& attrs, F f,typename disable_if<boost::is_convertible<F&,BOOST_THREAD_RV_REF(F) >, dummy* >::type=0):
             thread_info(make_thread_info(f))
         {
             start_thread(attrs);
         }
 #endif
-#endif
 
-#if defined BOOST_THREAD_USES_MOVE
         template <class F>
- explicit thread(boost::rv<F>& f):
- thread_info(make_thread_info(boost::move(f)))
+ explicit thread(BOOST_THREAD_RV_REF(F) f):
+ thread_info(make_thread_info(f))
         {
             start_thread();
         }
 
-
-// explicit thread(void (*f)()):
-// thread_info(make_thread_info(f))
-// {
-// start_thread();
-// }
-//
-
         template <class F>
- thread(attributes& attrs, boost::rv<F>& f):
- thread_info(make_thread_info(boost::move(f)))
+ thread(attributes& attrs, BOOST_THREAD_RV_REF(F) f):
+ thread_info(make_thread_info(f))
         {
             start_thread(attrs);
         }
 
+#if defined BOOST_THREAD_USES_MOVE
 
- thread(boost::rv<thread>& x)
+ thread(BOOST_THREAD_RV_REF(thread) x)
         {
             thread_info=x.thread_info;
             x.thread_info.reset();
         }
 #else
- template <class F>
- explicit thread(detail::thread_move_t<F> f):
- thread_info(make_thread_info(f))
- {
- start_thread();
- }
-
- template <class F>
- thread(attributes& attrs, detail::thread_move_t<F> f):
- thread_info(make_thread_info(f))
- {
- start_thread(attrs);
- }
 
- thread(detail::thread_move_t<thread> x)
+ thread(BOOST_THREAD_RV_REF(thread) x)
         {
             thread_info=x->thread_info;
             x->thread_info.reset();
@@ -350,18 +288,7 @@
             return *this;
         }
 #else
-#if defined BOOST_THREAD_USES_MOVE
- thread& operator=(boost::rv<thread>& x) BOOST_NOEXCEPT
- {
-#if defined BOOST_THREAD_PROVIDES_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE
- if (joinable()) std::terminate();
-#endif
- thread new_thread(boost::move(x));
- swap(new_thread);
- return *this;
- }
-#else
- thread& operator=(detail::thread_move_t<thread> x) BOOST_NOEXCEPT
+ thread& operator=(BOOST_THREAD_RV_REF(thread) x) BOOST_NOEXCEPT
         {
 #if defined BOOST_THREAD_PROVIDES_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE
             if (joinable()) std::terminate();
@@ -372,7 +299,6 @@
         }
 #endif
 #endif
-#endif
 
         template <class F,class A1>
         thread(F f,A1 a1,typename disable_if<boost::is_convertible<F&,thread_attributes >, dummy* >::type=0):
@@ -447,9 +373,6 @@
 
         bool joinable() const BOOST_NOEXCEPT;
         void join();
-#if defined(BOOST_THREAD_PLATFORM_WIN32)
- bool timed_join(const system_time& abs_time); // DEPRECATED V2
-
 #ifdef BOOST_THREAD_USES_CHRONO
         template <class Rep, class Period>
         bool try_join_for(const chrono::duration<Rep, Period>& rel_time)
@@ -471,6 +394,11 @@
           typedef time_point<system_clock, nanoseconds> nano_sys_tmpt;
           return try_join_until(nano_sys_tmpt(ceil<nanoseconds>(t.time_since_epoch())));
         }
+#endif
+#if defined(BOOST_THREAD_PLATFORM_WIN32)
+ bool timed_join(const system_time& abs_time); // DEPRECATED V2
+
+#ifdef BOOST_THREAD_USES_CHRONO
         bool try_join_until(const chrono::time_point<chrono::system_clock, chrono::nanoseconds>& tp);
 #endif
     public:
@@ -482,26 +410,6 @@
           return do_try_join_until(ts);
         }
 #ifdef BOOST_THREAD_USES_CHRONO
- template <class Rep, class Period>
- bool try_join_for(const chrono::duration<Rep, Period>& rel_time)
- {
- return try_join_until(chrono::steady_clock::now() + rel_time);
- }
- template <class Clock, class Duration>
- bool try_join_until(const chrono::time_point<Clock, Duration>& t)
- {
- using namespace chrono;
- system_clock::time_point s_now = system_clock::now();
- typename Clock::time_point c_now = Clock::now();
- return try_join_until(s_now + ceil<nanoseconds>(t - c_now));
- }
- template <class Duration>
- bool try_join_until(const chrono::time_point<chrono::system_clock, Duration>& t)
- {
- using namespace chrono;
- typedef time_point<system_clock, nanoseconds> nano_sys_tmpt;
- return try_join_until(nano_sys_tmpt(ceil<nanoseconds>(t.time_since_epoch())));
- }
         bool try_join_until(const chrono::time_point<chrono::system_clock, chrono::nanoseconds>& tp)
         {
           using namespace chrono;
@@ -562,17 +470,6 @@
     {
         return static_cast<thread&&>(t);
     }
- inline thread&& move(thread&& t) BOOST_NOEXCEPT
- {
- return static_cast<thread&&>(t);
- }
-#else
-#if !defined BOOST_THREAD_USES_MOVE
- inline detail::thread_move_t<thread> move(detail::thread_move_t<thread> t) BOOST_NOEXCEPT
- {
- return t;
- }
-#endif
 #endif
 
 #ifdef BOOST_NO_RVALUE_REFERENCES
@@ -632,7 +529,6 @@
         id() BOOST_NOEXCEPT:
 #if defined BOOST_THREAD_PROVIDES_BASIC_THREAD_ID
 #if defined(BOOST_THREAD_PLATFORM_WIN32)
- //thread_data(detail::win32::invalid_handle_value)
         thread_data(0)
 #else
         thread_data(0)

Modified: trunk/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/time_point_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/time_point_pass.cpp (original)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/shared_lock/cons/time_point_pass.cpp 2012-04-12 07:12:23 EDT (Thu, 12 Apr 2012)
@@ -67,7 +67,7 @@
   {
     m.lock();
     boost::thread t(f2);
- boost::this_thread::sleep_for(ms(300));
+ boost::this_thread::sleep_for(ms(300)+ms(1000));
     m.unlock();
     t.join();
   }

Modified: trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/duration_pass.cpp
==============================================================================
--- trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/duration_pass.cpp (original)
+++ trunk/libs/thread/test/sync/mutual_exclusion/locks/upgrade_lock/cons/duration_pass.cpp 2012-04-12 07:12:23 EDT (Thu, 12 Apr 2012)
@@ -38,7 +38,8 @@
 void f1()
 {
   time_point t0 = Clock::now();
- boost::upgrade_lock<boost::shared_mutex> lk(m, ms(300));
+ // This test is spurious as it depends on the time the thread system switches the threads
+ boost::upgrade_lock<boost::shared_mutex> lk(m, ms(300)+ms(1000));
   BOOST_TEST(lk.owns_lock() == true);
   time_point t1 = Clock::now();
   ns d = t1 - t0 - ms(250);


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