|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r77375 - in trunk: boost/thread/detail boost/thread/win32 libs/thread/src/win32
From: vicente.botet_at_[hidden]
Date: 2012-03-18 13:26:31
Author: viboes
Date: 2012-03-18 13:26:30 EDT (Sun, 18 Mar 2012)
New Revision: 77375
URL: http://svn.boost.org/trac/boost/changeset/77375
Log:
Thread: Fix bug on time related functions that should base the _for functions on the until_ ones
Text files modified:
trunk/boost/thread/detail/thread.hpp | 17 ++++--
trunk/boost/thread/win32/basic_timed_mutex.hpp | 90 ++++++++++++++++++++++-----------------
trunk/libs/thread/src/win32/thread.cpp | 17 ++++---
3 files changed, 71 insertions(+), 53 deletions(-)
Modified: trunk/boost/thread/detail/thread.hpp
==============================================================================
--- trunk/boost/thread/detail/thread.hpp (original)
+++ trunk/boost/thread/detail/thread.hpp 2012-03-18 13:26:30 EDT (Sun, 18 Mar 2012)
@@ -503,19 +503,24 @@
template <class Rep, class Period>
bool try_join_for(const chrono::duration<Rep, Period>& rel_time)
{
- return try_join_for(chrono::ceil<chrono::milliseconds>(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_for(chrono::ceil<chrono::milliseconds>(t - c_now));
+ return try_join_until(s_now + ceil<nanoseconds>(t - c_now));
}
-#endif
- private:
-#ifdef BOOST_THREAD_USES_CHRONO
- bool do_try_join_for(chrono::milliseconds const &rel_time_in_milliseconds);
+ 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);
#endif
public:
Modified: trunk/boost/thread/win32/basic_timed_mutex.hpp
==============================================================================
--- trunk/boost/thread/win32/basic_timed_mutex.hpp (original)
+++ trunk/boost/thread/win32/basic_timed_mutex.hpp 2012-03-18 13:26:30 EDT (Sun, 18 Mar 2012)
@@ -145,34 +145,7 @@
}
return true;
}
- bool try_lock_for(chrono::milliseconds const& rel_time)
- {
- if(try_lock())
- {
- return true;
- }
- long old_count=active_count;
- mark_waiting_and_try_lock(old_count);
-
- if(old_count&lock_flag_value)
- {
- bool lock_acquired=false;
- void* const sem=get_event();
- do
- {
- if(win32::WaitForSingleObject(sem,static_cast<unsigned long>(rel_time.count()))!=0)
- {
- BOOST_INTERLOCKED_DECREMENT(&active_count);
- return false;
- }
- clear_waiting_and_try_lock(old_count);
- lock_acquired=!(old_count&lock_flag_value);
- }
- while(!lock_acquired);
- }
- return true;
- }
template<typename Duration>
bool timed_lock(Duration const& timeout)
@@ -185,19 +158,56 @@
return timed_lock(system_time(timeout));
}
- template <class Rep, class Period>
- bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
- {
- using namespace chrono;
- return try_lock_for(ceil<milliseconds>(rel_time));
- }
- template <class Clock, class Duration>
- bool try_lock_until(const chrono::time_point<Clock, Duration>& t)
- {
- using namespace chrono;
- typename Clock::time_point c_now = Clock::now();
- return try_lock_for(ceil<milliseconds>(t - c_now));
- }
+ template <class Rep, class Period>
+ bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
+ {
+ return try_lock_until(chrono::steady_clock::now() + rel_time);
+ }
+ template <class Clock, class Duration>
+ bool try_lock_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_lock_until(s_now + ceil<system_clock::duration>(t - c_now));
+ }
+ template <class Duration>
+ bool try_lock_until(const chrono::time_point<chrono::system_clock, Duration>& t)
+ {
+ using namespace chrono;
+ typedef time_point<chrono::system_clock, chrono::system_clock::duration> sys_tmpt;
+ return try_lock_until(sys_tmpt(chrono::ceil<chrono::system_clock::duration>(t.time_since_epoch())));
+ }
+ bool try_lock_until(const chrono::time_point<chrono::system_clock, chrono::system_clock::duration>& tp)
+ {
+ if(try_lock())
+ {
+ return true;
+ }
+ long old_count=active_count;
+ mark_waiting_and_try_lock(old_count);
+
+ if(old_count&lock_flag_value)
+ {
+ bool lock_acquired=false;
+ void* const sem=get_event();
+
+ do
+ {
+ chrono::milliseconds rel_time= chrono::ceil<chrono::milliseconds>(tp-chrono::system_clock::now());
+
+ if(win32::WaitForSingleObject(sem,static_cast<unsigned long>(rel_time.count()))!=0)
+ {
+ BOOST_INTERLOCKED_DECREMENT(&active_count);
+ return false;
+ }
+ clear_waiting_and_try_lock(old_count);
+ lock_acquired=!(old_count&lock_flag_value);
+ }
+ while(!lock_acquired);
+ }
+ return true;
+ }
void unlock()
{
Modified: trunk/libs/thread/src/win32/thread.cpp
==============================================================================
--- trunk/libs/thread/src/win32/thread.cpp (original)
+++ trunk/libs/thread/src/win32/thread.cpp 2012-03-18 13:26:30 EDT (Sun, 18 Mar 2012)
@@ -319,7 +319,9 @@
}
#ifdef BOOST_THREAD_USES_CHRONO
- bool thread::do_try_join_for(chrono::milliseconds const &rel_time_in_milliseconds) {
+
+ 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"));
@@ -327,15 +329,16 @@
detail::thread_data_ptr local_thread_info=(get_thread_info)();
if(local_thread_info)
{
- if(!this_thread::interruptible_wait(local_thread_info->thread_handle,rel_time_in_milliseconds.count()))
- {
- return false;
- }
- release_handle();
+ 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-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