Boost logo

Boost-Commit :

From: anthony_at_[hidden]
Date: 2008-07-03 05:16:50


Author: anthonyw
Date: 2008-07-03 05:16:49 EDT (Thu, 03 Jul 2008)
New Revision: 47033
URL: http://svn.boost.org/trac/boost/changeset/47033

Log:
Use rvalue refs for move semantics of unique_lock where available
Text files modified:
   trunk/boost/thread/locks.hpp | 57 +++++++++++++++++++++++++++++++++++++--
   1 files changed, 54 insertions(+), 3 deletions(-)

Modified: trunk/boost/thread/locks.hpp
==============================================================================
--- trunk/boost/thread/locks.hpp (original)
+++ trunk/boost/thread/locks.hpp 2008-07-03 05:16:49 EDT (Thu, 03 Jul 2008)
@@ -126,8 +126,10 @@
     private:
         Mutex* m;
         bool is_locked;
- explicit unique_lock(unique_lock&);
+ unique_lock(unique_lock&);
+ explicit unique_lock(upgrade_lock<Mutex>&);
         unique_lock& operator=(unique_lock&);
+ unique_lock& operator=(upgrade_lock<Mutex>& other);
     public:
         unique_lock():
             m(0),is_locked(false)
@@ -154,6 +156,35 @@
         {
             timed_lock(target_time);
         }
+#ifdef BOOST_HAS_RVALUE_REFS
+ unique_lock(unique_lock&& other):
+ m(other.m),is_locked(other.is_locked)
+ {
+ other.is_locked=false;
+ other.m=0;
+ }
+ explicit unique_lock(upgrade_lock<Mutex>&& other);
+
+ unique_lock<Mutex>&& move()
+ {
+ return static_cast<unique_lock<Mutex>&&>(*this);
+ }
+
+
+ unique_lock& operator=(unique_lock<Mutex>&& other)
+ {
+ unique_lock temp(other);
+ swap(temp);
+ return *this;
+ }
+
+ unique_lock& operator=(upgrade_lock<Mutex>&& other)
+ {
+ unique_lock temp(other);
+ swap(temp);
+ return *this;
+ }
+#else
         unique_lock(detail::thread_move_t<unique_lock<Mutex> > other):
             m(other->m),is_locked(other->is_locked)
         {
@@ -185,7 +216,7 @@
             swap(temp);
             return *this;
         }
-
+#endif
         void swap(unique_lock& other)
         {
             std::swap(m,other.m);
@@ -281,6 +312,14 @@
         lhs.swap(rhs);
     }
 
+#ifdef BOOST_HAS_RVALUE_REFS
+ template<typename Mutex>
+ inline unique_lock<Mutex>&& move(unique_lock<Mutex>&& ul)
+ {
+ return ul;
+ }
+#endif
+
     template<typename Mutex>
     class shared_lock
     {
@@ -576,6 +615,18 @@
     };
 
 
+#ifdef BOOST_HAS_RVALUE_REFS
+ template<typename Mutex>
+ unique_lock<Mutex>::unique_lock(upgrade_lock<Mutex>&& other):
+ m(other.m),is_locked(other.is_locked)
+ {
+ other.is_locked=false;
+ if(is_locked)
+ {
+ m.unlock_upgrade_and_lock();
+ }
+ }
+#else
     template<typename Mutex>
     unique_lock<Mutex>::unique_lock(detail::thread_move_t<upgrade_lock<Mutex> > other):
         m(other->m),is_locked(other->is_locked)
@@ -586,7 +637,7 @@
             m->unlock_upgrade_and_lock();
         }
     }
-
+#endif
     template <class Mutex>
     class upgrade_to_unique_lock
     {


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