Boost logo

Boost-Commit :

From: hinnant_at_[hidden]
Date: 2007-11-28 21:12:55


Author: hinnant
Date: 2007-11-28 21:12:54 EST (Wed, 28 Nov 2007)
New Revision: 41451
URL: http://svn.boost.org/trac/boost/changeset/41451

Log:
Added cv::timed_wait duration overload and beefed up constraints on the Duration template parameter everywhere
Text files modified:
   sandbox/committee/LWG/ref_impl/condition_variable | 40 ++++++++++++++++++++++++++++++++++++----
   sandbox/committee/LWG/ref_impl/hdate_time | 27 +++++++++++++++++++++++++--
   sandbox/committee/LWG/ref_impl/mutex | 6 ++++--
   sandbox/committee/LWG/ref_impl/mutex_base | 6 ++++--
   sandbox/committee/LWG/ref_impl/thread | 4 +++-
   5 files changed, 72 insertions(+), 11 deletions(-)

Modified: sandbox/committee/LWG/ref_impl/condition_variable
==============================================================================
--- sandbox/committee/LWG/ref_impl/condition_variable (original)
+++ sandbox/committee/LWG/ref_impl/condition_variable 2007-11-28 21:12:54 EST (Wed, 28 Nov 2007)
@@ -27,6 +27,8 @@
         template <class Predicate>
             void wait(unique_lock<mutex>& lock, Predicate pred);
         bool timed_wait(unique_lock<mutex>& lock, const system_time& abs_time);
+ template <class Duration>
+ bool timed_wait(unique_lock<mutex>& lock, const Duration& rel_time);
         template <class Predicate>
             bool timed_wait(unique_lock<mutex>& lock, const system_time& abs_time, Predicate pred);
         template <class Duration, class Predicate>
@@ -54,6 +56,8 @@
             void wait(Lock& lock, Predicate pred);
         template <class Lock>
             bool timed_wait(Lock& lock, const system_time& abs_time);
+ template <class Lock, class Duration>
+ bool timed_wait(Lock& lock, const Duration& rel_time);
         template <class Lock, class Predicate>
             bool timed_wait(Lock& lock, const system_time& abs_time, Predicate pred);
         template <class Lock, class Duration, class Predicate>
@@ -96,10 +100,14 @@
     template <class Predicate>
         void wait(unique_lock<mutex>& lock, Predicate pred);
     bool timed_wait(unique_lock<mutex>& lock, const system_time& abs_time);
+ template <class Duration>
+ bool timed_wait(unique_lock<mutex>& lock, const Duration& rel_time,
+ typename enable_if<__is_duration<Duration>::value>::type* =0);
     template <class Predicate>
         bool timed_wait(unique_lock<mutex>& lock, const system_time& abs_time, Predicate pred);
     template <class Duration, class Predicate>
- bool timed_wait(unique_lock<mutex>& lock, const Duration& rel_time, Predicate pred);
+ bool timed_wait(unique_lock<mutex>& lock, const Duration& rel_time, Predicate pred,
+ typename enable_if<__is_duration<Duration>::value>::type* =0);
 
     typedef pthread_cond_t* native_handle_type;
     native_handle_type native_handle() {return &cv_;}
@@ -116,6 +124,15 @@
     __do_wait(lock.mutex()->native_handle());
 }
 
+template <class Duration>
+inline
+bool
+condition_variable::timed_wait(unique_lock<mutex>& lock, const Duration& rel_time,
+ typename enable_if<__is_duration<Duration>::value>::type*)
+{
+ return timed_wait(lock, get_system_time() + rel_time);
+}
+
 template <class Predicate>
 void
 condition_variable::wait(unique_lock<mutex>& lock, Predicate pred)
@@ -144,7 +161,8 @@
 template <class Duration, class Predicate>
 inline
 bool
-condition_variable::timed_wait(unique_lock<mutex>& lock, const Duration& rel_time, Predicate pred)
+condition_variable::timed_wait(unique_lock<mutex>& lock, const Duration& rel_time, Predicate pred,
+ typename enable_if<__is_duration<Duration>::value>::type*)
 {
     return timed_wait(lock, get_system_time() + rel_time, std::move(pred));
 }
@@ -169,10 +187,14 @@
         void wait(Lock& lock, Predicate pred);
     template <class Lock>
         bool timed_wait(Lock& lock, const system_time& abs_time);
+ template <class Lock, class Duration>
+ bool timed_wait(Lock& lock, const Duration& rel_time,
+ typename enable_if<__is_duration<Duration>::value>::type* =0);
     template <class Lock, class Predicate>
         bool timed_wait(Lock& lock, const system_time& abs_time, Predicate pred);
     template <class Lock, class Duration, class Predicate>
- bool timed_wait(Lock& lock, const Duration& rel_time, Predicate pred);
+ bool timed_wait(Lock& lock, const Duration& rel_time, Predicate pred,
+ typename enable_if<__is_duration<Duration>::value>::type* =0);
 };
 
 inline
@@ -224,6 +246,15 @@
     return cv_.timed_wait(lk, abs_time);
 } // mut_.unlock(), lock.lock()
 
+template <class Lock, class Duration>
+inline
+bool
+condition_variable_any::timed_wait(Lock& lock, const Duration& rel_time,
+ typename enable_if<__is_duration<Duration>::value>::type*)
+{
+ return timed_wait(lock, get_system_time() + rel_time);
+}
+
 template <class Lock, class Predicate>
 inline
 bool
@@ -238,7 +269,8 @@
 template <class Lock, class Duration, class Predicate>
 inline
 bool
-condition_variable_any::timed_wait(Lock& lock, const Duration& rel_time, Predicate pred)
+condition_variable_any::timed_wait(Lock& lock, const Duration& rel_time, Predicate pred,
+ typename enable_if<__is_duration<Duration>::value>::type*)
 {
     return timed_wait(lock, get_system_time() + rel_time, std::move(pred));
 }

Modified: sandbox/committee/LWG/ref_impl/hdate_time
==============================================================================
--- sandbox/committee/LWG/ref_impl/hdate_time (original)
+++ sandbox/committee/LWG/ref_impl/hdate_time 2007-11-28 21:12:54 EST (Wed, 28 Nov 2007)
@@ -416,19 +416,42 @@
 */
 
 #include <ctime>
+#include <type_traits>
 
 namespace std {
 
 template <class T>
-class __is_duration
+class __has_tick_type
+{
+ struct two {char x; char y;};
+ template <class U> static two test(...);
+ template <class U> static char test(typename U::tick_type*);
+public:
+ static const bool value = sizeof(test<T>(0)) == 1;
+};
+
+template <class T, T val>
+struct __member_wrapper{};
+
+template <class T>
+class __has_get_count
 {
         struct two {char x; char y;};
         template <class U> static two test(...);
- template <class U> static char test(typename U::tick_type* = 0);
+ template <class U> static char test(__member_wrapper<typename U::tick_type (U::*)() const, &U::get_count>*);
 public:
         static const bool value = sizeof(test<T>(0)) == 1;
 };
 
+template <class T>
+class __is_duration
+{
+public:
+ static const bool value = __has_tick_type<T>::value &&
+ __has_get_count<T>::value &&
+ stb::is_convertible<long long, T>::value;
+};
+
 class nanoseconds
 {
 public:

Modified: sandbox/committee/LWG/ref_impl/mutex
==============================================================================
--- sandbox/committee/LWG/ref_impl/mutex (original)
+++ sandbox/committee/LWG/ref_impl/mutex 2007-11-28 21:12:54 EST (Wed, 28 Nov 2007)
@@ -200,7 +200,8 @@
     void lock();
     bool try_lock();
     template <class Duration>
- bool timed_lock(const Duration& rel_time)
+ bool timed_lock(const Duration& rel_time,
+ typename enable_if<__is_duration<Duration>::value>::type* =0)
             {return timed_lock(get_system_time() + rel_time);}
     bool timed_lock(const system_time& abs_time);
     void unlock();
@@ -223,7 +224,8 @@
     void lock();
     bool try_lock();
     template <class Duration>
- bool timed_lock(const Duration& rel_time)
+ bool timed_lock(const Duration& rel_time,
+ typename enable_if<__is_duration<Duration>::value>::type* =0)
             {return timed_lock(get_system_time() + rel_time);}
     bool timed_lock(const system_time& abs_time);
     void unlock();

Modified: sandbox/committee/LWG/ref_impl/mutex_base
==============================================================================
--- sandbox/committee/LWG/ref_impl/mutex_base (original)
+++ sandbox/committee/LWG/ref_impl/mutex_base 2007-11-28 21:12:54 EST (Wed, 28 Nov 2007)
@@ -167,7 +167,8 @@
     void lock();
     bool try_lock();
     template <class Duration>
- bool timed_lock(const Duration& rel_t);
+ bool timed_lock(const Duration& rel_t,
+ typename enable_if<__is_duration<Duration>::value>::type* =0);
     bool timed_lock(const system_time& abs_time);
     void unlock();
 
@@ -217,7 +218,8 @@
 template <class Mutex>
 template <class Duration>
 bool
-unique_lock<Mutex>::timed_lock(const Duration& rel_t)
+unique_lock<Mutex>::timed_lock(const Duration& rel_t,
+ typename enable_if<__is_duration<Duration>::value>::type*)
 {
     if (m_ == 0 || owns_lock_)
         throw lock_error();

Modified: sandbox/committee/LWG/ref_impl/thread
==============================================================================
--- sandbox/committee/LWG/ref_impl/thread (original)
+++ sandbox/committee/LWG/ref_impl/thread 2007-11-28 21:12:54 EST (Wed, 28 Nov 2007)
@@ -185,7 +185,9 @@
 void sleep(const system_time& abs_time);
 template <class Duration>
 inline
-void sleep(const Duration& rel_t) {this_thread::sleep(get_system_time() + rel_t);}
+void sleep(const Duration& rel_t,
+ typename enable_if<__is_duration<Duration>::value>::type* =0)
+ {this_thread::sleep(get_system_time() + rel_t);}
 
 } // this_thread
 


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