Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81381 - in trunk: boost/thread/detail boost/thread/pthread libs/thread/src/pthread
From: vicente.botet_at_[hidden]
Date: 2012-11-17 02:50:58


Author: viboes
Date: 2012-11-17 02:50:56 EST (Sat, 17 Nov 2012)
New Revision: 81381
URL: http://svn.boost.org/trac/boost/changeset/81381

Log:
Thread: refactor time related conversions + move datetime deprecation to version 4
Text files modified:
   trunk/boost/thread/detail/config.hpp | 33 ++++++++++++++++++++-------------
   trunk/boost/thread/detail/thread.hpp | 7 ++-----
   trunk/boost/thread/pthread/condition_variable.hpp | 7 ++-----
   trunk/boost/thread/pthread/condition_variable_fwd.hpp | 9 +++------
   trunk/boost/thread/pthread/mutex.hpp | 12 +++++-------
   trunk/boost/thread/pthread/recursive_mutex.hpp | 11 ++++-------
   trunk/boost/thread/pthread/thread_data.hpp | 12 ++++--------
   trunk/boost/thread/pthread/timespec.hpp | 37 +++++++++++++++++++++++++++----------
   trunk/libs/thread/src/pthread/thread.cpp | 2 +-
   9 files changed, 68 insertions(+), 62 deletions(-)

Modified: trunk/boost/thread/detail/config.hpp
==============================================================================
--- trunk/boost/thread/detail/config.hpp (original)
+++ trunk/boost/thread/detail/config.hpp 2012-11-17 02:50:56 EST (Sat, 17 Nov 2012)
@@ -41,35 +41,44 @@
 #endif
 
 // This compiler doesn't support Boost.Chrono
-#if defined __IBMCPP__ && (__IBMCPP__ < 1100) && ! defined BOOST_THREAD_DONT_USE_CHRONO
+#if defined __IBMCPP__ && (__IBMCPP__ < 1100) \
+ && ! defined BOOST_THREAD_DONT_USE_CHRONO
 #define BOOST_THREAD_DONT_USE_CHRONO
+#if ! defined BOOST_THREAD_USE_DATE
 #define BOOST_THREAD_USE_DATE
 #endif
+#endif
 
 // This compiler doesn't support Boost.Move
-#if BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100) && ! defined BOOST_THREAD_DONT_USE_MOVE
+#if BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100) \
+ && ! defined BOOST_THREAD_DONT_USE_MOVE
 #define BOOST_THREAD_DONT_USE_MOVE
 #endif
 
 // This compiler doesn't support Boost.Container Allocators files
-#if defined __SUNPRO_CC && ! defined BOOST_THREAD_DONT_PROVIDE_FUTURE_CTOR_ALLOCATORS
+#if defined __SUNPRO_CC \
+ && ! defined BOOST_THREAD_DONT_PROVIDE_FUTURE_CTOR_ALLOCATORS
 #define BOOST_THREAD_DONT_PROVIDE_FUTURE_CTOR_ALLOCATORS
 #endif
 
-#if defined _WIN32_WCE && _WIN32_WCE==0x501 && ! defined BOOST_THREAD_DONT_PROVIDE_FUTURE_CTOR_ALLOCATORS
+#if defined _WIN32_WCE && _WIN32_WCE==0x501 \
+ && ! defined BOOST_THREAD_DONT_PROVIDE_FUTURE_CTOR_ALLOCATORS
 #define BOOST_THREAD_DONT_PROVIDE_FUTURE_CTOR_ALLOCATORS
 #endif
 
-#if ! defined BOOST_THREAD_DONT_PROVIDE_BASIC_THREAD_ID && ! defined BOOST_THREAD_PROVIDES_BASIC_THREAD_ID
+/// BASIC_THREAD_ID
+// todo to be removed for 1.54
+#if ! defined BOOST_THREAD_DONT_PROVIDE_BASIC_THREAD_ID \
+ && ! defined BOOST_THREAD_PROVIDES_BASIC_THREAD_ID
 #define BOOST_THREAD_PROVIDES_BASIC_THREAD_ID
 #endif
 
+/// RVALUE_REFERENCES_DONT_MATCH_FUNTION_PTR
 #if defined BOOST_NO_CXX11_RVALUE_REFERENCES || defined BOOST_MSVC
 #define BOOST_THREAD_RVALUE_REFERENCES_DONT_MATCH_FUNTION_PTR
 #endif
 
-
-// Default version is 3
+// Default version is 2
 #if !defined BOOST_THREAD_VERSION
 #define BOOST_THREAD_VERSION 2
 #else
@@ -80,7 +89,8 @@
 
 // CHRONO
 // Uses Boost.Chrono by default if not stated the opposite defining BOOST_THREAD_DONT_USE_CHRONO
-#if ! defined BOOST_THREAD_DONT_USE_CHRONO && ! defined BOOST_THREAD_USES_CHRONO
+#if ! defined BOOST_THREAD_DONT_USE_CHRONO \
+ && ! defined BOOST_THREAD_USES_CHRONO
 #define BOOST_THREAD_USES_CHRONO
 #endif
 
@@ -103,9 +113,10 @@
 #if BOOST_THREAD_VERSION>=3
 
 // ONCE_CXX11
+// fixme BOOST_THREAD_PROVIDES_ONCE_CXX11 doesn't works when thread.cpp is compiled BOOST_THREAD_VERSION 3
 #if ! defined BOOST_THREAD_DONT_PROVIDE_ONCE_CXX11 \
  && ! defined BOOST_THREAD_PROVIDES_ONCE_CXX11
-#define BOOST_THREAD_PROVIDES_ONCE_CXX11
+#define BOOST_THREAD_DONT_PROVIDE_ONCE_CXX11
 #endif
 
 // THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE
@@ -259,10 +270,6 @@
 #define BOOST_THREAD_PROVIDES_THREAD_EQ
 #endif
 
-//#if ! defined BOOST_THREAD_USES_DATETIME
-//#define defined BOOST_THREAD_USES_DATETIME
-//#endif
-
 #endif
 
 #if BOOST_WORKAROUND(__BORLANDC__, < 0x600)

Modified: trunk/boost/thread/detail/thread.hpp
==============================================================================
--- trunk/boost/thread/detail/thread.hpp (original)
+++ trunk/boost/thread/detail/thread.hpp 2012-11-17 02:50:56 EST (Sat, 17 Nov 2012)
@@ -513,7 +513,7 @@
 #if defined BOOST_THREAD_USES_DATETIME
         bool timed_join(const system_time& abs_time)
         {
- struct timespec const ts=detail::get_timespec(abs_time);
+ struct timespec const ts=detail::to_timespec(abs_time);
           return do_try_join_until(ts);
         }
 #endif
@@ -522,10 +522,7 @@
         {
           using namespace chrono;
           nanoseconds d = tp.time_since_epoch();
- timespec ts;
- seconds s = duration_cast<seconds>(d);
- ts.tv_sec = static_cast<long>(s.count());
- ts.tv_nsec = static_cast<long>((d - s).count());
+ timespec ts = boost::detail::to_timespec(d);
           return do_try_join_until(ts);
         }
 #endif

Modified: trunk/boost/thread/pthread/condition_variable.hpp
==============================================================================
--- trunk/boost/thread/pthread/condition_variable.hpp (original)
+++ trunk/boost/thread/pthread/condition_variable.hpp 2012-11-17 02:50:56 EST (Sat, 17 Nov 2012)
@@ -175,7 +175,7 @@
         template<typename lock_type>
         bool timed_wait(lock_type& m,boost::system_time const& wait_until)
         {
- struct timespec const timeout=detail::get_timespec(wait_until);
+ struct timespec const timeout=detail::to_timespec(wait_until);
             return do_timed_wait(m, timeout);
         }
         template<typename lock_type>
@@ -295,10 +295,7 @@
         {
             using namespace chrono;
             nanoseconds d = tp.time_since_epoch();
- timespec ts;
- seconds s = duration_cast<seconds>(d);
- ts.tv_sec = static_cast<long>(s.count());
- ts.tv_nsec = static_cast<long>((d - s).count());
+ timespec ts = boost::detail::to_timespec(d);
             if (do_timed_wait(lk, ts)) return cv_status::no_timeout;
             else return cv_status::timeout;
         }

Modified: trunk/boost/thread/pthread/condition_variable_fwd.hpp
==============================================================================
--- trunk/boost/thread/pthread/condition_variable_fwd.hpp (original)
+++ trunk/boost/thread/pthread/condition_variable_fwd.hpp 2012-11-17 02:50:56 EST (Sat, 17 Nov 2012)
@@ -72,10 +72,10 @@
             boost::system_time const& wait_until)
         {
 #if defined BOOST_THREAD_WAIT_BUG
- struct timespec const timeout=detail::get_timespec(wait_until + BOOST_THREAD_WAIT_BUG);
+ struct timespec const timeout=detail::to_timespec(wait_until + BOOST_THREAD_WAIT_BUG);
             return do_timed_wait(m, timeout);
 #else
- struct timespec const timeout=detail::get_timespec(wait_until);
+ struct timespec const timeout=detail::to_timespec(wait_until);
             return do_timed_wait(m, timeout);
 #endif
         }
@@ -218,10 +218,7 @@
         {
             using namespace chrono;
             nanoseconds d = tp.time_since_epoch();
- timespec ts;
- seconds s = duration_cast<seconds>(d);
- ts.tv_sec = static_cast<long>(s.count());
- ts.tv_nsec = static_cast<long>((d - s).count());
+ timespec ts = boost::detail::to_timespec(d);
             if (do_timed_wait(lk, ts)) return cv_status::no_timeout;
             else return cv_status::timeout;
         }

Modified: trunk/boost/thread/pthread/mutex.hpp
==============================================================================
--- trunk/boost/thread/pthread/mutex.hpp (original)
+++ trunk/boost/thread/pthread/mutex.hpp 2012-11-17 02:50:56 EST (Sat, 17 Nov 2012)
@@ -6,6 +6,7 @@
 // accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
+#include <boost/thread/detail/config.hpp>
 #include <pthread.h>
 #include <boost/throw_exception.hpp>
 #include <boost/thread/exceptions.hpp>
@@ -263,7 +264,7 @@
 #if defined BOOST_THREAD_USES_DATETIME
         bool timed_lock(system_time const & abs_time)
         {
- struct timespec const ts=detail::get_timespec(abs_time);
+ struct timespec const ts=boost::detail::to_timespec(abs_time);
             return do_try_lock_until(ts);
         }
 #endif
@@ -290,12 +291,9 @@
         }
         bool try_lock_until(const chrono::time_point<chrono::system_clock, chrono::nanoseconds>& tp)
         {
- using namespace chrono;
- nanoseconds d = tp.time_since_epoch();
- timespec ts;
- seconds s = duration_cast<seconds>(d);
- ts.tv_sec = static_cast<long>(s.count());
- ts.tv_nsec = static_cast<long>((d - s).count());
+ //using namespace chrono;
+ chrono::nanoseconds d = tp.time_since_epoch();
+ timespec ts = boost::detail::to_timespec(d);
           return do_try_lock_until(ts);
         }
 #endif

Modified: trunk/boost/thread/pthread/recursive_mutex.hpp
==============================================================================
--- trunk/boost/thread/pthread/recursive_mutex.hpp (original)
+++ trunk/boost/thread/pthread/recursive_mutex.hpp 2012-11-17 02:50:56 EST (Sat, 17 Nov 2012)
@@ -343,7 +343,7 @@
 #if defined BOOST_THREAD_USES_DATETIME
         bool timed_lock(system_time const & abs_time)
         {
- struct timespec const ts=detail::get_timespec(abs_time);
+ struct timespec const ts=detail::to_timespec(abs_time);
             return do_try_lock_until(ts);
         }
 #endif
@@ -370,12 +370,9 @@
         }
         bool try_lock_until(const chrono::time_point<chrono::system_clock, chrono::nanoseconds>& tp)
         {
- using namespace chrono;
- nanoseconds d = tp.time_since_epoch();
- timespec ts;
- seconds s = duration_cast<seconds>(d);
- ts.tv_sec = static_cast<long>(s.count());
- ts.tv_nsec = static_cast<long>((d - s).count());
+ //using namespace chrono;
+ chrono::nanoseconds d = tp.time_since_epoch();
+ timespec ts = boost::detail::to_timespec(d);
           return do_try_lock_until(ts);
         }
 #endif

Modified: trunk/boost/thread/pthread/thread_data.hpp
==============================================================================
--- trunk/boost/thread/pthread/thread_data.hpp (original)
+++ trunk/boost/thread/pthread/thread_data.hpp 2012-11-17 02:50:56 EST (Sat, 17 Nov 2012)
@@ -228,20 +228,16 @@
               {
 
   # if defined(BOOST_HAS_PTHREAD_DELAY_NP)
- timespec ts;
- ts.tv_sec = static_cast<long>(duration_cast<seconds>(ns).count());
- ts.tv_nsec = static_cast<long>((ns - seconds(ts.tv_sec)).count());
+ timespec ts = boost::detail::to_timespec(ns);
                 BOOST_VERIFY(!pthread_delay_np(&ts));
   # elif defined(BOOST_HAS_NANOSLEEP)
- timespec ts;
- ts.tv_sec = static_cast<long>(duration_cast<seconds>(ns).count());
- ts.tv_nsec = static_cast<long>((ns - seconds(ts.tv_sec)).count());
+ timespec ts = boost::detail::to_timespec(ns);
                 // nanosleep takes a timespec that is an offset, not
                 // an absolute time.
                 nanosleep(&ts, 0);
   # else
                 mutex mx;
- mutex::scoped_lock lock(mx);
+ unique_lock<mutex> lock(mx);
                 condition_variable cond;
                 cond.wait_for(lock, ns);
   # endif
@@ -261,7 +257,7 @@
         }
 
         template<>
- void BOOST_THREAD_DECL sleep(system_time const& abs_time);
+ void BOOST_THREAD_DECL sleep(system_time const& abs_time)
 #else
         void BOOST_THREAD_DECL sleep(system_time const& abs_time);
 

Modified: trunk/boost/thread/pthread/timespec.hpp
==============================================================================
--- trunk/boost/thread/pthread/timespec.hpp (original)
+++ trunk/boost/thread/pthread/timespec.hpp 2012-11-17 02:50:56 EST (Sat, 17 Nov 2012)
@@ -1,17 +1,23 @@
 #ifndef BOOST_THREAD_PTHREAD_TIMESPEC_HPP
 #define BOOST_THREAD_PTHREAD_TIMESPEC_HPP
-// (C) Copyright 2007-8 Anthony Williams
+// (C) Copyright 2007-8 Anthony Williams
 //
 // Distributed under the Boost Software License, Version 1.0. (See
 // accompanying file LICENSE_1_0.txt or copy at
 // http://www.boost.org/LICENSE_1_0.txt)
 
+#include <boost/thread/detail/config.hpp>
 #include <boost/thread/thread_time.hpp>
+#if defined BOOST_THREAD_USES_DATETIME
 #include <boost/date_time/posix_time/conversion.hpp>
+#endif
 #include <pthread.h>
 #ifndef _WIN32
 #include <unistd.h>
 #endif
+#ifdef BOOST_THREAD_USES_CHRONO
+#include <boost/chrono/duration.hpp>
+#endif
 
 #include <boost/config/abi_prefix.hpp>
 
@@ -19,15 +25,26 @@
 {
     namespace detail
     {
- inline struct timespec get_timespec(boost::system_time const& abs_time)
- {
- struct timespec timeout={0,0};
- boost::posix_time::time_duration const time_since_epoch=abs_time-boost::posix_time::from_time_t(0);
-
- timeout.tv_sec=time_since_epoch.total_seconds();
- timeout.tv_nsec=(long)(time_since_epoch.fractional_seconds()*(1000000000l/time_since_epoch.ticks_per_second()));
- return timeout;
- }
+#if defined BOOST_THREAD_USES_DATETIME
+ inline struct timespec to_timespec(boost::system_time const& abs_time)
+ {
+ struct timespec timeout={0,0};
+ boost::posix_time::time_duration const time_since_epoch=abs_time-boost::posix_time::from_time_t(0);
+
+ timeout.tv_sec=time_since_epoch.total_seconds();
+ timeout.tv_nsec=(long)(time_since_epoch.fractional_seconds()*(1000000000l/time_since_epoch.ticks_per_second()));
+ return timeout;
+ }
+#endif
+#if defined BOOST_THREAD_USES_CHRONO
+ inline timespec to_timespec(chrono::nanoseconds const& ns)
+ {
+ struct timespec ts;
+ ts.tv_sec = static_cast<long>(no::duration_cast<chrono::seconds>(ns).count());
+ ts.tv_nsec = static_cast<long>((ns - no::duration_cast<chrono::seconds>(ns)).count());
+ return ts;
+ }
+#endif
     }
 }
 

Modified: trunk/libs/thread/src/pthread/thread.cpp
==============================================================================
--- trunk/libs/thread/src/pthread/thread.cpp (original)
+++ trunk/libs/thread/src/pthread/thread.cpp 2012-11-17 02:50:56 EST (Sat, 17 Nov 2012)
@@ -452,7 +452,7 @@
                     nanosleep(&ts, 0);
 # else
                     mutex mx;
- mutex::scoped_lock lock(mx);
+ unique_lock<mutex> lock(mx);
                     condition cond;
                     cond.timed_wait(lock, xt);
 # endif


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