Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r58848 - in sandbox/task: . boost/task libs/task/doc libs/task/test
From: oliver.kowalke_at_[hidden]
Date: 2010-01-09 13:47:18


Author: olli
Date: 2010-01-09 13:47:17 EST (Sat, 09 Jan 2010)
New Revision: 58848
URL: http://svn.boost.org/trac/boost/changeset/58848

Log:
- fiber as execution policy

Text files modified:
   sandbox/task/boost/task/async.hpp | 89 +++++++++++++++++++++++++++++++++++----
   sandbox/task/change.log | 1
   sandbox/task/libs/task/doc/async_execution.qbk | 40 +++++------------
   sandbox/task/libs/task/test/Jamfile.v2 | 1
   4 files changed, 93 insertions(+), 38 deletions(-)

Modified: sandbox/task/boost/task/async.hpp
==============================================================================
--- sandbox/task/boost/task/async.hpp (original)
+++ sandbox/task/boost/task/async.hpp 2010-01-09 13:47:17 EST (Sat, 09 Jan 2010)
@@ -7,11 +7,20 @@
 #ifndef BOOST_TASKS_ASYNC_H
 #define BOOST_TASKS_ASYNC_H
 
+#include <cstddef>
+
 #include <boost/config.hpp>
 #include <boost/move/move.hpp>
+#include <boost/fiber.hpp>
+#include <boost/thread/future.hpp>
 
 #include <boost/task/as_sub_task.hpp>
+#include <boost/task/callable.hpp>
+#include <boost/task/context.hpp>
 #include <boost/task/handle.hpp>
+#include <boost/task/new_thread.hpp>
+#include <boost/task/own_thread.hpp>
+#include <boost/task/spin/future.hpp>
 #include <boost/task/static_pool.hpp>
 #include <boost/task/task.hpp>
 
@@ -22,23 +31,39 @@
 
 template< typename R >
 handle< R > async( task< R > t)
-{ return as_sub_task()( boost::move( t) ); }
+{ return async( boost::move( t) ); }
 
 template< typename R >
 handle< R > async( BOOST_RV_REF( task< R >) t)
 { return as_sub_task()( t); }
 
-template< typename R, typename EP >
-handle< R > async( task< R > t, EP ep)
-{ return ep( boost::move( t) ); }
-
-template< typename R, typename EP >
-handle< R > async( BOOST_RV_REF( task< R >) t, EP ep)
-{ return ep( t); }
+template< typename R >
+handle< R > async( task< R > t, as_sub_task ast)
+{ return async( boost::move( t), ast); }
+
+template< typename R >
+handle< R > async( BOOST_RV_REF( task< R >) t, as_sub_task ast)
+{ return ast( t); }
+
+template< typename R >
+handle< R > async( task< R > t, own_thread ot)
+{ return async( boost::move( t) ); }
+
+template< typename R >
+handle< R > async( BOOST_RV_REF( task< R >) t, own_thread ot)
+{ return ot( t); }
+
+template< typename R >
+handle< R > async( task< R > t, new_thread nt)
+{ return async( boost::move( t), nt); }
+
+template< typename R >
+handle< R > async( BOOST_RV_REF( task< R >) t, new_thread nt)
+{ return nt( t); }
 
 template< typename R, typename Queue, typename UMS >
 handle< R > async( task< R > t, static_pool< Queue, UMS > & pool)
-{ return pool.submit( boost::move( t) ); }
+{ return async( boost::move(t), pool); }
 
 template< typename R, typename Queue, typename UMS >
 handle< R > async( BOOST_RV_REF( task< R >) t, static_pool< Queue, UMS > & pool)
@@ -46,12 +71,56 @@
 
 template< typename R, typename Attr, typename Queue, typename UMS >
 handle< R > async( task< R > t, Attr attr, static_pool< Queue, UMS > & pool)
-{ return pool.submit( boost::move( t), attr); }
+{ return async( boost::move(t), attr, pool); }
 
 template< typename R, typename Attr, typename Queue, typename UMS >
 handle< R > async( BOOST_RV_REF( task< R >) t, Attr attr, static_pool< Queue, UMS > & pool)
 { return pool.submit( t, attr); }
 
+template< typename R, typename Strategy >
+handle< R > async(
+ task< R > t,
+ fibers::scheduler< Strategy > & sched,
+ std::size_t stacksize = fiber::default_stacksize)
+{ return async( boost::move( t), sched, stacksize); }
+
+template< typename R, typename Strategy >
+handle< R > async(
+ BOOST_RV_REF( task< R >) t,
+ fibers::scheduler< Strategy > & sched,
+ std::size_t stacksize = fiber::default_stacksize)
+{
+ if ( this_task::runs_in_pool() )
+ {
+ spin::promise< R > prom;
+ spin::shared_future< R > f( prom.get_future() );
+ context ctx;
+ handle< R > h( f, ctx);
+ fiber fib( callable( t, boost::move( prom), ctx), stacksize);
+ sched.submit_fiber( boost::move( fib) );
+ return h;
+ }
+ else
+ {
+ promise< R > prom;
+ shared_future< R > f( prom.get_future() );
+ context ctx;
+ handle< R > h( f, ctx);
+ fiber fib(
+ callable(
+ t,
+// TODO: workaround because thread_move_t will be abigous for move
+#ifdef BOOST_HAS_RVALUE_REFS
+ boost::move( prom),
+#else
+ boost::detail::thread_move_t< promise< R > >( prom),
+#endif
+ ctx), stacksize);
+ sched.submit_fiber( boost::move( fib) );
+ return h;
+ }
+}
+
 }}
 
 #include <boost/config/abi_suffix.hpp>

Modified: sandbox/task/change.log
==============================================================================
--- sandbox/task/change.log (original)
+++ sandbox/task/change.log 2010-01-09 13:47:17 EST (Sat, 09 Jan 2010)
@@ -4,6 +4,7 @@
 - worker-threads of thread-pools used fibers for yielding tasks
 - documentation re-work
 - sync. prmitives (using spin-wait) added for inter-task communication
+- async() with fiber-scheduler
 
 
 * boost.task-0.3.0:

Modified: sandbox/task/libs/task/doc/async_execution.qbk
==============================================================================
--- sandbox/task/libs/task/doc/async_execution.qbk (original)
+++ sandbox/task/libs/task/doc/async_execution.qbk 2010-01-09 13:47:17 EST (Sat, 09 Jan 2010)
@@ -54,48 +54,32 @@
         }
 
 
-[section:async Non-member function `template< typename R, typename EP > async( task< R >, EP)`]
+[section:async Non-member function `async()`]
 
         #include <boost/task/async.hpp>
 
- template< typename R, typename EP >
- handle< R > async( task< R > t, EP ep);
+ template< typename R >
+ handle< R > async( task< R > t);
 
-[variablelist
-[[Effects:] [moves task to an asyncrounous executer and returns a handle associated with the task]]
-[[Throws:] [`boost::thread_resource_error`]]
-]
-
-[endsect]
+ template< typename R >
+ handle< R > async( task< R > t, own_thread ep);
 
-
-[section:async1 Non-member function `template< typename R, typename Channel > async( task< R >, pool< Channel > &)`]
-
- #include <boost/task/async.hpp>
+ template< typename R >
+ handle< R > async( task< R > t, new_thread ep);
 
         template< typename R, typename Channel >
         handle< R > async( task< R > t, pool< Channel > & ep);
 
-[variablelist
-[[Effects:] [moves task into a thread-pool and returns a handle associated with the task]]
-[[Throws:] [`boost::tasks::task_rejected`]]
-]
-
-[endsect]
-
-
-[section:async2 Non-member function `template< typename R, typename Channel, typename Attr > async( task< R >, Attr, pool< Channel > &)`]
-
- #include <boost/task/async.hpp>
-
         template< typename R, typename Channel, typename Attr >
         handle< R > async( task< R > t, Attr attr, pool< Channel > & ep);
 
+ template< typename R, typename Strategy >
+ handle< R > async( task< R > t, fibers::scheduler< Strategy > & ep);
+
 [variablelist
-[[Effects:] [moves attributed task into a thread-pool and returns a handle associated with the task]]
-[[Throws:] [`boost::tasks::task_rejected`]]
+[[Effects:] [moves task to an asyncrounous executer and returns a handle associated with the task]]
+[[Throws:] [`boost::thread_resource_error`]]
 ]
-
 [endsect]
 
 [endsect]

Modified: sandbox/task/libs/task/test/Jamfile.v2
==============================================================================
--- sandbox/task/libs/task/test/Jamfile.v2 (original)
+++ sandbox/task/libs/task/test/Jamfile.v2 2010-01-09 13:47:17 EST (Sat, 09 Jan 2010)
@@ -28,6 +28,7 @@
 test-suite task :
     [ task-test test_task ]
     [ task-test test_own_thread ]
+ [ task-test test_fiber ]
     [ task-test test_new_thread ]
     [ task-test test_unbounded_pool ]
     [ task-test test_bounded_pool ]


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