$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r81649 - in trunk/boost/thread: detail pthread v2
From: vicente.botet_at_[hidden]
Date: 2012-12-01 06:12:02
Author: viboes
Date: 2012-12-01 06:12:01 EST (Sat, 01 Dec 2012)
New Revision: 81649
URL: http://svn.boost.org/trac/boost/changeset/81649
Log:
Thread: update sleep_for algo depending on whether BOOST_THREAD_SLEEP_FOR_IS_STEADY is defined or not
Text files modified: 
   trunk/boost/thread/detail/config.hpp       |     7 +++++                                   
   trunk/boost/thread/pthread/thread_data.hpp |     5 +++                                     
   trunk/boost/thread/v2/thread.hpp           |    48 ++++++++++++++++++++++++++++++++------- 
   3 files changed, 50 insertions(+), 10 deletions(-)
Modified: trunk/boost/thread/detail/config.hpp
==============================================================================
--- trunk/boost/thread/detail/config.hpp	(original)
+++ trunk/boost/thread/detail/config.hpp	2012-12-01 06:12:01 EST (Sat, 01 Dec 2012)
@@ -281,6 +281,13 @@
 
 #include <boost/thread/detail/platform.hpp>
 
+#if defined(BOOST_THREAD_PLATFORM_WIN32)
+#else
+  #   if defined(BOOST_HAS_PTHREAD_DELAY_NP) || defined(BOOST_HAS_NANOSLEEP)
+  #     define BOOST_THREAD_SLEEP_FOR_IS_STEADY
+  #   endif
+#endif
+
 // provided for backwards compatibility, since this
 // macro was used for several releases by mistake.
 #if defined(BOOST_THREAD_DYN_DLL) && ! defined BOOST_THREAD_DYN_LINK
Modified: trunk/boost/thread/pthread/thread_data.hpp
==============================================================================
--- trunk/boost/thread/pthread/thread_data.hpp	(original)
+++ trunk/boost/thread/pthread/thread_data.hpp	2012-12-01 06:12:01 EST (Sat, 01 Dec 2012)
@@ -143,7 +143,7 @@
             typedef pthread_t native_handle_type;
 
             virtual void run()=0;
-            void notify_all_at_thread_exit(condition_variable* cv, mutex* m)
+            virtual void notify_all_at_thread_exit(condition_variable* cv, mutex* m)
             {
               notify.push_back(std::pair<condition_variable*, mutex*>(cv, m));
             }
@@ -221,11 +221,14 @@
       }
 
 #ifdef BOOST_THREAD_USES_CHRONO
+#ifdef BOOST_THREAD_SLEEP_FOR_IS_STEADY
+
         inline
         void BOOST_SYMBOL_VISIBLE sleep_for(const chrono::nanoseconds& ns)
         {
             return boost::this_thread::hiden::sleep_for(boost::detail::to_timespec(ns));
         }
+#endif
 #endif // BOOST_THREAD_USES_CHRONO
 
         void BOOST_THREAD_DECL yield() BOOST_NOEXCEPT;
Modified: trunk/boost/thread/v2/thread.hpp
==============================================================================
--- trunk/boost/thread/v2/thread.hpp	(original)
+++ trunk/boost/thread/v2/thread.hpp	2012-12-01 06:12:01 EST (Sat, 01 Dec 2012)
@@ -9,6 +9,7 @@
 #include <boost/thread/detail/config.hpp>
 #ifdef BOOST_THREAD_USES_CHRONO
 #include <boost/chrono/system_clocks.hpp>
+#include <boost/chrono/ceil.hpp>
 #endif
 #include <boost/thread/condition_variable.hpp>
 #include <boost/thread/lock_types.hpp>
@@ -20,15 +21,6 @@
 
 #ifdef BOOST_THREAD_USES_CHRONO
 
-    template <class Rep, class Period>
-    void sleep_for(const chrono::duration<Rep, Period>& d)
-    {
-      using namespace chrono;
-      nanoseconds ns = duration_cast<nanoseconds> (d);
-      if (ns < d) ++ns;
-      sleep_for(ns);
-    }
-
     template <class Clock, class Duration>
     void sleep_until(const chrono::time_point<Clock, Duration>& t)
     {
@@ -40,6 +32,28 @@
         cv.wait_until(lk, t);
     }
 
+#ifdef BOOST_THREAD_SLEEP_FOR_IS_STEADY
+
+    template <class Rep, class Period>
+    void sleep_for(const chrono::duration<Rep, Period>& d)
+    {
+      using namespace chrono;
+      if (d > duration<Rep, Period>::zero())
+      {
+          duration<long double> Max = nanoseconds::max();
+          nanoseconds ns;
+          if (d < Max)
+          {
+              ns = duration_cast<nanoseconds>(d);
+              if (ns < d)
+                  ++ns;
+          }
+          else
+              ns = nanoseconds::max();
+          sleep_for(ns);
+      }
+    }
+
     template <class Duration>
     inline BOOST_SYMBOL_VISIBLE
     void sleep_until(const chrono::time_point<chrono::steady_clock, Duration>& t)
@@ -47,6 +61,22 @@
       using namespace chrono;
       sleep_for(t - steady_clock::now());
     }
+#else
+    template <class Rep, class Period>
+    void sleep_for(const chrono::duration<Rep, Period>& d)
+    {
+      using namespace chrono;
+      if (d > duration<Rep, Period>::zero())
+      {
+        steady_clock::time_point c_now = steady_clock::now();
+        do
+        {
+          sleep_until(system_clock::now() + ceil<nanoseconds>(d));
+        } while (steady_clock::now() - c_now < d );
+      }
+    }
+
+#endif
 
 #endif
   }