Boost logo

Boost-Commit :

From: anthony_at_[hidden]
Date: 2008-06-05 06:39:08


Author: anthonyw
Date: 2008-06-05 06:39:08 EDT (Thu, 05 Jun 2008)
New Revision: 46160
URL: http://svn.boost.org/trac/boost/changeset/46160

Log:
Added swap for unique_lock
Text files modified:
   trunk/boost/thread/locks.hpp | 6 ++++++
   trunk/libs/thread/test/test_lock_concept.cpp | 30 ++++++++++++++++++++++++++++++
   2 files changed, 36 insertions(+), 0 deletions(-)

Modified: trunk/boost/thread/locks.hpp
==============================================================================
--- trunk/boost/thread/locks.hpp (original)
+++ trunk/boost/thread/locks.hpp 2008-06-05 06:39:08 EDT (Thu, 05 Jun 2008)
@@ -276,6 +276,12 @@
     };
 
     template<typename Mutex>
+ void swap(unique_lock<Mutex>& lhs,unique_lock<Mutex>& rhs)
+ {
+ lhs.swap(rhs);
+ }
+
+ template<typename Mutex>
     class shared_lock
     {
     protected:

Modified: trunk/libs/thread/test/test_lock_concept.cpp
==============================================================================
--- trunk/libs/thread/test/test_lock_concept.cpp (original)
+++ trunk/libs/thread/test/test_lock_concept.cpp 2008-06-05 06:39:08 EDT (Thu, 05 Jun 2008)
@@ -196,6 +196,35 @@
     };
 };
 
+
+template<typename Mutex,typename Lock>
+struct test_locks_can_be_swapped
+{
+ void operator()() const
+ {
+ Mutex m1;
+ Mutex m2;
+ Lock l1(m1);
+ Lock l2(m2);
+
+ BOOST_CHECK_EQUAL(l1.mutex(),&m1);
+ BOOST_CHECK_EQUAL(l2.mutex(),&m2);
+
+ l1.swap(l2);
+
+ BOOST_CHECK_EQUAL(l1.mutex(),&m2);
+ BOOST_CHECK_EQUAL(l2.mutex(),&m1);
+
+ swap(l1,l2);
+
+ BOOST_CHECK_EQUAL(l1.mutex(),&m1);
+ BOOST_CHECK_EQUAL(l2.mutex(),&m2);
+
+ }
+};
+
+
+
 BOOST_TEST_CASE_TEMPLATE_FUNCTION(test_scoped_lock_concept,Mutex)
 {
     typedef typename Mutex::scoped_lock Lock;
@@ -208,6 +237,7 @@
     test_locked_after_lock_called<Mutex,Lock>()();
     test_throws_if_lock_called_when_already_locked<Mutex,Lock>()();
     test_throws_if_unlock_called_when_already_unlocked<Mutex,Lock>()();
+ test_locks_can_be_swapped<Mutex,Lock>()();
 }
 
 BOOST_TEST_CASE_TEMPLATE_FUNCTION(test_scoped_try_lock_concept,Mutex)


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