Boost logo

Boost-Commit :

From: hinnant_at_[hidden]
Date: 2007-11-12 15:10:52


Author: hinnant
Date: 2007-11-12 15:10:52 EST (Mon, 12 Nov 2007)
New Revision: 41042
URL: http://svn.boost.org/trac/boost/changeset/41042

Log:
Every time related function now had duration and absolute overloads except for cv::timed_waits not taking a predicate
Text files modified:
   sandbox/committee/LWG/ref_impl/condition_variable | 24 ++++++
   sandbox/committee/LWG/ref_impl/mutex | 14 +++
   sandbox/committee/LWG/ref_impl/thread | 5
   sandbox/committee/LWG/ref_impl/thread.cpp | 7 -
   sandbox/committee/LWG/thread_library.html | 151 +++++++++++++++++++++++++++++++++------
   5 files changed, 168 insertions(+), 33 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-12 15:10:52 EST (Mon, 12 Nov 2007)
@@ -29,6 +29,8 @@
         bool timed_wait(unique_lock<mutex>& lock, const system_time& abs_time);
         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);
 
         typedef pthread_cond_t* native_handle_type;
         native_handle_type native_handle();
@@ -54,6 +56,8 @@
             bool timed_wait(Lock& lock, const system_time& abs_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>
+ bool timed_wait(Lock& lock, const Duration& rel_time, Predicate pred);
     };
 
     } // std
@@ -93,6 +97,8 @@
     bool timed_wait(unique_lock<mutex>& lock, const system_time& abs_time);
     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);
 
     typedef pthread_cond_t* native_handle_type;
     native_handle_type native_handle() {return &cv_;}
@@ -134,6 +140,14 @@
     return true;
 }
 
+template <class Duration, class Predicate>
+inline
+bool
+condition_variable::timed_wait(unique_lock<mutex>& lock, const Duration& rel_time, Predicate pred)
+{
+ return timed_wait(lock, get_system_time() + rel_time, std::move(pred));
+}
+
 class condition_variable_any
 {
     condition_variable cv_;
@@ -156,6 +170,8 @@
         bool timed_wait(Lock& lock, const system_time& abs_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>
+ bool timed_wait(Lock& lock, const Duration& rel_time, Predicate pred);
 };
 
 inline
@@ -216,6 +232,14 @@
     return true;
 }
 
+template <class Lock, class Duration, class Predicate>
+inline
+bool
+condition_variable_any::timed_wait(Lock& lock, const Duration& rel_time, Predicate pred)
+{
+ return timed_wait(lock, get_system_time() + rel_time, std::move(pred));
+}
+
 } // std
 
 #endif

Modified: sandbox/committee/LWG/ref_impl/mutex
==============================================================================
--- sandbox/committee/LWG/ref_impl/mutex (original)
+++ sandbox/committee/LWG/ref_impl/mutex 2007-11-12 15:10:52 EST (Mon, 12 Nov 2007)
@@ -237,9 +237,12 @@
 struct once_flag
 {
 private:
- mutex m_;
+ pthread_mutex_t m_;
     bool completed_;
 
+ once_flag(const once_flag&); // = default;
+ once_flag& operator=(const once_flag&); // = default;
+
     template <class F> void run(F f);
 
     template<class Callable, class ...Args>
@@ -249,7 +252,13 @@
 
 public:
     //constexpr
- once_flag() : completed_(false) {}
+ once_flag() : m_(PTHREAD_MUTEX_INITIALIZER), completed_(false) {}
+ ~once_flag() {pthread_mutex_destroy(&m_);}
+};
+
+struct __pthread_mutex_unlocker
+{
+ void operator()(pthread_mutex_t* m) {pthread_mutex_unlock(m);}
 };
 
 template <class F>
@@ -257,6 +266,7 @@
 once_flag::run(F f)
 {
     lock_guard<mutex> _(m_);
+ unique_ptr<pthread_mutex_t, __pthread_mutex_unlocker> _(&m_);
     if (!completed_)
     {
         f();

Modified: sandbox/committee/LWG/ref_impl/thread
==============================================================================
--- sandbox/committee/LWG/ref_impl/thread (original)
+++ sandbox/committee/LWG/ref_impl/thread 2007-11-12 15:10:52 EST (Mon, 12 Nov 2007)
@@ -67,6 +67,7 @@
         thread::id get_id();
         
         void yield();
+ void sleep(const system_time& abs_t);
         template <class Duration>
             void sleep(const Duration& rel_t);
     
@@ -175,10 +176,10 @@
 
 inline __thread_id get_id() {return __thread_id(pthread_self());}
 
-void sleep(const nanoseconds&);
+void sleep(const system_time& abs_time);
 template <class Duration>
 inline
-void sleep(const Duration& rel_t) {this_thread::sleep(__make<nanoseconds>::from(rel_t));}
+void sleep(const Duration& rel_t) {this_thread::sleep(get_system_time() + rel_t);}
 
 } // this_thread
 

Modified: sandbox/committee/LWG/ref_impl/thread.cpp
==============================================================================
--- sandbox/committee/LWG/ref_impl/thread.cpp (original)
+++ sandbox/committee/LWG/ref_impl/thread.cpp 2007-11-12 15:10:52 EST (Mon, 12 Nov 2007)
@@ -64,14 +64,13 @@
 {
 
 void
-sleep(const nanoseconds& rel_time)
+sleep(const system_time& abs_time)
 {
- system_time limit = get_system_time() + rel_time;
     mutex mut;
     unique_lock<mutex> lk(mut);
     condition_variable cv;
- while (get_system_time() < limit)
- cv.timed_wait(lk, limit);
+ while (get_system_time() < abs_time)
+ cv.timed_wait(lk, abs_time);
 }
 
 } // this_thread

Modified: sandbox/committee/LWG/thread_library.html
==============================================================================
--- sandbox/committee/LWG/thread_library.html (original)
+++ sandbox/committee/LWG/thread_library.html 2007-11-12 15:10:52 EST (Mon, 12 Nov 2007)
@@ -29,7 +29,7 @@
 <h1>Multi-threading Library for Standard C++</h1>
 
 <p>
-ISO/IEC JTC1 SC22 WG21 N???? = 07-???? - 2007-11-10
+ISO/IEC JTC1 SC22 WG21 N???? = 07-???? - 2007-11-12
 </p>
 
 <address>
@@ -130,6 +130,7 @@
 
 <p>
 Modify paragraph 1 as follows:
+</p>
 
 <blockquote>
 <p>
@@ -257,6 +258,7 @@
     thread::id get_id();
 
     void yield();
+ void sleep(const system_time&amp; abs_t);
     template &lt;class Duration&gt;
         void sleep(const Duration&amp; rel_t);
 
@@ -819,6 +821,7 @@
 thread::id get_id();
 
 void yield();
+void sleep(const system_time&amp; abs_t);
 template &lt;class Duration&gt;
     void sleep(const Duration&amp; rel_t);
 
@@ -864,6 +867,22 @@
 </dl>
 
 <pre><code>
+void sleep(const system_time&amp; abs_t);
+</code></pre>
+
+<dl>
+<dt>Effects:</dt>
+<dd>
+The current thread blocks at least until the time specified.
+</dd>
+
+<dt>Throws:</dt>
+<dd>
+Nothing.
+</dd>
+</dl>
+
+<pre><code>
 template &lt;class Duration&gt;
     void sleep(const Duration&amp; rel_t);
 </code></pre>
@@ -1460,7 +1479,7 @@
     unique_lock(mutex_type&amp; <var>m</var>, adopt_lock_t);
     unique_lock(mutex_type&amp; <var>m</var>, const system_time&amp; <var>abs_time</var>);
     template &lt;class Duration&gt;
- unique_lock(mutex_type&amp; <var>m</var>, const Duration&amp; <var>rel_time</var>);
+ unique_lock(mutex_type&amp; <var>m</var>, const Duration&amp; <var>rel_time</var>);
     ~unique_lock();
 
     unique_lock(unique_lock const&amp;) = delete;
@@ -1662,11 +1681,13 @@
   unique_lock(mutex_type&amp; <var>m</var>, const Duration&amp; <var>rel_time</var>);
 </code></pre>
 
+<dl>
 <dt>Remarks:</dt>
 <dd>
 The implementation must ensure that only <code>Duration</code> types [<cite>reference to date-time library clause</cite>]
 will bind to this constructor.
 </dd>
+</dl>
 
 <dl>
 <dt>Precondition:</dt>
@@ -2233,7 +2254,8 @@
 <h3><a name="thread.condition">30.3 Condition variables [thread.condition]</a></h3>
 
 <p>
-[<i>Note:</i> For condition variables, time duration overloads are not provided because spurious wakeups
+[<i>Note:</i> For condition variables, time duration overloads are not provided for
+the <code>timed_wait</code> members which do not take a <code>Predicate</code> because spurious wakeups
 would cause endless loops unless extraordinary care were taken. The composability
 of absolute time provides an equivalent, but terminating, idiom:
 </p>
@@ -2302,6 +2324,8 @@
     bool timed_wait(unique_lock&lt;mutex&gt;&amp; lock, const system_time&amp; abs_time);
     template &lt;class Predicate&gt;
         bool timed_wait(unique_lock&lt;mutex&gt;&amp; lock, const system_time&amp; abs_time, Predicate pred);
+ template &lt;class Duration, class Predicate&gt;
+ bool timed_wait(unique_lock&lt;mutex&gt;&amp; lock, const Duration&amp; rel_time, Predicate pred);
 
     typedef <var><strong>implemenation-defined</strong></var> native_handle_type; // <em>See [frontmatter]</em>
     native_handle_type native_handle(); // <em>See [frontmatter]</em>
@@ -2584,6 +2608,44 @@
 </dd>
 </dl>
 
+<pre><code>
+template &lt;class Duration, class Predicate&gt;
+ bool timed_wait(unique_lock&lt;mutex&gt;&amp; lock, const Duration&amp; rel_time, Predicate pred);
+</code></pre>
+
+<dl>
+<dt>Effects:</dt>
+<dd>
+<p>
+As if:
+</p>
+
+<blockquote>
+<pre><code>
+return timed_wait(lock, get_system_time() + rel_time, std::move(pred));
+</code></pre>
+</blockquote>
+</dd>
+
+<dt>Returns:</dt>
+<dd>
+<p>
+<code>pred()</code>.
+</p>
+
+<p>
+[<i>Note:</i>
+There is no blocking if <code>pred()</code> is initially <code>true</code>,
+even
+if the timeout has already expired.
+The return value indicates whether the predicate
+evaluates to <code>true</code>,
+regardless of whether the timeout was triggered.
+&mdash;<i>end note</i>]
+</p>
+</dd>
+</dl>
+
 <p>
 <code>condition_variable</code>
 shall be a standard-layout class (chapter 9 [class]).
@@ -2628,6 +2690,8 @@
         bool timed_wait(Lock&amp; lock, const system_time&amp; abs_time);
     template &lt;class Lock, class Predicate&gt;
         bool timed_wait(Lock&amp; lock, const system_time&amp; abs_time, Predicate pred);
+ template &lt;class Lock, class Duration, class Predicate&gt;
+ bool timed_wait(Lock&amp; lock, const Duration&amp; rel_time, Predicate pred);
 
     typedef <var><strong>implemenation-defined</strong></var> native_handle_type; // <em>See [frontmatter]</em>
     native_handle_type native_handle(); // <em>See [frontmatter]</em>
@@ -2877,6 +2941,43 @@
 <p>
 <code>pred()</code>.
 </p>
+<p>
+[<i>Note:</i>
+There is no blocking if <code>pred()</code> is initially <code>true</code>,
+even
+if the timeout has already expired.
+The return value indicates whether the predicate
+evaluates to <code>true</code>,
+regardless of whether the timeout was triggered.
+&mdash;<i>end note</i>]
+</p>
+</dd>
+</dl>
+
+<pre><code>
+template &lt;class Duration, class _Predicate&gt;
+ bool timed_wait(Lock&amp; lock, const Duration&amp; rel_time, Predicate pred);
+</code></pre>
+
+<dl>
+<dt>Effects:</dt>
+<dd>
+<p>
+As if:
+</p>
+
+<blockquote>
+<pre><code>
+return timed_wait(lock, get_system_time() + rel_time, std::move(pred));
+</code></pre>
+</blockquote>
+</dd>
+
+<dt>Returns:</dt>
+<dd>
+<p>
+<code>pred()</code>.
+</p>
 
 <p>
 [<i>Note:</i>
@@ -2906,6 +3007,7 @@
 have an <dfn>epoch</dfn> or start of a given time scale.
 For time_t the epoch is
 1970-01-01 00:00:00.
+</p>
 
 <p>
 Throughout this clause, the names of template parameters are used to express
@@ -3035,7 +3137,7 @@
 <dl>
 <dt>Effects:</dt>
 <dd>
-Construct<u>s</u> a utc
+Construct<var>s</var> a utc
 time object representing the time point
 that is secs + 1,000,000,000*ns after the epoch.
 </dd>
@@ -3075,7 +3177,7 @@
 <dl>
 <dt>Returns:</dt>
 <dd>
-The count of <u>nano</u>seconds
+The count of nanoseconds
 since 1970-01-01 00:00:00.
 </dd>
 
@@ -3146,8 +3248,8 @@
 <dt>Returns:</dt>
 <dd>
 True if
-the <u>time
-represented by *this is equal to the time represented by rhs</u>.
+the time
+represented by <code>*this</code> is equal to the time represented by <var>rhs</var>.
 </dd>
 
 <dt>Throws:</dt>
@@ -3163,8 +3265,8 @@
 <dl>
 <dt>Returns:</dt>
 <dd>
-True if the <u>time represented by *this is not equal to the time represented
-by rhs</u>
+True if the time represented by <code>*this</code> is not equal to the time represented
+by <var>rhs</var>.
 </dd>
 
 <dt>Throws:</dt>
@@ -3180,8 +3282,8 @@
 <dl>
 <dt>Returns:</dt>
 <dd>
-True if time <u>represented by
-*this is greater than the time represented by rhs</u>.
+True if time represented by
+<code>*this</code> is greater than the time represented by <var>rhs</var>.
 </dd>
 
 <dt>Throws:</dt>
@@ -3197,8 +3299,8 @@
 <dl>
 <dt>Returns:</dt>
 <dd>
-True if time <u>represented
-by *this is greater or equal than the time represented by rhs</u>.
+True if time represented
+by <code>*this</code> is greater or equal than the time represented by <var>rhs</var>.
 </dd>
 
 <dt>Throws:</dt>
@@ -3214,8 +3316,8 @@
 <dl>
 <dt>Returns:</dt>
 <dd>
-True if time <u>represented by *this
-is less than the time represented by rhs</u>.
+True if time represented by <code>*this</code>
+is less than the time represented by <var>rhs</var>.
 </dd>
 
 <dt>Throws:</dt>
@@ -3231,8 +3333,8 @@
 <dl>
 <dt>Returns:</dt>
 <dd>
-True if time <u>represented by *this
-is less or equal than the time represented by rhs</u>.
+True if time represented by <code>*this</code>
+is less or equal than the time represented by <var>rhs</var>.
 </dd>
 
 <dt>Throws:</dt>
@@ -3248,9 +3350,8 @@
 <dl>
 <dt>Returns:</dt>
 <dd>
-<u>
-The difference in nanoseconds between the time represented by *this and the
-time represented by rhs.</u>
+The difference in nanoseconds between the time represented by <code>*this</code> and the
+time represented by <var>rhs</var>.
 </dd>
 
 <dt>Remarks:</dt>
@@ -3274,7 +3375,7 @@
 <dt>Returns:</dt>
 <dd>
 The duration converted to nanosecond resolution
-and added to the time <u>represented by *this</u>.
+and added to the time represented by <code>*this</code>.
 </dd>
 
 <dt>Throws:</dt>
@@ -3315,7 +3416,7 @@
 <dt>Returns:</dt>
 <dd>
 The duration converted to nanosecond resolution
-and subtracted from the time <u>represented by *this</u>.
+and subtracted from the time represented by <code>*this</code>.
 </dd>
 
 <dt>Throws:</dt>
@@ -4250,7 +4351,7 @@
 <dl>
 <dt>Effects:</dt>
 <dd>
-Construct<u>s</u> a<u>n object with a</u> count of seconds - default is
+Construct<var>s</var> an object with a count of seconds - default is
 zero.
 </dd>
 
@@ -4413,7 +4514,7 @@
 <dl>
 <dt>Effects:</dt>
 <dd>
-Construct<u>s</u> a<u>n object with a</u> count of minutes - default is
+Construct<var>s</var> an object with a count of minutes - default is
 zero.
 </dd>
 
@@ -4593,7 +4694,7 @@
 <dl>
 <dt>Effects:</dt>
 <dd>
-Construct<u>s</u> a<u>n object with a</u> count of hours - default is zero.
+Construct<var>s</var> an object with a count of hours - default is zero.
 </dd>
 
 <dt>Throws:</dt>


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