Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80122 - in trunk: boost/thread/detail boost/thread/pthread libs/thread/src/pthread libs/thread/src/win32
From: vicente.botet_at_[hidden]
Date: 2012-08-21 17:20:42


Author: viboes
Date: 2012-08-21 17:20:41 EDT (Tue, 21 Aug 2012)
New Revision: 80122
URL: http://svn.boost.org/trac/boost/changeset/80122

Log:
Thread: remove dependency from boo_thread to boost_chrono
Text files modified:
   trunk/boost/thread/detail/thread.hpp | 19 +++++++++++++++++
   trunk/boost/thread/pthread/thread_data.hpp | 38 +++++++++++++++++++++++++++++++++++
   trunk/libs/thread/src/pthread/thread.cpp | 42 ---------------------------------------
   trunk/libs/thread/src/win32/thread.cpp | 23 ---------------------
   4 files changed, 56 insertions(+), 66 deletions(-)

Modified: trunk/boost/thread/detail/thread.hpp
==============================================================================
--- trunk/boost/thread/detail/thread.hpp (original)
+++ trunk/boost/thread/detail/thread.hpp 2012-08-21 17:20:41 EDT (Tue, 21 Aug 2012)
@@ -366,7 +366,24 @@
         bool timed_join(const system_time& abs_time);
 
 #ifdef BOOST_THREAD_USES_CHRONO
- bool try_join_until(const chrono::time_point<chrono::system_clock, chrono::nanoseconds>& tp);
+ bool try_join_until(const chrono::time_point<chrono::system_clock, chrono::nanoseconds>& tp)
+ {
+ if (this_thread::get_id() == get_id())
+ {
+ boost::throw_exception(thread_resource_error(system::errc::resource_deadlock_would_occur, "boost thread: trying joining itself"));
+ }
+ detail::thread_data_ptr local_thread_info=(get_thread_info)();
+ if(local_thread_info)
+ {
+ chrono::milliseconds rel_time= chrono::ceil<chrono::milliseconds>(tp-chrono::system_clock::now());
+ if(!this_thread::interruptible_wait(local_thread_info->thread_handle,rel_time.count()))
+ {
+ return false;
+ }
+ release_handle();
+ }
+ return true;
+ }
 #endif
     public:
 

Modified: trunk/boost/thread/pthread/thread_data.hpp
==============================================================================
--- trunk/boost/thread/pthread/thread_data.hpp (original)
+++ trunk/boost/thread/pthread/thread_data.hpp 2012-08-21 17:20:41 EDT (Tue, 21 Aug 2012)
@@ -177,7 +177,43 @@
     namespace this_thread
     {
 #ifdef BOOST_THREAD_USES_CHRONO
- void BOOST_SYMBOL_VISIBLE sleep_for(const chrono::nanoseconds& ns);
+ inline
+ void BOOST_SYMBOL_VISIBLE sleep_for(const chrono::nanoseconds& ns)
+ {
+ using namespace chrono;
+ boost::detail::thread_data_base* const thread_info=boost::detail::get_current_thread_data();
+
+ if(thread_info)
+ {
+ unique_lock<mutex> lk(thread_info->sleep_mutex);
+ while(cv_status::no_timeout==thread_info->sleep_condition.wait_for(lk,ns)) {}
+ }
+ else
+ {
+ if (ns >= nanoseconds::zero())
+ {
+
+ # 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());
+ 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());
+ // nanosleep takes a timespec that is an offset, not
+ // an absolute time.
+ nanosleep(&ts, 0);
+ # else
+ mutex mx;
+ mutex::scoped_lock lock(mx);
+ condition_variable cond;
+ cond.wait_for(lock, ns);
+ # endif
+ }
+ }
+ }
 #endif
         void BOOST_THREAD_DECL yield() BOOST_NOEXCEPT;
 

Modified: trunk/libs/thread/src/pthread/thread.cpp
==============================================================================
--- trunk/libs/thread/src/pthread/thread.cpp (original)
+++ trunk/libs/thread/src/pthread/thread.cpp 2012-08-21 17:20:41 EDT (Tue, 21 Aug 2012)
@@ -24,7 +24,7 @@
 #include <unistd.h>
 #endif
 
-#include <libs/thread/src/pthread/timeconv.inl>
+#include "./timeconv.inl"
 
 namespace boost
 {
@@ -427,46 +427,6 @@
             }
         }
 
-#ifdef BOOST_THREAD_USES_CHRONO
- void
- sleep_for(const chrono::nanoseconds& ns)
- {
- using namespace chrono;
- boost::detail::thread_data_base* const thread_info=boost::detail::get_current_thread_data();
-
- if(thread_info)
- {
- unique_lock<mutex> lk(thread_info->sleep_mutex);
- while(cv_status::no_timeout==thread_info->sleep_condition.wait_for(lk,ns)) {}
- }
- else
- {
- if (ns >= nanoseconds::zero())
- {
-
- # 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());
- 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());
- // nanosleep takes a timespec that is an offset, not
- // an absolute time.
- nanosleep(&ts, 0);
- # else
- mutex mx;
- mutex::scoped_lock lock(mx);
- condition_variable cond;
- cond.wait_for(lock, ns);
- # endif
- }
- }
- }
-#endif
-
         void yield() BOOST_NOEXCEPT
         {
 # if defined(BOOST_HAS_SCHED_YIELD)

Modified: trunk/libs/thread/src/win32/thread.cpp
==============================================================================
--- trunk/libs/thread/src/win32/thread.cpp (original)
+++ trunk/libs/thread/src/win32/thread.cpp 2012-08-21 17:20:41 EDT (Tue, 21 Aug 2012)
@@ -334,29 +334,6 @@
         return true;
     }
 
-#ifdef BOOST_THREAD_USES_CHRONO
-
- bool thread::try_join_until(const chrono::time_point<chrono::system_clock, chrono::nanoseconds>& tp)
- {
- if (this_thread::get_id() == get_id())
- {
- boost::throw_exception(thread_resource_error(system::errc::resource_deadlock_would_occur, "boost thread: trying joining itself"));
- }
- detail::thread_data_ptr local_thread_info=(get_thread_info)();
- if(local_thread_info)
- {
- chrono::milliseconds rel_time= chrono::ceil<chrono::milliseconds>(tp-chrono::system_clock::now());
- if(!this_thread::interruptible_wait(local_thread_info->thread_handle,rel_time.count()))
- {
- return false;
- }
- release_handle();
- }
- return true;
- }
-
-#endif
-
     void thread::detach() BOOST_NOEXCEPT
     {
         release_handle();


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