Boost logo

Boost-Commit :

From: hinnant_at_[hidden]
Date: 2007-11-28 15:37:20


Author: hinnant
Date: 2007-11-28 15:37:20 EST (Wed, 28 Nov 2007)
New Revision: 41442
URL: http://svn.boost.org/trac/boost/changeset/41442

Log:
minor tweaks on call_once, corrected some timed_wait errors
Text files modified:
   sandbox/committee/LWG/ref_impl/mutex | 13 +++++++------
   sandbox/committee/LWG/ref_impl/mutex.cpp | 14 +++++++-------
   2 files changed, 14 insertions(+), 13 deletions(-)

Modified: sandbox/committee/LWG/ref_impl/mutex
==============================================================================
--- sandbox/committee/LWG/ref_impl/mutex (original)
+++ sandbox/committee/LWG/ref_impl/mutex 2007-11-28 15:37:20 EST (Wed, 28 Nov 2007)
@@ -295,7 +295,7 @@
                 flag = once_flag(0);
                 pthread_mutex_unlock(&__call_once_mut);
                 pthread_cond_broadcast(&__call_once_cv);
- throw;
+ throw;
             }
             pthread_mutex_lock(&__call_once_mut);
             flag = global_epoch;
@@ -310,18 +310,19 @@
 template <class F>
 inline
 void
-call_once(once_flag& flag, F f)
+call_once(once_flag& flag, F&& func)
 {
     if (flag < __get_once_per_thread_epoch())
- __call_once(flag, std::move(f));
+ __call_once(flag, std::forward<F>(func));
 }
 
-template<class F, class ...Args>
+template<class F, class Arg0, class ...Args>
 inline
 void
-call_once(once_flag& flag, F&& func, Args&&... args)
+call_once(once_flag& flag, F&& func, Arg0&& arg0, Args&&... args)
 {
- std::call_once(flag, bind(std::forward<F>(func), std::forward<Args>(args)...));
+ if (flag < __get_once_per_thread_epoch())
+ __call_once(flag, bind(std::forward<F>(func), std::forward<Arg0>(arg0), std::forward<Args>(args)...));
 }
 
 } // std

Modified: sandbox/committee/LWG/ref_impl/mutex.cpp
==============================================================================
--- sandbox/committee/LWG/ref_impl/mutex.cpp (original)
+++ sandbox/committee/LWG/ref_impl/mutex.cpp 2007-11-28 15:37:20 EST (Wed, 28 Nov 2007)
@@ -149,9 +149,9 @@
 timed_mutex::timed_lock(const system_time& abs_time)
 {
     unique_lock<mutex> lk(mut_);
- bool timed_out = get_system_time() > abs_time;
- while (!timed_out && locked_)
- timed_out = gate1_.timed_wait(lk, abs_time);
+ bool within_time = get_system_time() < abs_time;
+ while (within_time && locked_)
+ within_time = gate1_.timed_wait(lk, abs_time);
     if (!locked_)
     {
         locked_ = true;
@@ -226,9 +226,9 @@
         ++state_;
         return true;
     }
- bool timed_out = get_system_time() > abs_time;
- while (!timed_out && state_ != 0)
- timed_out = gate1_.timed_wait(lk, abs_time);
+ bool within_time = get_system_time() < abs_time;
+ while (within_time && state_ != 0)
+ within_time = gate1_.timed_wait(lk, abs_time);
     if (state_ == 0)
     {
         state_ = 1;
@@ -299,10 +299,10 @@
 
 pthread_mutex_t __call_once_mut = PTHREAD_MUTEX_INITIALIZER;
 pthread_cond_t __call_once_cv = PTHREAD_COND_INITIALIZER;
-static once_flag global_epoch(SIG_ATOMIC_MAX);
 
 once_flag& __get_call_once_global_epoch()
 {
+ static once_flag global_epoch(SIG_ATOMIC_MAX);
     return global_epoch;
 }
 


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