$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r76995 - trunk/boost/thread
From: vicente.botet_at_[hidden]
Date: 2012-02-12 11:44:44
Author: viboes
Date: 2012-02-12 11:44:43 EST (Sun, 12 Feb 2012)
New Revision: 76995
URL: http://svn.boost.org/trac/boost/changeset/76995
Log:
Thread: Move semantics cleanup
Text files modified: 
   trunk/boost/thread/locks.hpp |   217 ++++++++++++++++++--------------------- 
   1 files changed, 103 insertions(+), 114 deletions(-)
Modified: trunk/boost/thread/locks.hpp
==============================================================================
--- trunk/boost/thread/locks.hpp	(original)
+++ trunk/boost/thread/locks.hpp	2012-02-12 11:44:43 EST (Sun, 12 Feb 2012)
@@ -253,15 +253,16 @@
         Mutex& m;
 
 #ifndef BOOST_NO_DELETED_FUNCTIONS
+    public:
         lock_guard(lock_guard const&) = delete;
         lock_guard& operator=(lock_guard const&) = delete;
 #else // BOOST_NO_DELETED_FUNCTIONS
-  private:
+    private:
         lock_guard(lock_guard const&);
         lock_guard& operator=(lock_guard const&);
-  public:
 #endif // BOOST_NO_DELETED_FUNCTIONS
     public:
+        typedef Mutex mutex_type;
         explicit lock_guard(Mutex& m_):
             m(m_)
         {
@@ -285,27 +286,20 @@
         bool is_locked;
 
 #ifndef BOOST_NO_DELETED_FUNCTIONS
+    public:
         unique_lock(unique_lock const&) = delete;
         unique_lock& operator=(unique_lock const&) = delete;
 #else // BOOST_NO_DELETED_FUNCTIONS
-     private:
-        // Fixme The following doesn't work
-        //test_move_function.cpp:71:12: error: calling a private constructor of class 'boost::unique_lock<boost::mutex>'
-        //    return boost::unique_lock<boost::mutex>(m);
-        //unique_lock(unique_lock const&);
+    private:
         unique_lock(unique_lock&);
-        // Fixme The following doesn't work
-        // ../../../boost/thread/future.hpp:452:33: error: 'operator=' is a private member of 'boost::unique_lock<boost::mutex>'
-        // locks[i]=boost::unique_lock<boost::mutex>(futures[i].future->mutex);
-        //unique_lock& operator=(unique_lock const&);
         unique_lock& operator=(unique_lock &);
-     public:
 #endif // BOOST_NO_DELETED_FUNCTIONS
 
     private:
         explicit unique_lock(upgrade_lock<Mutex>&);
         unique_lock& operator=(upgrade_lock<Mutex>& other);
     public:
+        typedef Mutex mutex_type;
 #if BOOST_WORKAROUND(__SUNPRO_CC, < 0x5100)
         unique_lock(const volatile unique_lock&);
 #endif
@@ -363,29 +357,20 @@
         }
         explicit unique_lock(upgrade_lock<Mutex>&& other);
 
-        unique_lock<Mutex>&& move()
-        {
-            return static_cast<unique_lock<Mutex>&&>(*this);
-        }
 
         unique_lock& operator=(unique_lock&& other)  BOOST_NOEXCEPT
         {
-            unique_lock temp(other.move());
+            unique_lock temp(move(other));
             swap(temp);
             return *this;
         }
 
         unique_lock& operator=(upgrade_lock<Mutex>&& other)  BOOST_NOEXCEPT
         {
-            unique_lock temp(other.move());
+            unique_lock temp(move(other));
             swap(temp);
             return *this;
         }
-        void swap(unique_lock&& other) BOOST_NOEXCEPT
-        {
-            std::swap(m,other.m);
-            std::swap(is_locked,other.is_locked);
-        }
 #else
 #if defined BOOST_THREAD_USES_MOVE
         unique_lock(boost::rv<unique_lock<Mutex> >& other)  BOOST_NOEXCEPT:
@@ -638,46 +623,13 @@
         friend class upgrade_lock<Mutex>;
     };
 
-#ifndef BOOST_NO_RVALUE_REFERENCES
-//    template<typename Mutex>
-//    void swap(unique_lock<Mutex>&& lhs,unique_lock<Mutex>&& rhs)
-//    {
-//        lhs.swap(rhs);
-//    }
-
-    template<typename Mutex>
-    inline upgrade_lock<Mutex>&& move(upgrade_lock<Mutex>&& ul)
-    {
-        return static_cast<upgrade_lock<Mutex>&&>(ul);
-    }
-
-    template<typename Mutex>
-    inline upgrade_lock<Mutex>&& move(upgrade_lock<Mutex>& ul)
-    {
-        return static_cast<upgrade_lock<Mutex>&&>(ul);
-    }
-#endif
     template<typename Mutex>
     void swap(unique_lock<Mutex>& lhs,unique_lock<Mutex>& rhs) BOOST_NOEXCEPT
     {
         lhs.swap(rhs);
     }
 
-#ifndef BOOST_NO_RVALUE_REFERENCES
-    template<typename Mutex>
-    inline unique_lock<Mutex>&& move(unique_lock<Mutex>&& ul)
-    {
-        return static_cast<unique_lock<Mutex>&&>(ul);
-    }
-
-    template<typename Mutex>
-    inline unique_lock<Mutex>&& move(unique_lock<Mutex>& ul)
-    {
-        return static_cast<unique_lock<Mutex>&&>(ul);
-    }
-#endif
-
-#ifdef BOOST_NO_RVALUE_REFERENCES
+#if defined BOOST_NO_RVALUE_REFERENCES && ! defined BOOST_THREAD_USES_MOVE
     template <typename Mutex>
     struct has_move_emulation_enabled_aux<unique_lock<Mutex> >
       : BOOST_MOVE_BOOST_NS::integral_constant<bool, true>
@@ -691,15 +643,17 @@
         Mutex* m;
         bool is_locked;
 #ifndef BOOST_NO_DELETED_FUNCTIONS
-        shared_lock(shared_lock const&);
-        shared_lock& operator=(shared_lock const&);
+    public:
+        shared_lock(shared_lock const&) = delete;
+        shared_lock& operator=(shared_lock const&) = delete;
 #else // BOOST_NO_DELETED_FUNCTIONS
-     private:
+    private:
         shared_lock(shared_lock const&);
         shared_lock& operator=(shared_lock const&);
-     public:
 #endif // BOOST_NO_DELETED_FUNCTIONS
     public:
+        typedef Mutex mutex_type;
+
         shared_lock():
             m(0),is_locked(false)
         {}
@@ -726,6 +680,56 @@
             timed_lock(target_time);
         }
 #ifndef BOOST_NO_RVALUE_REFERENCES
+        shared_lock(shared_lock<Mutex> && other):
+            m(other.m),is_locked(other.is_locked)
+        {
+            other.is_locked=false;
+            other.m=0;
+        }
+
+        shared_lock(unique_lock<Mutex> && other):
+            m(other.m),is_locked(other.is_locked)
+        {
+            if(is_locked)
+            {
+                m->unlock_and_lock_shared();
+            }
+            other.is_locked=false;
+            other.m=0;
+        }
+
+        shared_lock(upgrade_lock<Mutex> && other):
+            m(other.m),is_locked(other.is_locked)
+        {
+            if(is_locked)
+            {
+                m->unlock_upgrade_and_lock_shared();
+            }
+            other.is_locked=false;
+            other.m=0;
+        }
+
+
+        shared_lock& operator=(shared_lock<Mutex> && other)
+        {
+            shared_lock temp(other);
+            swap(temp);
+            return *this;
+        }
+
+        shared_lock& operator=(unique_lock<Mutex> && other)
+        {
+            shared_lock temp(other);
+            swap(temp);
+            return *this;
+        }
+
+        shared_lock& operator=(upgrade_lock<Mutex> && other)
+        {
+            shared_lock temp(other);
+            swap(temp);
+            return *this;
+        }
 
 #else
 #if defined BOOST_THREAD_USES_MOVE
@@ -853,19 +857,6 @@
 #endif
 #endif
 
-#ifndef BOOST_NO_RVALUE_REFERENCES
-        void swap(shared_lock&& other)
-        {
-            std::swap(m,other.m);
-            std::swap(is_locked,other.is_locked);
-        }
-#else
-        void swap(boost::detail::thread_move_t<shared_lock<Mutex> > other)
-        {
-            std::swap(m,other->m);
-            std::swap(is_locked,other->is_locked);
-        }
-#endif
         void swap(shared_lock& other)
         {
             std::swap(m,other.m);
@@ -954,7 +945,7 @@
 
     };
 
-#ifdef BOOST_NO_RVALUE_REFERENCES
+#if defined BOOST_NO_RVALUE_REFERENCES && ! defined BOOST_THREAD_USES_MOVE
   template <typename Mutex>
   struct has_move_emulation_enabled_aux<shared_lock<Mutex> >
   : BOOST_MOVE_BOOST_NS::integral_constant<bool, true>
@@ -962,24 +953,11 @@
 #endif
 
 
-#ifndef BOOST_NO_RVALUE_REFERENCES
-    template<typename Mutex>
-    void swap(shared_lock<Mutex>&& lhs,shared_lock<Mutex>&& rhs)
-    {
-        lhs.swap(rhs);
-    }
     template<typename Mutex>
     void swap(shared_lock<Mutex>& lhs,shared_lock<Mutex>& rhs)
     {
         lhs.swap(rhs);
     }
-#else
-    template<typename Mutex>
-    void swap(shared_lock<Mutex>& lhs,shared_lock<Mutex>& rhs)
-    {
-        lhs.swap(rhs);
-    }
-#endif
 
     template<typename Mutex>
     class upgrade_lock
@@ -987,10 +965,17 @@
     protected:
         Mutex* m;
         bool is_locked;
+#ifndef BOOST_NO_DELETED_FUNCTIONS
+    public:
+        upgrade_lock(upgrade_lock&) = delete;
+        upgrade_lock& operator=(upgrade_lock&) = delete;
+#else
     private:
         explicit upgrade_lock(upgrade_lock&);
         upgrade_lock& operator=(upgrade_lock&);
+#endif
     public:
+        typedef Mutex mutex_type;
         upgrade_lock():
             m(0),is_locked(false)
         {}
@@ -1043,6 +1028,7 @@
             swap(temp);
             return *this;
         }
+
 #else
 #if defined BOOST_THREAD_USES_MOVE
         upgrade_lock(boost::rv<upgrade_lock<Mutex> >& other):
@@ -1196,7 +1182,7 @@
         friend class unique_lock<Mutex>;
     };
 
-#ifdef BOOST_NO_RVALUE_REFERENCES
+#if defined BOOST_NO_RVALUE_REFERENCES && ! defined BOOST_THREAD_USES_MOVE
     template <typename Mutex>
     struct has_move_emulation_enabled_aux<upgrade_lock<Mutex> >
       : BOOST_MOVE_BOOST_NS::integral_constant<bool, true>
@@ -1247,9 +1233,17 @@
         upgrade_lock<Mutex>* source;
         unique_lock<Mutex> exclusive;
 
+#ifndef BOOST_NO_DELETED_FUNCTIONS
+    public:
+        upgrade_to_unique_lock(upgrade_to_unique_lock&) = delete;
+        upgrade_to_unique_lock& operator=(upgrade_to_unique_lock&) = delete;
+#else
+    private:
         explicit upgrade_to_unique_lock(upgrade_to_unique_lock&);
         upgrade_to_unique_lock& operator=(upgrade_to_unique_lock&);
+#endif
     public:
+        typedef Mutex mutex_type;
         explicit upgrade_to_unique_lock(upgrade_lock<Mutex>& m_):
             source(&m_),exclusive(move(*source))
         {}
@@ -1288,6 +1282,14 @@
             swap(temp);
             return *this;
         }
+        operator ::boost::rv<upgrade_to_unique_lock>&()
+        {
+          return *static_cast< ::boost::rv<upgrade_to_unique_lock>* >(this);
+        }
+        operator const ::boost::rv<upgrade_to_unique_lock>&() const
+        {
+          return *static_cast<const ::boost::rv<upgrade_to_unique_lock>* >(this);
+        }
 #else
         upgrade_to_unique_lock(detail::thread_move_t<upgrade_to_unique_lock<Mutex> > other):
             source(other->source),exclusive(move(other->exclusive))
@@ -1301,6 +1303,15 @@
             swap(temp);
             return *this;
         }
+        operator detail::thread_move_t<upgrade_to_unique_lock<Mutex> >()
+        {
+            return move();
+        }
+
+        detail::thread_move_t<upgrade_to_unique_lock<Mutex> > move()
+        {
+            return detail::thread_move_t<upgrade_to_unique_lock<Mutex> >(*this);
+        }
 #endif
 #endif
         void swap(upgrade_to_unique_lock& other)
@@ -1332,7 +1343,7 @@
         }
     };
 
-#ifdef BOOST_NO_RVALUE_REFERENCES
+#if defined BOOST_NO_RVALUE_REFERENCES && ! defined BOOST_THREAD_USES_MOVE
     template <typename Mutex>
     struct has_move_emulation_enabled_aux<upgrade_to_unique_lock<Mutex> >
       : BOOST_MOVE_BOOST_NS::integral_constant<bool, true>
@@ -1365,25 +1376,16 @@
             {}
 #ifndef BOOST_NO_RVALUE_REFERENCES
             try_lock_wrapper(try_lock_wrapper&& other):
-                base(other.move())
+                base(move(other))
             {}
 
-            try_lock_wrapper&& move()
-            {
-                return static_cast<try_lock_wrapper&&>(*this);
-            }
-
             try_lock_wrapper& operator=(try_lock_wrapper<Mutex>&& other)
             {
-                try_lock_wrapper temp(other.move());
+                try_lock_wrapper temp(move(other));
                 swap(temp);
                 return *this;
             }
 
-            void swap(try_lock_wrapper&& other)
-            {
-                base::swap(other);
-            }
 #else
 #if defined BOOST_THREAD_USES_MOVE
             try_lock_wrapper(boost::rv<try_lock_wrapper<Mutex> >& other):
@@ -1481,24 +1483,11 @@
 #endif
         };
 
-#ifndef BOOST_NO_RVALUE_REFERENCES
-        template<typename Mutex>
-        void swap(try_lock_wrapper<Mutex>&& lhs,try_lock_wrapper<Mutex>&& rhs)
-        {
-            lhs.swap(rhs);
-        }
-        template<typename Mutex>
-        void swap(try_lock_wrapper<Mutex>& lhs,try_lock_wrapper<Mutex>& rhs)
-        {
-            lhs.swap(rhs);
-        }
-#else
         template<typename Mutex>
         void swap(try_lock_wrapper<Mutex>& lhs,try_lock_wrapper<Mutex>& rhs)
         {
             lhs.swap(rhs);
         }
-#endif
 
         template<typename MutexType1,typename MutexType2>
         unsigned try_lock_internal(MutexType1& m1,MutexType2& m2)