Boost logo

Boost-Commit :

From: anthony_at_[hidden]
Date: 2008-05-08 10:34:41


Author: anthonyw
Date: 2008-05-08 10:34:40 EDT (Thu, 08 May 2008)
New Revision: 45212
URL: http://svn.boost.org/trac/boost/changeset/45212

Log:
Added default constructor to lock types
Text files modified:
   trunk/boost/thread/locks.hpp | 26 +++++++++++++++++++++++---
   trunk/libs/thread/doc/mutex_concepts.qbk | 30 ++++++++++++++++++++++++++++++
   trunk/libs/thread/test/test_lock_concept.cpp | 12 ++++++++++++
   3 files changed, 65 insertions(+), 3 deletions(-)

Modified: trunk/boost/thread/locks.hpp
==============================================================================
--- trunk/boost/thread/locks.hpp (original)
+++ trunk/boost/thread/locks.hpp 2008-05-08 10:34:40 EDT (Thu, 08 May 2008)
@@ -62,6 +62,10 @@
         explicit unique_lock(unique_lock&);
         unique_lock& operator=(unique_lock&);
     public:
+ unique_lock():
+ m(0),is_locked(false)
+ {}
+
         explicit unique_lock(Mutex& m_):
             m(&m_),is_locked(false)
         {
@@ -214,6 +218,10 @@
         explicit shared_lock(shared_lock&);
         shared_lock& operator=(shared_lock&);
     public:
+ shared_lock():
+ m(0),is_locked(false)
+ {}
+
         explicit shared_lock(Mutex& m_):
             m(&m_),is_locked(false)
         {
@@ -240,26 +248,29 @@
             m(other->m),is_locked(other->is_locked)
         {
             other->is_locked=false;
+ other->m=0;
         }
 
         shared_lock(detail::thread_move_t<unique_lock<Mutex> > other):
             m(other->m),is_locked(other->is_locked)
         {
- other->is_locked=false;
             if(is_locked)
             {
                 m->unlock_and_lock_shared();
             }
+ other->is_locked=false;
+ other->m=0;
         }
 
         shared_lock(detail::thread_move_t<upgrade_lock<Mutex> > other):
             m(other->m),is_locked(other->is_locked)
         {
- other->is_locked=false;
             if(is_locked)
             {
                 m->unlock_upgrade_and_lock_shared();
             }
+ other->is_locked=false;
+ other->m=0;
         }
 
         operator detail::thread_move_t<shared_lock<Mutex> >()
@@ -370,6 +381,10 @@
         explicit upgrade_lock(upgrade_lock&);
         upgrade_lock& operator=(upgrade_lock&);
     public:
+ upgrade_lock():
+ m(0),is_locked(false)
+ {}
+
         explicit upgrade_lock(Mutex& m_):
             m(&m_),is_locked(false)
         {
@@ -390,16 +405,18 @@
             m(other->m),is_locked(other->is_locked)
         {
             other->is_locked=false;
+ other->m=0;
         }
 
         upgrade_lock(detail::thread_move_t<unique_lock<Mutex> > other):
             m(other->m),is_locked(other->is_locked)
         {
- other->is_locked=false;
             if(is_locked)
             {
                 m->unlock_and_lock_upgrade();
             }
+ other->is_locked=false;
+ other->m=0;
         }
 
         operator detail::thread_move_t<upgrade_lock<Mutex> >()
@@ -558,6 +575,9 @@
         {
             typedef unique_lock<Mutex> base;
         public:
+ try_lock_wrapper()
+ {}
+
             explicit try_lock_wrapper(Mutex& m):
                 base(m,try_to_lock)
             {}

Modified: trunk/libs/thread/doc/mutex_concepts.qbk
==============================================================================
--- trunk/libs/thread/doc/mutex_concepts.qbk (original)
+++ trunk/libs/thread/doc/mutex_concepts.qbk 2008-05-08 10:34:40 EDT (Thu, 08 May 2008)
@@ -373,6 +373,7 @@
     class unique_lock
     {
     public:
+ unique_lock();
         explicit unique_lock(Lockable& m_);
         unique_lock(Lockable& m_,adopt_lock_t);
         unique_lock(Lockable& m_,defer_lock_t);
@@ -426,6 +427,20 @@
 __lockable_concept_type__ object by a particular thread, and the member functions that release ownership of the lock state
 (including the destructor) must be called by the same thread that acquired ownership of the lock state.
 
+[section:defaultconstructor `unique_lock()`]
+
+[variablelist
+
+[[Effects:] [Creates a lock object with no associated mutex.]]
+
+[[Postcondition:] [__owns_lock_ref__ returns `false`. __mutex_func_ref__ returns `NULL`.]]
+
+[[Throws:] [Nothing.]]
+
+]
+
+[endsect]
+
 [section:constructor `unique_lock(Lockable & m)`]
 
 [variablelist
@@ -599,6 +614,7 @@
     class shared_lock
     {
     public:
+ shared_lock();
         explicit shared_lock(Lockable& m_);
         shared_lock(Lockable& m_,adopt_lock_t);
         shared_lock(Lockable& m_,defer_lock_t);
@@ -644,6 +660,20 @@
 ownership of a __lockable_concept_type__ object by a particular thread, and the member functions that release ownership of the lock
 state (including the destructor) must be called by the same thread that acquired ownership of the lock state.
 
+[section:defaultconstructor `shared_lock()`]
+
+[variablelist
+
+[[Effects:] [Creates a lock object with no associated mutex.]]
+
+[[Postcondition:] [__owns_lock_ref__ returns `false`. __mutex_func_ref__ returns `NULL`.]]
+
+[[Throws:] [Nothing.]]
+
+]
+
+[endsect]
+
 [section:constructor `shared_lock(Lockable & m)`]
 
 [variablelist

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-05-08 10:34:40 EDT (Thu, 08 May 2008)
@@ -185,11 +185,22 @@
         BOOST_CHECK_THROW( lock.unlock(), boost::lock_error );
     }
 };
+template<typename Lock>
+struct test_default_constructed_has_no_mutex_and_unlocked
+{
+ void operator()() const
+ {
+ Lock l;
+ BOOST_CHECK(!l.mutex());
+ BOOST_CHECK(!l.owns_lock());
+ };
+};
 
 BOOST_TEST_CASE_TEMPLATE_FUNCTION(test_scoped_lock_concept,Mutex)
 {
     typedef typename Mutex::scoped_lock Lock;
     
+ test_default_constructed_has_no_mutex_and_unlocked<Lock>()();
     test_initially_locked<Mutex,Lock>()();
     test_initially_unlocked_with_defer_lock_parameter<Mutex,Lock>()();
     test_initially_locked_with_adopt_lock_parameter<Mutex,Lock>()();
@@ -203,6 +214,7 @@
 {
     typedef typename Mutex::scoped_try_lock Lock;
     
+ test_default_constructed_has_no_mutex_and_unlocked<Lock>()();
     test_initially_locked<Mutex,Lock>()();
     test_initially_unlocked_if_other_thread_has_lock<Mutex,Lock>()();
     test_initially_unlocked_with_defer_lock_parameter<Mutex,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