Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57256 - in sandbox/task: boost/task boost/task/detail libs/task/src
From: oliver.kowalke_at_[hidden]
Date: 2009-10-31 04:49:24


Author: olli
Date: 2009-10-31 04:49:23 EDT (Sat, 31 Oct 2009)
New Revision: 57256
URL: http://svn.boost.org/trac/boost/changeset/57256

Log:
- bugfix for wsq -> swap callable taken from queue (with assignment it would be still in the queue)
- bugfix for as_sub_task -> callback for blocking task must use a weak_ptr to shared_future (requires handle to store a shared_ptr< shared_future >)

Text files modified:
   sandbox/task/boost/task/as_sub_task.hpp | 21 ++++++++++++++++++---
   sandbox/task/boost/task/detail/pool_base.hpp | 9 +++++++--
   sandbox/task/boost/task/handle.hpp | 24 ++++++++++++------------
   sandbox/task/boost/task/new_thread.hpp | 4 +++-
   sandbox/task/boost/task/own_thread.hpp | 5 ++++-
   sandbox/task/libs/task/src/wsq.cpp | 31 ++++++++++++++++---------------
   6 files changed, 60 insertions(+), 34 deletions(-)

Modified: sandbox/task/boost/task/as_sub_task.hpp
==============================================================================
--- sandbox/task/boost/task/as_sub_task.hpp (original)
+++ sandbox/task/boost/task/as_sub_task.hpp 2009-10-31 04:49:23 EDT (Sat, 31 Oct 2009)
@@ -10,7 +10,9 @@
 #include <boost/bind.hpp>
 #include <boost/config.hpp>
 #include <boost/function.hpp>
+#include <boost/shared_ptr.hpp>
 #include <boost/thread/detail/move.hpp>
+#include <boost/weak_ptr.hpp>
 
 #include <boost/task/callable.hpp>
 #include <boost/task/context.hpp>
@@ -24,6 +26,17 @@
 
 namespace boost {
 namespace task {
+namespace {
+
+template< typename R >
+bool future_ready( weak_ptr< shared_future< R > > wptr)
+{
+ shared_ptr< shared_future< R > > sptr = wptr.lock();
+ BOOST_ASSERT( sptr);
+ return sptr->is_ready();
+}
+
+}
 
 struct as_sub_task
 {
@@ -33,11 +46,13 @@
                 detail::worker * w( detail::worker::tss_get() );
                 if ( w)
                 {
- shared_future< R > f( t.get_future() );
+ shared_ptr< shared_future< R > > f(
+ new shared_future< R >(
+ t.get_future() ) );
                         function< bool() > wcb(
                                 bind(
- & shared_future< R >::is_ready,
- f) );
+ ( bool (*) ( weak_ptr< shared_future< R > >) ) & future_ready,
+ weak_ptr< shared_future< R > >( f) ) );
                         t.set_wait_callback(
                                 bind(
                                         ( void ( detail::worker::*)( function< bool() > const&) ) & detail::worker::reschedule_until,

Modified: sandbox/task/boost/task/detail/pool_base.hpp
==============================================================================
--- sandbox/task/boost/task/detail/pool_base.hpp (original)
+++ sandbox/task/boost/task/detail/pool_base.hpp 2009-10-31 04:49:23 EDT (Sat, 31 Oct 2009)
@@ -14,6 +14,7 @@
 #include <boost/config.hpp>
 #include <boost/cstdint.hpp>
 #include <boost/date_time/posix_time/posix_time.hpp>
+#include <boost/shared_ptr.hpp>
 #include <boost/thread.hpp>
 #include <boost/thread/detail/move.hpp>
 
@@ -277,7 +278,9 @@
                 if ( closed_() )
                         throw task_rejected("pool is closed");
 
- shared_future< R > f( t.get_future() );
+ shared_ptr< shared_future< R > > f(
+ new shared_future< R >(
+ t.get_future() ) );
                 context ctx;
                 handle< R > h( f, ctx);
                 queue_.put( callable( boost::move( t), ctx) );
@@ -290,7 +293,9 @@
                 if ( closed_() )
                         throw task_rejected("pool is closed");
 
- shared_future< R > f( t.get_future() );
+ shared_ptr< shared_future< R > > f(
+ new shared_future< R >(
+ t.get_future() ) );
                 context ctx;
                 handle< R > h( f, ctx);
                 queue_.put(

Modified: sandbox/task/boost/task/handle.hpp
==============================================================================
--- sandbox/task/boost/task/handle.hpp (original)
+++ sandbox/task/boost/task/handle.hpp 2009-10-31 04:49:23 EDT (Sat, 31 Oct 2009)
@@ -26,16 +26,16 @@
 class handle
 {
 private:
- shared_future< R > fut_;
- context ctx_;
+ shared_ptr< shared_future< R > > fut_;
+ context ctx_;
 
 public:
         handle() :
- fut_(), ctx_()
+ fut_( new shared_future< R >() ), ctx_()
         {}
 
         handle(
- shared_future< R > fut,
+ shared_ptr< shared_future< R > > const& fut,
                         context const& ctx) :
                 fut_( fut),
                 ctx_( ctx)
@@ -69,7 +69,7 @@
         R get()
         {
                 try
- { return fut_.get(); }
+ { return fut_->get(); }
                 catch ( future_uninitialized const&)
                 { throw task_uninitialized(); }
                 catch ( broken_promise const&)
@@ -79,18 +79,18 @@
         }
 
         bool is_ready() const
- { return fut_.is_ready(); }
+ { return fut_->is_ready(); }
 
         bool has_value() const
- { return fut_.has_value(); }
+ { return fut_->has_value(); }
 
         bool has_exception() const
- { return fut_.has_exception(); }
+ { return fut_->has_exception(); }
 
         void wait() const
         {
                 try
- { fut_.wait(); }
+ { fut_->wait(); }
                 catch ( future_uninitialized const&)
                 { throw task_uninitialized(); }
                 catch ( broken_promise const&)
@@ -103,7 +103,7 @@
         bool wait_for( Duration const& rel_time) const
         {
                 try
- { return fut_.timed_wait( rel_time); }
+ { return fut_->timed_wait( rel_time); }
                 catch ( future_uninitialized const&)
                 { throw task_uninitialized(); }
                 catch ( broken_promise const&)
@@ -115,7 +115,7 @@
         bool wait_until( system_time const& abs_time) const
         {
                 try
- { return fut_.timed_wait_until( abs_time); }
+ { return fut_->timed_wait_until( abs_time); }
                 catch ( future_uninitialized const&)
                 { throw task_uninitialized(); }
                 catch ( broken_promise const&)
@@ -125,7 +125,7 @@
         }
 
         shared_future< R > & get_future()
- { return fut_; }
+ { return * fut_; }
 
         void swap( handle< R > & other)
         {

Modified: sandbox/task/boost/task/new_thread.hpp
==============================================================================
--- sandbox/task/boost/task/new_thread.hpp (original)
+++ sandbox/task/boost/task/new_thread.hpp 2009-10-31 04:49:23 EDT (Sat, 31 Oct 2009)
@@ -65,7 +65,9 @@
         template< typename R >
         handle< R > operator()( task< R > t)
         {
- shared_future< R > f( t.get_future() );
+ shared_ptr< shared_future< R > > f(
+ new shared_future< R >(
+ t.get_future() ) );
                 context ctx1, ctx2;
                 handle< R > h( f, ctx1);
                 callable ca( boost::move( t), ctx2);

Modified: sandbox/task/boost/task/own_thread.hpp
==============================================================================
--- sandbox/task/boost/task/own_thread.hpp (original)
+++ sandbox/task/boost/task/own_thread.hpp 2009-10-31 04:49:23 EDT (Sat, 31 Oct 2009)
@@ -8,6 +8,7 @@
 #define BOOST_TASK_OWN_THREAD_H
 
 #include <boost/config.hpp>
+#include <boost/shared_ptr.hpp>
 #include <boost/thread/detail/move.hpp>
 
 #include <boost/task/callable.hpp>
@@ -26,7 +27,9 @@
         template< typename R >
         handle< R > operator()( task< R > t)
         {
- shared_future< R > f( t.get_future() );
+ shared_ptr< shared_future< R > > f(
+ new shared_future< R >(
+ t.get_future() ) );
                 context ctx;
                 handle< R > h( f, ctx);
                 callable ca( boost::move( t), ctx);

Modified: sandbox/task/libs/task/src/wsq.cpp
==============================================================================
--- sandbox/task/libs/task/src/wsq.cpp (original)
+++ sandbox/task/libs/task/src/wsq.cpp 2009-10-31 04:49:23 EDT (Sat, 31 Oct 2009)
@@ -10,18 +10,19 @@
 
 #include <boost/task/detail/atomic.hpp>
 
-namespace boost {
-namespace task {
-namespace detail {
-
-wsq::wsq() :
- initial_size_( 32),
- array_( new callable[ initial_size_]),
- capacity_( initial_size_),
- mask_( initial_size_ - 1),
- head_idx_( 0),
- tail_idx_( 0),
- mtx_()
+namespace boost { namespace task {
+namespace detail
+{
+
+wsq::wsq()
+:
+initial_size_( 32),
+array_( new callable[ initial_size_]),
+capacity_( initial_size_),
+mask_( initial_size_ - 1),
+head_idx_( 0),
+tail_idx_( 0),
+mtx_()
 {}
 
 bool
@@ -73,7 +74,7 @@
         atomic_exchange( & tail_idx_, tail);
         if ( head_idx_ <= tail)
         {
- ca = array_[tail & mask_];
+ ca.swap( array_[tail & mask_]);
                 return true;
         }
         else
@@ -81,7 +82,7 @@
                 lock_guard< recursive_mutex > lk( mtx_);
                 if ( head_idx_ <= tail)
                 {
- ca = array_[tail & mask_];
+ ca.swap( array_[tail & mask_]);
                         return true;
                 }
                 else
@@ -102,7 +103,7 @@
                 atomic_exchange( & head_idx_, head + 1);
                 if ( head < tail_idx_)
                 {
- ca = array_[head & mask_];
+ ca.swap( array_[head & mask_]);
                         return true;
                 }
                 else


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