Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83264 - trunk/boost/thread
From: vicente.botet_at_[hidden]
Date: 2013-03-03 05:55:14


Author: viboes
Date: 2013-03-03 05:55:13 EST (Sun, 03 Mar 2013)
New Revision: 83264
URL: http://svn.boost.org/trac/boost/changeset/83264

Log:
Thread: go towards testable_mutex
Text files modified:
   trunk/boost/thread/is_locked_by_this_thread.hpp | 2
   trunk/boost/thread/testable_mutex.hpp | 68 +++++++++++++++++++++------------------
   2 files changed, 38 insertions(+), 32 deletions(-)

Modified: trunk/boost/thread/is_locked_by_this_thread.hpp
==============================================================================
--- trunk/boost/thread/is_locked_by_this_thread.hpp (original)
+++ trunk/boost/thread/is_locked_by_this_thread.hpp 2013-03-03 05:55:13 EST (Sun, 03 Mar 2013)
@@ -25,7 +25,7 @@
   template <typename Lockable>
   bool is_locked_by_this_thread(testable_mutex<Lockable> const& mtx)
   {
- return mtx.is_locked();
+ return mtx.is_locked_by_this_thread();
   }
   template <typename Lockable>
   bool is_locked_by_this_thread(Lockable const&)

Modified: trunk/boost/thread/testable_mutex.hpp
==============================================================================
--- trunk/boost/thread/testable_mutex.hpp (original)
+++ trunk/boost/thread/testable_mutex.hpp 2013-03-03 05:55:13 EST (Sun, 03 Mar 2013)
@@ -9,7 +9,7 @@
 
 #include <boost/thread/detail/config.hpp>
 
-#include <boost/thread/detail/thread.hpp>
+#include <boost/thread/thread_only.hpp>
 
 #include <boost/atomic.hpp>
 #include <boost/assert.hpp>
@@ -26,7 +26,7 @@
    *
    * Many mutex services (including boost::mutex) don't provide a way to ask,
    * "Do I already hold a lock on this mutex?"
- * Sometimes it is needed to know if a method like is_held to be available.
+ * Sometimes it is needed to know if a method like is_locked to be available.
    * This wrapper associates an arbitrary lockable type with a thread id that stores the ID of the thread that
    * currently holds the lockable. The thread id initially holds an invalid value that means no threads own the mutex.
    * When we acquire a lock, we set the thread id; and when we release a lock, we reset it back to its default no id state.
@@ -44,6 +44,8 @@
     /// Non copyable
     BOOST_THREAD_NO_COPYABLE(testable_mutex)
 
+ testable_mutex() {}
+
     void lock()
     {
       mtx_.lock();
@@ -52,7 +54,7 @@
 
     void unlock()
     {
- BOOST_ASSERT(is_locked(mtx_));
+ BOOST_ASSERT(is_locked_by_this_thread());
       id_ = thread::id();
       mtx_.unlock();
     }
@@ -70,40 +72,44 @@
       }
     }
 #ifdef BOOST_THREAD_USES_CHRONO
- template <class Rep, class Period>
- bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
- {
- if (mtx_.try_lock_for(rel_time))
- {
- id_ = this_thread::get_id();
- return true;
- }
- else
- {
- return false;
- }
- }
- template <class Clock, class Duration>
- bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time)
- {
- if (mtx_.try_lock_until(abs_time))
- {
- id_ = this_thread::get_id();
- return true;
- }
- else
- {
- return false;
- }
- }
+ template <class Rep, class Period>
+ bool try_lock_for(const chrono::duration<Rep, Period>& rel_time)
+ {
+ if (mtx_.try_lock_for(rel_time))
+ {
+ id_ = this_thread::get_id();
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ template <class Clock, class Duration>
+ bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time)
+ {
+ if (mtx_.try_lock_until(abs_time))
+ {
+ id_ = this_thread::get_id();
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
 #endif
 
- bool is_locked_by_this_thread()
+ bool is_locked_by_this_thread() const
     {
       return this_thread::get_id() == id_;
     }
+ bool is_locked() const
+ {
+ return ! (thread::id() == id_);
+ }
 
- bool get_id()
+ thread::id get_id() const
     {
       return id_;
     }


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