Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85644 - in trunk: boost/thread libs/thread/doc
From: vicente.botet_at_[hidden]
Date: 2013-09-10 15:40:14


Author: viboes
Date: 2013-09-10 15:40:14 EDT (Tue, 10 Sep 2013)
New Revision: 85644
URL: http://svn.boost.org/trac/boost/changeset/85644

Log:
Thread: added future<>::get_exception_ptr().

Text files modified:
   trunk/boost/thread/future.hpp | 60 ++++++++++++++++++++++++++++------------
   trunk/libs/thread/doc/future_ref.qbk | 46 ++++++++++++++++++++++++++++--
   2 files changed, 84 insertions(+), 22 deletions(-)

Modified: trunk/boost/thread/future.hpp
==============================================================================
--- trunk/boost/thread/future.hpp Tue Sep 10 14:55:52 2013 (r85643)
+++ trunk/boost/thread/future.hpp 2013-09-10 15:40:14 EDT (Tue, 10 Sep 2013) (r85644)
@@ -213,7 +213,7 @@
             bool is_deferred_;
             launch policy_;
             bool is_constructed;
- boost::mutex mutex;
+ mutable boost::mutex mutex;
             boost::condition_variable waiters;
             waiter_list external_waiters;
             boost::function<void()> callback;
@@ -434,7 +434,7 @@
               get_current_thread_data()->make_ready_at_thread_exit(shared_from_this());
             }
 
- bool has_value()
+ bool has_value() const
             {
                 boost::lock_guard<boost::mutex> lock(mutex);
                 return done && !(exception
@@ -444,7 +444,7 @@
                 );
             }
 
- bool has_value(unique_lock<boost::mutex>& )
+ bool has_value(unique_lock<boost::mutex>& ) const
             {
                 return done && !(exception
 #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
@@ -453,7 +453,7 @@
                 );
             }
 
- bool has_exception()
+ bool has_exception() const
             {
                 boost::lock_guard<boost::mutex> lock(mutex);
                 return done && (exception
@@ -463,7 +463,7 @@
                     );
             }
 
- bool has_exception(unique_lock<boost::mutex>&)
+ bool has_exception(unique_lock<boost::mutex>&) const
             {
                 return done && (exception
 #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
@@ -472,16 +472,16 @@
                     );
             }
 
- bool is_deferred() const BOOST_NOEXCEPT {
+ bool is_deferred(boost::lock_guard<boost::mutex>&) const {
                 return is_deferred_;
             }
 
- launch launch_policy() const BOOST_NOEXCEPT
+ launch launch_policy(boost::unique_lock<boost::mutex>&) const
             {
                 return policy_;
             }
 
- future_state::state get_state()
+ future_state::state get_state() const
             {
                 boost::lock_guard<boost::mutex> guard(mutex);
                 if(!done)
@@ -494,6 +494,23 @@
                 }
             }
 
+ exception_ptr get_exception_ptr()
+ {
+ boost::unique_lock<boost::mutex> lock(mutex);
+ return get_exception_ptr(lock);
+ }
+ exception_ptr get_exception_ptr(boost::unique_lock<boost::mutex>& lock)
+ {
+ wait_internal(lock, false);
+#if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS
+ if(thread_was_interrupted)
+ {
+ return copy_exception(boost::thread_interrupted());
+ }
+#endif
+ return exception;
+ }
+
             template<typename F,typename U>
             void set_wait_callback(F f,U* u)
             {
@@ -1294,7 +1311,7 @@
           future_.swap(that.future_);
         }
         // functions to check state, and wait for ready
- state get_state() const BOOST_NOEXCEPT
+ state get_state() const
         {
             if(!future_)
             {
@@ -1303,27 +1320,34 @@
             return future_->get_state();
         }
 
- bool is_ready() const BOOST_NOEXCEPT
+ bool is_ready() const
         {
             return get_state()==future_state::ready;
         }
 
- bool has_exception() const BOOST_NOEXCEPT
+ bool has_exception() const
         {
             return future_ && future_->has_exception();
         }
 
- bool has_value() const BOOST_NOEXCEPT
+ bool has_value() const
         {
             return future_ && future_->has_value();
         }
 
- launch launch_policy() const BOOST_NOEXCEPT
+ launch launch_policy(boost::unique_lock<boost::mutex>& lk) const
         {
- if ( future_ ) return future_->launch_policy();
+ if ( future_ ) return future_->launch_policy(lk);
             else return launch(launch::none);
         }
 
+ exception_ptr get_exception_ptr()
+ {
+ return future_
+ ? future_->get_exception_ptr()
+ : exception_ptr();
+ }
+
         bool valid() const BOOST_NOEXCEPT
         {
             return future_ != 0;
@@ -3938,13 +3962,13 @@
     BOOST_THREAD_ASSERT_PRECONDITION(this->future_!=0, future_uninitialized());
 
     boost::unique_lock<boost::mutex> lock(this->future_->mutex);
- if (int(this->launch_policy()) & int(launch::async))
+ if (int(this->launch_policy(lock)) & int(launch::async))
     {
       return boost::detail::make_future_async_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type, F>(
           lock, boost::move(*this), boost::forward<F>(func)
       );
     }
- else if (int(this->launch_policy()) & int(launch::deferred))
+ else if (int(this->launch_policy(lock)) & int(launch::deferred))
     {
       this->future_->wait_internal(lock);
       return boost::detail::make_future_deferred_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type, F>(
@@ -4056,13 +4080,13 @@
     BOOST_THREAD_ASSERT_PRECONDITION(this->future_!=0, future_uninitialized());
 
     boost::unique_lock<boost::mutex> lock(this->future_->mutex);
- if (int(this->launch_policy()) & int(launch::async))
+ if (int(this->launch_policy(lock)) & int(launch::async))
     {
       return boost::detail::make_future_async_continuation_shared_state<shared_future<R>, future_type, F>(
           lock, boost::move(*this), boost::forward<F>(func)
       );
     }
- else if (int(this->launch_policy()) & int(launch::deferred))
+ else if (int(this->launch_policy(lock)) & int(launch::deferred))
     {
       this->future_->wait_internal(lock);
       return boost::detail::make_future_deferred_continuation_shared_state<shared_future<R>, future_type, F>(

Modified: trunk/libs/thread/doc/future_ref.qbk
==============================================================================
--- trunk/libs/thread/doc/future_ref.qbk Tue Sep 10 14:55:52 2013 (r85643)
+++ trunk/libs/thread/doc/future_ref.qbk 2013-09-10 15:40:14 EDT (Tue, 10 Sep 2013) (r85644)
@@ -301,6 +301,8 @@
       // retrieving the value
       see below get();
       see below get_or(see below); // EXTENSION
+
+ exception_ptr get_exception_ptr(); // EXTENSION
 
       // functions to check state
       bool valid() const noexcept;
@@ -759,6 +761,23 @@
 ]
 
 [endsect]
+[/////////////////////////////////////////////////////////////////]
+[section:get_exception_ptr Member function `get_exception_ptr()` EXTENSION]
+
+ exception_ptr get_exception_ptr();
+
+[variablelist
+
+[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready. If the result is not ready on
+entry, and the result has a ['wait callback] set, that callback is invoked prior to waiting.]]
+
+[[Returns:] [a exception_ptr, storring or not an exception.]]
+
+[[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
+
+]
+
+[endsect]
 [/////////////////////////////////////////////////////////]
 [section:get_state Member function `get_state()` EXTENSION]
 
@@ -925,6 +944,8 @@
       // retrieving the value
       see below get();
 
+ exception_ptr get_exception_ptr(); // EXTENSION
+
       // functions to check state, and wait for ready
       bool valid() const noexcept;
       bool is_ready() const noexcept; // EXTENSION
@@ -1185,7 +1206,7 @@
 [[Returns:] [`true` if `*this` is associated with a shared state, and that result is ready for retrieval, `false`
 otherwise.]]
 
-[[Throws:] [Nothing.]]
+[[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
 
 ]
 
@@ -1200,7 +1221,7 @@
 [[Returns:] [`true` if `*this` is associated with a shared state, that result is ready for retrieval, and the result is a
 stored value, `false` otherwise.]]
 
-[[Throws:] [Nothing.]]
+[[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
 
 ]
 
@@ -1215,7 +1236,24 @@
 [[Returns:] [`true` if `*this` is associated with a shared state, that result is ready for retrieval, and the result is a
 stored exception, `false` otherwise.]]
 
-[[Throws:] [Nothing.]]
+[[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
+
+]
+
+[endsect]
+[/////////////////////////////////////////////////////////////////]
+[section:get_exception_ptr Member function `get_exception_ptr()` EXTENSION]
+
+ exception_ptr get_exception_ptr();
+
+[variablelist
+
+[[Effects:] [If `*this` is associated with a shared state, waits until the result is ready. If the result is not ready on
+entry, and the result has a ['wait callback] set, that callback is invoked prior to waiting.]]
+
+[[Returns:] [a exception_ptr, storring or not an exception.]]
+
+[[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
 
 ]
 
@@ -1232,7 +1270,7 @@
 [[Returns:] [__uninitialized__ if `*this` is not associated with a shared state. __ready__ if the shared state
 associated with `*this` is ready for retrieval, __waiting__ otherwise.]]
 
-[[Throws:] [Nothing.]]
+[[Throws:] [Whatever `mutex::lock()/mutex::unlock()` can throw.]]
 
 ]
 


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