Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84076 - in trunk: boost/thread libs/thread/doc
From: vicente.botet_at_[hidden]
Date: 2013-04-28 16:12:29


Author: viboes
Date: 2013-04-28 16:12:28 EDT (Sun, 28 Apr 2013)
New Revision: 84076
URL: http://svn.boost.org/trac/boost/changeset/84076

Log:
Thread: update externally_locked with assignment.
Text files modified:
   trunk/boost/thread/externally_locked.hpp | 84 +++++++++++--
   trunk/libs/thread/doc/mutex_concepts.qbk | 229 +++++++++++++++++++++++++++++++++++++++
   trunk/libs/thread/doc/thread.qbk | 3
   3 files changed, 294 insertions(+), 22 deletions(-)

Modified: trunk/boost/thread/externally_locked.hpp
==============================================================================
--- trunk/boost/thread/externally_locked.hpp (original)
+++ trunk/boost/thread/externally_locked.hpp 2013-04-28 16:12:28 EDT (Sun, 28 Apr 2013)
@@ -33,6 +33,8 @@
 
   //[externally_locked
   template <typename T, typename MutexType = boost::mutex>
+ class externally_locked;
+ template <typename T, typename MutexType>
   class externally_locked
   {
     //BOOST_CONCEPT_ASSERT(( CopyConstructible<T> ));
@@ -46,7 +48,7 @@
      * Requires: T is a model of CopyConstructible.
      * Effects: Constructs an externally locked object copying the cloaked type.
      */
- BOOST_CONSTEXPR externally_locked(mutex_type& mtx, const T& obj) :
+ externally_locked(mutex_type& mtx, const T& obj) :
       obj_(obj), mtx_(&mtx)
     {
     }
@@ -55,7 +57,7 @@
      * Requires: T is a model of Movable.
      * Effects: Constructs an externally locked object by moving the cloaked type.
      */
- BOOST_CONSTEXPR externally_locked(mutex_type& mtx, BOOST_THREAD_RV_REF(T) obj) :
+ externally_locked(mutex_type& mtx, BOOST_THREAD_RV_REF(T) obj) :
       obj_(move(obj)), mtx_(&mtx)
     {
     }
@@ -64,18 +66,46 @@
      * Requires: T is a model of DefaultConstructible.
      * Effects: Constructs an externally locked object initializing the cloaked type with the default constructor.
      */
- externally_locked(mutex_type& mtx) :
- obj_(), mtx_(&mtx)
+ externally_locked(mutex_type& mtx) // BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(T()))
+ : obj_(), mtx_(&mtx)
     {
     }
 
     /**
+ * Copy constructor
+ */
+ externally_locked(externally_locked const& rhs) //BOOST_NOEXCEPT
+ : obj_(rhs.obj_), mtx_(rhs.mtx_)
+ {
+ }
+ /**
      * Move constructor
      */
- externally_locked(BOOST_THREAD_RV_REF(externally_locked) rhs) :
- obj_(move(rhs.obj_)), mtx_(rhs.mtx_)
+ externally_locked(BOOST_THREAD_RV_REF(externally_locked) rhs) //BOOST_NOEXCEPT
+ : obj_(move(rhs.obj_)), mtx_(rhs.mtx_)
+ {
+ }
+
+ /// assignment
+ externally_locked& operator=(externally_locked const& rhs) //BOOST_NOEXCEPT
+ {
+ obj_=rhs.obj_;
+ mtx_=rhs.mtx_;
+ return *this;
+ }
+
+ /// move assignment
+ externally_locked& operator=(BOOST_THREAD_RV_REF(externally_locked) rhs) // BOOST_NOEXCEPT
+ {
+ obj_=move(rhs.obj_);
+ mtx_=rhs.mtx_;
+ return *this;
+ }
+
+ void swap(externally_locked& rhs) //BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR)
     {
- rhs.mtx_=0;
+ swap(obj_, rhs.obj_);
+ swap(mtx_, rhs.mtx_);
     }
 
     /**
@@ -126,13 +156,13 @@
       BOOST_STATIC_ASSERT( (is_strict_lock<Lock>::value)); /*< lk is a strict lock "sur parolle" >*/
       BOOST_STATIC_ASSERT( (is_same<mutex_type, typename Lock::mutex_type>::value)); /*< that locks the same type >*/
 
- BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(), lock_error() ); /*< run time check throw if no locked >*/
+ //BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(), lock_error() ); /*< run time check throw if no locked >*/
       BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/
 
       return obj_;
     }
 
- mutex_type* mutex()
+ mutex_type* mutex() const BOOST_NOEXCEPT
     {
       return mtx_;
     }
@@ -175,25 +205,45 @@
   public:
     typedef MutexType mutex_type;
 
- BOOST_THREAD_MOVABLE_ONLY( externally_locked )
+ BOOST_THREAD_COPYABLE_AND_MOVABLE( externally_locked )
 
     /**
      * Effects: Constructs an externally locked object storing the cloaked reference object.
      */
- externally_locked(T& obj, mutex_type& mtx) :
+ externally_locked(T& obj, mutex_type& mtx) BOOST_NOEXCEPT :
       obj_(&obj), mtx_(&mtx)
     {
     }
 
+ /// copy constructor
+ externally_locked(externally_locked const& rhs) BOOST_NOEXCEPT :
+ obj_(rhs.obj_), mtx_(rhs.mtx_)
+ {
+ }
+
     /// move constructor
- externally_locked(BOOST_THREAD_RV_REF(externally_locked) rhs) :
+ externally_locked(BOOST_THREAD_RV_REF(externally_locked) rhs) BOOST_NOEXCEPT :
     obj_(rhs.obj_), mtx_(rhs.mtx_)
     {
- rhs.obj_=0;
- rhs.mtx_=0;
     }
 
- void swap(externally_locked& rhs)
+ /// assignment
+ externally_locked& operator=(externally_locked const& rhs) BOOST_NOEXCEPT
+ {
+ obj_=rhs.obj_;
+ mtx_=rhs.mtx_;
+ return *this;
+ }
+
+ /// move assignment
+ externally_locked& operator=(BOOST_THREAD_RV_REF(externally_locked) rhs) BOOST_NOEXCEPT
+ {
+ obj_=rhs.obj_;
+ mtx_=rhs.mtx_;
+ return *this;
+ }
+
+ void swap(externally_locked& rhs) BOOST_NOEXCEPT
     {
       swap(obj_, rhs.obj_);
       swap(mtx_, rhs.mtx_);
@@ -266,7 +316,7 @@
       BOOST_THREAD_ASSERT_PRECONDITION( lk.owns_lock(mtx_), lock_error() ); /*< run time check throw if not locks the same >*/
       return *obj_;
     }
- mutex_type* mutex()
+ mutex_type* mutex() const BOOST_NOEXCEPT
     {
       return mtx_;
     }
@@ -292,7 +342,7 @@
   //]
 
   template <typename T, typename MutexType>
- void swap(externally_locked<T, MutexType> & lhs, externally_locked<T, MutexType> & rhs)
+ void swap(externally_locked<T, MutexType> & lhs, externally_locked<T, MutexType> & rhs) // BOOST_NOEXCEPT
   {
     lhs.swap(rhs);
   }

Modified: trunk/libs/thread/doc/mutex_concepts.qbk
==============================================================================
--- trunk/libs/thread/doc/mutex_concepts.qbk (original)
+++ trunk/libs/thread/doc/mutex_concepts.qbk 2013-04-28 16:12:28 EDT (Sun, 28 Apr 2013)
@@ -2441,10 +2441,13 @@
   // #include <boost/thread/externally_locked.hpp>
   template <class T, typename MutexType = boost::mutex>
   class externally_locked;
+ template <class T, typename MutexType>
+ class externally_locked<T&, MutexType>;
+
   template <typename T, typename MutexType>
   void swap(externally_locked<T, MutexType> & lhs, externally_locked<T, MutexType> & rhs);
 
-[section Template Class `externally_locked`]
+[section:externally_locked Template Class `externally_locked`]
 
   // #include <boost/thread/externally_locked.hpp>
 
@@ -2460,8 +2463,11 @@
     externally_locked(mutex_type& mtx, const T& obj);
     externally_locked(mutex_type& mtx,T&& obj);
     explicit externally_locked(mutex_type& mtx);
+ externally_locked(externally_locked const& rhs);
     externally_locked(externally_locked&& rhs);
-
+ externally_locked& operator=(externally_locked const& rhs);
+ externally_locked& operator=(externally_locked&& rhs);
+
     // observers
     T& get(strict_lock<mutex_type>& lk);
     const T& get(strict_lock<mutex_type>& lk) const;
@@ -2476,7 +2482,7 @@
     template <class Lock>
     T const& get(Lock& lk) const;
 
- mutex_type* mutex();
+ mutex_type* mutex() const noexcept;
 
     // modifiers
     void lock();
@@ -2540,7 +2546,7 @@
 
 [endsect]
 [///////////////////////////////]
-[section:constructor4 `externally_locked(externally_locked&)`]
+[section:constructor4 `externally_locked(externally_locked&&)`]
 
     externally_locked(externally_locked&& rhs);
 
@@ -2548,7 +2554,7 @@
 
 [[Requires:] [T is a model of Movable.]]
 
-[[Effects:] [Moves an externally locked object by moving the the cloaked type and copying the mutex reference ]]
+[[Effects:] [Move constructs an externally locked object by moving the cloaked type and copying the mutex reference ]]
 
 [[Throws:] [Any exception thrown by the call to `T(T&&)`.]]
 
@@ -2556,6 +2562,55 @@
 
 [endsect]
 [///////////////////////////////]
+[section:constructor5 `externally_locked(externally_locked&)`]
+
+ externally_locked(externally_locked& rhs);
+
+[variablelist
+
+[[Requires:] [T is a model of Copyable.]]
+
+[[Effects:] [Copy constructs an externally locked object by copying the cloaked type and copying the mutex reference ]]
+
+[[Throws:] [Any exception thrown by the call to `T(T&)`.]]
+
+]
+
+[endsect]
+[///////////////////////////////]
+[section:assign4 `externally_locked(externally_locked&&)`]
+
+ externally_locked& operator=(externally_locked&& rhs);
+
+[variablelist
+
+[[Requires:] [T is a model of Movable.]]
+
+[[Effects:] [Move assigns an externally locked object by moving the cloaked type and copying the mutex reference ]]
+
+[[Throws:] [Any exception thrown by the call to `T::operator=(T&&)`.]]
+
+]
+
+[endsect]
+[///////////////////////////////]
+[section:assign5 `externally_locked(externally_locked&)`]
+
+ externally_locked& operator=(externally_locked const& rhs);
+
+[variablelist
+
+[[Requires:] [T is a model of Copyable.]]
+
+[[Effects:] [Copy assigns an externally locked object by copying the cloaked type and copying the mutex reference ]]
+
+[[Throws:] [Any exception thrown by the call to `T::operator=(T&)`.]]
+
+]
+
+[endsect]
+
+[///////////////////////////////]
 [section:get1 `get(strict_lock<mutex_type>&)`]
 
     T& get(strict_lock<mutex_type>& lk);
@@ -2613,6 +2668,170 @@
 [endsect]
 
 [endsect]
+[section:externally_locked_ref Template Class `externally_locked<T&>`]
+
+ // #include <boost/thread/externally_locked.hpp>
+
+ template <class T, typename MutexType>
+ class externally_locked<T&, MutexType>
+ {
+ //BOOST_CONCEPT_ASSERT(( CopyConstructible<T> ));
+ BOOST_CONCEPT_ASSERT(( BasicLockable<MutexType> ));
+
+ public:
+ typedef MutexType mutex_type;
+
+ externally_locked(mutex_type& mtx, T& obj);
+ explicit externally_locked(mutex_type& mtx);
+ externally_locked(externally_locked const& rhs) noexcept;
+ externally_locked(externally_locked&& rhs) noexcept;
+ externally_locked& operator=(externally_locked const& rhs) noexcept;
+ externally_locked& operator=(externally_locked&& rhs) noexcept;
+
+ // observers
+ T& get(strict_lock<mutex_type>& lk);
+ const T& get(strict_lock<mutex_type>& lk) const;
+
+ template <class Lock>
+ T& get(nested_strict_lock<Lock>& lk);
+ template <class Lock>
+ const T& get(nested_strict_lock<Lock>& lk) const;
+
+ template <class Lock>
+ T& get(Lock& lk);
+ template <class Lock>
+ T const& get(Lock& lk) const;
+
+ mutex_type* mutex() const noexcept;
+
+ // modifiers
+ void lock();
+ void unlock();
+ bool try_lock();
+ void swap(externally_locked&) noexcept;
+ };
+
+`externally_locked` is a model of __Lockable, it cloaks an object of type `T`, and actually provides full
+access to that object through the get and set member functions, provided you
+pass a reference to a strict lock object.
+
+Only the specificities respect to __Lockable are described here.
+
+[///////////////////////////////]
+[section:constructor1 `externally_locked<T&>(mutex_type&, T&)`]
+
+ externally_locked<T&>(mutex_type& mtx, T& obj) noexcept;
+
+[variablelist
+
+
+[[Effects:] [Constructs an externally locked object copying the cloaked reference.]]
+
+]
+
+[endsect]
+[///////////////////////////////]
+[section:constructor4 `externally_locked<T&>(externally_locked&&)`]
+
+ externally_locked(externally_locked&& rhs) noexcept;
+
+[variablelist
+
+[[Effects:] [Moves an externally locked object by moving the cloaked type and copying the mutex reference ]]
+
+
+]
+
+[endsect]
+[///////////////////////////////]
+[section:assign4 `externally_locked(externally_locked&&)`]
+
+ externally_locked& operator=(externally_locked&& rhs);
+
+[variablelist
+
+[[Effects:] [Move assigns an externally locked object by copying the cloaked reference and copying the mutex reference ]]
+
+]
+
+[endsect]
+[///////////////////////////////]
+[section:assign5 `externally_locked(externally_locked&)`]
+
+ externally_locked& operator=(externally_locked const& rhs);
+
+[variablelist
+
+[[Requires:] [T is a model of Copyable.]]
+
+[[Effects:] [Copy assigns an externally locked object by copying the cloaked reference and copying the mutex reference ]]
+
+[[Throws:] [Any exception thrown by the call to `T::operator=(T&)`.]]
+
+]
+
+[endsect]
+
+[///////////////////////////////]
+[section:get1 `get(strict_lock<mutex_type>&)`]
+
+ T& get(strict_lock<mutex_type>& lk);
+ const T& get(strict_lock<mutex_type>& lk) const;
+
+[variablelist
+
+[[Requires:] [The `lk` parameter must be locking the associated mutex.]]
+
+[[Returns:] [A reference to the cloaked object ]]
+
+[[Throws:] [__lock_error__ if `BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED` is defined and the run-time preconditions are not satisfied .]]
+
+]
+
+[endsect]
+[///////////////////////////////]
+[section:get2 `get(strict_lock<nested_strict_lock<Lock>>&)`]
+
+ template <class Lock>
+ T& get(nested_strict_lock<Lock>& lk);
+ template <class Lock>
+ const T& get(nested_strict_lock<Lock>& lk) const;
+
+[variablelist
+
+[[Requires:] [`is_same<mutex_type, typename Lock::mutex_type>` and the `lk` parameter must be locking the associated mutex.]]
+
+[[Returns:] [A reference to the cloaked object ]]
+
+[[Throws:] [__lock_error__ if `BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED` is defined and the run-time preconditions are not satisfied .]]
+
+]
+
+[endsect]
+
+[///////////////////////////////]
+[section:get3 `get(strict_lock<nested_strict_lock<Lock>>&)`]
+
+ template <class Lock>
+ T& get(Lock& lk);
+ template <class Lock>
+ T const& get(Lock& lk) const;
+
+[variablelist
+
+[[Requires:] [`Lock` is a model of __StrictLock, `is_same<mutex_type, typename Lock::mutex_type>` and the `lk` parameter must be locking the associated mutex.]]
+
+[[Returns:] [A reference to the cloaked object ]]
+
+[[Throws:] [__lock_error__ if `BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATISFIED` is defined and the run-time preconditions are not satisfied .]]
+
+]
+
+[endsect]
+
+[endsect]
+
+
 [///////////////////////////////]
 [section:swap `swap(externally_locked&, externally_locked&)`]
 

Modified: trunk/libs/thread/doc/thread.qbk
==============================================================================
--- trunk/libs/thread/doc/thread.qbk (original)
+++ trunk/libs/thread/doc/thread.qbk 2013-04-28 16:12:28 EDT (Sun, 28 Apr 2013)
@@ -203,6 +203,7 @@
 [def __thread_resource_error__ `boost::thread_resource_error`]
 [def __thread_interrupted__ `boost::thread_interrupted`]
 [def __barrier__ [link thread.synchronization.barriers.barrier `boost::barrier`]]
+[def __latch__ [link thread.synchronization.latches.latch `latch`]]
 
 [template cond_wait_link[link_text] [link thread.synchronization.condvar_ref.condition_variable.wait [link_text]]]
 [def __cond_wait__ [cond_wait_link `wait()`]]
@@ -238,7 +239,9 @@
 [include condition_variables.qbk]
 [include once.qbk]
 [include barrier.qbk]
+[/include latch.qbk]
 [include futures.qbk]
+[/include async_executors.qbk]
 [endsect]
 
 


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