Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52514 - sandbox/task/boost/task
From: oliver.kowalke_at_[hidden]
Date: 2009-04-20 12:19:50


Author: olli
Date: 2009-04-20 12:19:49 EDT (Mon, 20 Apr 2009)
New Revision: 52514
URL: http://svn.boost.org/trac/boost/changeset/52514

Log:
* allow to get a handle from task at any time

Text files modified:
   sandbox/task/boost/task/exceptions.hpp | 8 ++++++++
   sandbox/task/boost/task/handle.hpp | 38 ++++++++++++++++++++++++++++++--------
   sandbox/task/boost/task/pool.hpp | 12 ++++++------
   sandbox/task/boost/task/task.hpp | 10 ++++++++++
   4 files changed, 54 insertions(+), 14 deletions(-)

Modified: sandbox/task/boost/task/exceptions.hpp
==============================================================================
--- sandbox/task/boost/task/exceptions.hpp (original)
+++ sandbox/task/boost/task/exceptions.hpp 2009-04-20 12:19:49 EDT (Mon, 20 Apr 2009)
@@ -52,6 +52,14 @@
         {}
 };
 
+class broken_task : public std::logic_error
+{
+public:
+ broken_task()
+ : std::logic_error("broken task")
+ {}
+};
+
 struct task_interrupted
 {};
 

Modified: sandbox/task/boost/task/handle.hpp
==============================================================================
--- sandbox/task/boost/task/handle.hpp (original)
+++ sandbox/task/boost/task/handle.hpp 2009-04-20 12:19:49 EDT (Mon, 20 Apr 2009)
@@ -15,15 +15,15 @@
 
 namespace boost { namespace task
 {
-template< typename Channel >
-class pool;
+template< typename T >
+class task;
 
 template< typename R >
 class handle
 {
 private:
- template< typename Channel >
- friend class pool;
+ template< typename T >
+ friend class task;
         template< typename Iterator >
         friend void waitfor_all( Iterator begin, Iterator end);
         template< typename T1, typename T2 >
@@ -74,7 +74,12 @@
         { return intr_.interruption_requested(); }
 
         R get()
- { return fut_.get(); }
+ {
+ try
+ { return fut_.get(); }
+ catch ( broken_promise const&)
+ { throw broken_task(); }
+ }
 
         bool is_ready() const
         { return fut_.is_ready(); }
@@ -94,14 +99,20 @@
 
     bool timed_wait_until( system_time const& abs_time) const
         { return fut_.timed_wait_until( abs_time); }
+
+ void swap( handle< R > & other)
+ {
+ fut_.swap( other.fut_);
+ intr_.swap( other.intr_);
+ }
 };
 
 template<>
 class handle< void >
 {
 private:
- template< typename Channel >
- friend class pool;
+ template< typename T >
+ friend class task;
         template< typename Iterator >
         friend void waitfor_all( Iterator begin, Iterator end);
         template< typename T1, typename T2 >
@@ -152,7 +163,12 @@
         { return intr_.interruption_requested(); }
 
         void get()
- { fut_.get(); }
+ {
+ try
+ { fut_.get(); }
+ catch ( broken_promise const&)
+ { throw broken_task(); }
+ }
 
         bool is_ready() const
         { return fut_.is_ready(); }
@@ -172,6 +188,12 @@
 
     bool timed_wait_until( system_time const& abs_time) const
         { return fut_.timed_wait_until( abs_time); }
+
+ void swap( handle< void > & other)
+ {
+ fut_.swap( other.fut_);
+ intr_.swap( other.intr_);
+ }
 };
 
 template< typename Iterator >

Modified: sandbox/task/boost/task/pool.hpp
==============================================================================
--- sandbox/task/boost/task/pool.hpp (original)
+++ sandbox/task/boost/task/pool.hpp 2009-04-20 12:19:49 EDT (Mon, 20 Apr 2009)
@@ -291,7 +291,7 @@
         template< typename R >
         handle< R > submit( task< R > t)
         {
- shared_future< R > fut( t.impl_->prom.get_future() );
+ shared_future< R > fut( t.impl_->fut);
                 detail::worker * w( detail::worker::tss_get() );
                 if ( w)
                 {
@@ -305,7 +305,7 @@
                                         w,
                                         wcb) );
                         w->put( detail::callable( t) );
- return handle< R >( fut, t.impl_->intr);
+ return t.get_handle();
                 }
                 else
                 {
@@ -313,7 +313,7 @@
                                 throw task_rejected("pool is closed");
 
                         channel_.put( detail::callable( t) );
- return handle< R >( fut, t.impl_->intr);
+ return t.get_handle();
                 }
         }
 
@@ -323,7 +323,7 @@
>
         handle< R > submit( task< R > t, Attr const& attr)
         {
- shared_future< R > fut( t.impl_->prom.get_future() );
+ shared_future< R > fut( t.impl_->fut);
                 detail::worker * w( detail::worker::tss_get() );
                 if ( w)
                 {
@@ -337,7 +337,7 @@
                                         w,
                                         wcb) );
                         w->put( detail::callable( t) );
- return handle< R >( fut, t.impl_->intr);
+ return t.get_handle();
                 }
                 else
                 {
@@ -345,7 +345,7 @@
                                 throw task_rejected("pool is closed");
 
                         channel_.put( channel_item( detail::callable( t), attr) );
- return handle< R >( fut, t.impl_->intr);
+ return t.get_handle();
                 }
         }
 };

Modified: sandbox/task/boost/task/task.hpp
==============================================================================
--- sandbox/task/boost/task/task.hpp (original)
+++ sandbox/task/boost/task/task.hpp 2009-04-20 12:19:49 EDT (Mon, 20 Apr 2009)
@@ -46,12 +46,14 @@
         struct impl
         {
                 promise< R > prom;
+ shared_future< R > fut;
                 detail::interrupter intr;
                 exception_ptr excep;
 
                 impl()
                 :
                 prom(),
+ fut( prom.get_future() ),
                 intr(),
                 excep()
                 {}
@@ -127,6 +129,9 @@
         : impl_( new impl_wrapper< Fn >( fn) )
         {}
 
+ const handle< R > get_handle()
+ { return handle< R >( impl_->fut, impl_->intr); }
+
         void swap( task< R > & other) // throw()
         { impl_.swap( other.impl_); }
 
@@ -149,12 +154,14 @@
         struct impl
         {
                 promise< void > prom;
+ shared_future< void > fut;
                 detail::interrupter intr;
                 exception_ptr excep;
 
                 impl()
                 :
                 prom(),
+ fut( prom.get_future() ),
                 intr(),
                 excep()
                 {}
@@ -233,6 +240,9 @@
         : impl_( new impl_wrapper< Fn >( fn) )
         {}
 
+ const handle< void > get_handle()
+ { return handle< void >( impl_->fut, impl_->intr); }
+
         void swap( task< void > & other) // throw()
         { impl_.swap( other.impl_); }
 


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