$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r55659 - in sandbox/fmhess/boost/generic_ptr: . detail
From: fmhess_at_[hidden]
Date: 2009-08-18 16:25:27
Author: fmhess
Date: 2009-08-18 16:25:26 EDT (Tue, 18 Aug 2009)
New Revision: 55659
URL: http://svn.boost.org/trac/boost/changeset/55659
Log:
Avoid having to creation of any generic_ptr::shared inside
generic_ptr::monitor::operator->().
Text files modified: 
   sandbox/fmhess/boost/generic_ptr/detail/unique_lock.hpp |    30 +++++++++++++++++++++++++++---          
   sandbox/fmhess/boost/generic_ptr/monitor.hpp            |    32 ++++++++++++++++++++++----------        
   2 files changed, 49 insertions(+), 13 deletions(-)
Modified: sandbox/fmhess/boost/generic_ptr/detail/unique_lock.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/detail/unique_lock.hpp	(original)
+++ sandbox/fmhess/boost/generic_ptr/detail/unique_lock.hpp	2009-08-18 16:25:26 EDT (Tue, 18 Aug 2009)
@@ -24,16 +24,40 @@
       class unique_lock: public noncopyable
       {
       public:
-        unique_lock(Mutex &m): _mutex(m)
+        unique_lock(Mutex &m): _mutex(m), _owns_lock(false)
         {
           _mutex.lock();
+          _owns_lock = true;
         }
-        ~unique_lock()
+ #ifdef BOOST_NO_RVALUE_REFERENCES
+        unique_lock(boost::detail::thread_move_t<unique_lock> other):
+          _mutex(other->_mutex), _owns_lock(true)
         {
-          _mutex.unlock();
+          other->_owns_lock = false;
+        }
+        boost::detail::thread_move_t<unique_lock> move()
+        {
+          return boost::detail::thread_move_t<unique_lock>(*this);
+        }
+#else // BOOST_NO_RVALUE_REFERENCES
+        unique_lock(unique_lock && other):
+          _mutex(other._mutex), _owns_lock(true)
+        {
+          other._owns_lock = false;
+        }
+        unique_lock && move()
+        {
+          return std::move(*this);
+        }
+#endif // BOOST_NO_RVALUE_REFERENCES
+       ~unique_lock()
+        {
+          if(_owns_lock)
+            _mutex.unlock();
         }
       private:
         Mutex &_mutex;
+        bool _owns_lock;
       };
     } // namespace detail
   } // namespace generic_ptr
Modified: sandbox/fmhess/boost/generic_ptr/monitor.hpp
==============================================================================
--- sandbox/fmhess/boost/generic_ptr/monitor.hpp	(original)
+++ sandbox/fmhess/boost/generic_ptr/monitor.hpp	2009-08-18 16:25:26 EDT (Tue, 18 Aug 2009)
@@ -34,25 +34,37 @@
     class monitor
     {
       typedef monitor this_type; // for detail/operator_bool.hpp
-#ifdef BOOST_NO_RVALUE_REFERENCES
-      class moveable_monitor_lock
+
+      // we could use monitor_unique_lock, but this should be slightly faster
+      class moving_monitor_lock
       {
       public:
-        moveable_monitor_lock(const monitor& mon): _object_p(mon.px),
-          _lock(new detail::unique_lock<Mutex>(mon.get_mutex_ref()))
+        moving_monitor_lock(const monitor& mon):
+          _object_p(mon.px),
+          _lock(mon.get_mutex_ref())
+        {}
+#ifdef BOOST_NO_RVALUE_REFERENCES
+        moving_monitor_lock(const moving_monitor_lock & other):
+          _object_p(other._object_p),
+          _lock(const_cast<moving_monitor_lock &>(other)._lock.move())
         {}
+#else // BOOST_NO_RVALUE_REFERENCES
+        moving_monitor_lock(moving_monitor_lock && other):
+          _object_p(std::move(other._object_p)),
+          _lock(std::move(other._lock))
+        {}
+#endif // BOOST_NO_RVALUE_REFERENCES
         T operator->() const
         {
           detail::assert_plain_old_pointer_not_null(_object_p);
           return _object_p;
         }
       private:
+        moving_monitor_lock(moving_monitor_lock & other);
+
         T _object_p;
-        shared<detail::unique_lock<Mutex> *> _lock;
+        detail::unique_lock<Mutex> _lock;
       };
-#else
-      typedef monitor_unique_lock<monitor> moveable_monitor_lock;
-#endif // BOOST_NO_RVALUE_REFERENCES
 
     public:
       typedef typename pointer_traits<T>::value_type value_type;
@@ -141,9 +153,9 @@
 // implicit conversion to "bool"
 #include <boost/generic_ptr/detail/operator_bool.hpp>
 
-      moveable_monitor_lock operator->() const
+      moving_monitor_lock operator->() const
       {
-        return moveable_monitor_lock(*this);
+        return moving_monitor_lock(*this);
       }
 
 // Tasteless as this may seem, making all members public allows member templates