|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52493 - in sandbox/task: boost boost/task libs/task/examples libs/task/src libs/task/test
From: oliver.kowalke_at_[hidden]
Date: 2009-04-19 14:40:34
Author: olli
Date: 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
New Revision: 52493
URL: http://svn.boost.org/trac/boost/changeset/52493
Log:
* task splitt into task and handle
Added:
sandbox/task/boost/task/handle.hpp (contents, props changed)
Text files modified:
sandbox/task/boost/task.hpp | 1
sandbox/task/boost/task/launch.hpp | 17 ++-
sandbox/task/boost/task/pool.hpp | 15 ++
sandbox/task/boost/task/task.hpp | 178 ---------------------------------------
sandbox/task/libs/task/examples/bind_to_processors.cpp | 49 ++++------
sandbox/task/libs/task/examples/delay.cpp | 26 ++--
sandbox/task/libs/task/examples/fork_join.cpp | 49 ++++------
sandbox/task/libs/task/examples/interrupt.cpp | 14 +-
sandbox/task/libs/task/examples/pending.cpp | 12 +-
sandbox/task/libs/task/examples/reschedule_until.cpp | 26 ++--
sandbox/task/libs/task/examples/shutdonw_now.cpp | 13 +-
sandbox/task/libs/task/examples/submit.cpp | 18 +--
sandbox/task/libs/task/examples/yield.cpp | 34 ++----
sandbox/task/libs/task/src/wsq.cpp | 4
sandbox/task/libs/task/test/test_launch.cpp | 35 ++++---
sandbox/task/libs/task/test/test_pool_bounded_channel.cpp | 22 ++--
16 files changed, 161 insertions(+), 352 deletions(-)
Modified: sandbox/task/boost/task.hpp
==============================================================================
--- sandbox/task/boost/task.hpp (original)
+++ sandbox/task/boost/task.hpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -11,6 +11,7 @@
#include <boost/task/default_pool.hpp>
#include <boost/task/exceptions.hpp>
#include <boost/task/fifo.hpp>
+#include <boost/task/handle.hpp>
#include <boost/task/info.hpp>
#include <boost/task/launch.hpp>
#include <boost/task/lifo.hpp>
Added: sandbox/task/boost/task/handle.hpp
==============================================================================
--- (empty file)
+++ sandbox/task/boost/task/handle.hpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -0,0 +1,227 @@
+
+// Copyright Oliver Kowalke 2009.
+// Distributed under the Boost Software License, Version 1.0.
+// (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+
+#ifndef BOOST_TASK_HANDLE_H
+#define BOOST_TASK_HANDLE_H
+
+#include <boost/thread.hpp>
+#include <boost/thread/thread_time.hpp>
+
+#include <boost/task/detail/interrupter.hpp>
+#include <boost/task/future.hpp>
+
+namespace boost { namespace task
+{
+template< typename Channel >
+class pool;
+
+template< typename R >
+class handle
+{
+private:
+ template< typename Channel >
+ friend class pool;
+ template< typename Iterator >
+ friend void waitfor_all( Iterator begin, Iterator end);
+ template< typename T1, typename T2 >
+ friend void waitfor_all( T1 & t1, T2 & t2);
+ template< typename T1, typename T2, typename T3 >
+ friend void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3);
+ template< typename T1, typename T2, typename T3, typename T4 >
+ friend void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4);
+ template< typename T1, typename T2, typename T3, typename T4, typename T5 >
+ friend void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5);
+ template< typename Iterator >
+ friend Iterator waitfor_any( Iterator begin, Iterator end);
+ template< typename T1, typename T2 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2);
+ template< typename T1, typename T2, typename T3 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3);
+ template< typename T1, typename T2, typename T3, typename T4 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4);
+ template< typename T1, typename T2, typename T3, typename T4, typename T5 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5);
+
+ shared_future< R > fut_;
+ detail::interrupter intr_;
+
+ handle( shared_future< R > const& fut, detail::interrupter const& intr)
+ : fut_( fut), intr_( intr)
+ {}
+
+public:
+ handle()
+ : fut_(), intr_()
+ {}
+
+ void interrupt()
+ { intr_.interrupt(); }
+
+ void interrupt_and_wait()
+ { intr_.interrupt_and_wait(); }
+
+ void interrupt_and_wait( system_time const& abs_time)
+ { intr_.interrupt_and_wait( abs_time); }
+
+ template< typename Duration >
+ void interrupt_and_wait( Duration const& rel_time)
+ { intr_.interrupt_and_wait( rel_time); }
+
+ bool interruption_requested()
+ { return intr_.interruption_requested(); }
+
+ R get()
+ { return fut_.get(); }
+
+ bool is_ready() const
+ { return fut_.is_ready(); }
+
+ bool has_value() const
+ { return fut_.has_value(); }
+
+ bool has_exception() const
+ { return fut_.has_exception(); }
+
+ void wait() const
+ { fut_.wait(); }
+
+ template< typename Duration >
+ bool timed_wait( Duration const& rel_time) const
+ { return fut_.timed_wait( rel_time); }
+
+ bool timed_wait_until( system_time const& abs_time) const
+ { return fut_.timed_wait_until( abs_time); }
+};
+
+template<>
+class handle< void >
+{
+private:
+ template< typename Channel >
+ friend class pool;
+ template< typename Iterator >
+ friend void waitfor_all( Iterator begin, Iterator end);
+ template< typename T1, typename T2 >
+ friend void waitfor_all( T1 & t1, T2 & t2);
+ template< typename T1, typename T2, typename T3 >
+ friend void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3);
+ template< typename T1, typename T2, typename T3, typename T4 >
+ friend void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4);
+ template< typename T1, typename T2, typename T3, typename T4, typename T5 >
+ friend void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5);
+ template< typename Iterator >
+ friend Iterator waitfor_any( Iterator begin, Iterator end);
+ template< typename T1, typename T2 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2);
+ template< typename T1, typename T2, typename T3 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3);
+ template< typename T1, typename T2, typename T3, typename T4 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4);
+ template< typename T1, typename T2, typename T3, typename T4, typename T5 >
+ friend unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5);
+
+ shared_future< void > fut_;
+ detail::interrupter intr_;
+
+ handle( shared_future< void > const& fut, detail::interrupter const& intr)
+ : fut_( fut), intr_( intr)
+ {}
+
+public:
+ handle()
+ : fut_(), intr_()
+ {}
+
+ void interrupt()
+ { intr_.interrupt(); }
+
+ void interrupt_and_wait()
+ { intr_.interrupt_and_wait(); }
+
+ void interrupt_and_wait( system_time const& abs_time)
+ { intr_.interrupt_and_wait( abs_time); }
+
+ template< typename Duration >
+ void interrupt_and_wait( Duration const& rel_time)
+ { intr_.interrupt_and_wait( rel_time); }
+
+ bool interruption_requested()
+ { return intr_.interruption_requested(); }
+
+ void get()
+ { fut_.get(); }
+
+ bool is_ready() const
+ { return fut_.is_ready(); }
+
+ bool has_value() const
+ { return fut_.has_value(); }
+
+ bool has_exception() const
+ { return fut_.has_exception(); }
+
+ void wait() const
+ { fut_.wait(); }
+
+ template< typename Duration >
+ bool timed_wait( Duration const& rel_time) const
+ { return fut_.timed_wait( rel_time); }
+
+ bool timed_wait_until( system_time const& abs_time) const
+ { return fut_.timed_wait_until( abs_time); }
+};
+
+template< typename Iterator >
+void waitfor_all( Iterator begin, Iterator end)
+{
+ for ( Iterator i = begin; i != end; ++i)
+ i->wait();
+}
+
+template< typename T1, typename T2 >
+void waitfor_all( T1 & t1, T2 & t2)
+{ wait_for_all( t1.fut_, t2.fut_); }
+
+template< typename T1, typename T2, typename T3 >
+void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3)
+{ wait_for_all( t1.fut_, t2.fut_, t3.fut_); }
+
+template< typename T1, typename T2, typename T3, typename T4 >
+void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4)
+{ wait_for_all( t1.fut_, t2.fut_, t3.fut_, t4.fut_); }
+
+template< typename T1, typename T2, typename T3, typename T4, typename T5 >
+void waitfor_all( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5)
+{ wait_for_all( t1.fut_, t2.fut_, t3.fut_, t4.fut_, t5.fut_); }
+
+template< typename Iterator >
+Iterator waitfor_any( Iterator begin, Iterator end)
+{
+ boost::detail::future_waiter waiter;
+ for ( Iterator i = begin; i != end; ++i)
+ waiter.add( i->fut_);
+ return next( begin, waiter.wait() );
+}
+
+template< typename T1, typename T2 >
+unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2)
+{ return wait_for_any( t1.fut_, t2.fut_); }
+
+template< typename T1, typename T2, typename T3 >
+unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3)
+{ return wait_for_any( t1.fut_, t2.fut_, t3.fut_); }
+
+template< typename T1, typename T2, typename T3, typename T4 >
+unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4)
+{ return wait_for_any( t1.fut_, t2.fut_, t3.fut_, t4.fut_); }
+
+template< typename T1, typename T2, typename T3, typename T4, typename T5 >
+unsigned int waitfor_any( handle< T1 > & t1, handle< T2 > & t2, handle< T3 > & t3, handle< T4 > & t4, handle< T5 > & t5)
+{ return wait_for_any( t1.fut_, t2.fut_, t3.fut_, t4.fut_, t5.fut_); }
+
+}}
+
+#endif // BOOST_TASK_HANDLE_H
Modified: sandbox/task/boost/task/launch.hpp
==============================================================================
--- sandbox/task/boost/task/launch.hpp (original)
+++ sandbox/task/boost/task/launch.hpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -8,43 +8,44 @@
#define BOOST_TASK_LAUNCH_H
#include <boost/task/default_pool.hpp>
+#include <boost/task/handle.hpp>
#include <boost/task/pool.hpp>
#include <boost/task/task.hpp>
namespace boost { namespace task
{
template< typename R >
-void launch( task< R > t)
-{ get_default_pool().submit( t); }
+handle< R > launch( task< R > t)
+{ return get_default_pool().submit( t); }
template<
typename R,
typename Attr
>
-void launch(
+handle< R > launch(
task< R > t,
Attr const& attr)
-{ get_default_pool().submit( t, attr); }
+{ return get_default_pool().submit( t, attr); }
template<
typename Channel,
typename R
>
-void launch(
+handle< R > launch(
pool< Channel > & pool,
task< R > t)
-{ pool.submit( t); }
+{ return pool.submit( t); }
template<
typename Channel,
typename R,
typename Attr
>
-void launch(
+handle< R > launch(
pool< Channel > & pool,
task< R > t,
Attr const& attr)
-{ pool.submit( t, attr); }
+{ return pool.submit( t, attr); }
} }
#endif // BOOST_TASK_LAUNCH_H
Modified: sandbox/task/boost/task/pool.hpp
==============================================================================
--- sandbox/task/boost/task/pool.hpp (original)
+++ sandbox/task/boost/task/pool.hpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -25,6 +25,7 @@
#include <boost/task/detail/worker_group.hpp>
#include <boost/task/exceptions.hpp>
#include <boost/task/future.hpp>
+#include <boost/task/handle.hpp>
#include <boost/task/poolsize.hpp>
#include <boost/task/scanns.hpp>
#include <boost/task/task.hpp>
@@ -288,21 +289,23 @@
{ return channel_.lower_bound( lwm); }
template< typename R >
- void submit( task< R > t)
+ handle< R > submit( task< R > t)
{
+ shared_future< R > fut( t.impl_->prom.get_future() );
detail::worker * w( detail::worker::tss_get() );
if ( w)
{
function< bool() > wcb(
bind(
& shared_future< R >::is_ready,
- t.impl_->fut) );
+ fut) );
t.set_wait_callback(
bind(
( void ( detail::worker::*)( function< bool() > const&) ) & detail::worker::reschedule_until,
w,
wcb) );
w->put( detail::callable( t) );
+ return handle< R >( fut, t.impl_->intr);
}
else
{
@@ -310,6 +313,7 @@
throw task_rejected("pool is closed");
channel_.put( detail::callable( t) );
+ return handle< R >( fut, t.impl_->intr);
}
}
@@ -317,21 +321,23 @@
typename R,
typename Attr
>
- void submit( task< R > t, Attr const& attr)
+ handle< R > submit( task< R > t, Attr const& attr)
{
+ shared_future< R > fut( t.impl_->prom.get_future() );
detail::worker * w( detail::worker::tss_get() );
if ( w)
{
function< bool() > wcb(
bind(
& shared_future< R >::is_ready,
- t.impl_->fut) );
+ fut) );
t.set_wait_callback(
bind(
( void ( detail::worker::*)( function< bool() > const&) ) & detail::worker::reschedule_until,
w,
wcb) );
w->put( detail::callable( t) );
+ return handle< R >( fut, t.impl_->intr);
}
else
{
@@ -339,6 +345,7 @@
throw task_rejected("pool is closed");
channel_.put( channel_item( detail::callable( t), attr) );
+ return handle< R >( fut, t.impl_->intr);
}
}
};
Modified: sandbox/task/boost/task/task.hpp
==============================================================================
--- sandbox/task/boost/task/task.hpp (original)
+++ sandbox/task/boost/task/task.hpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -23,6 +23,7 @@
#include <boost/task/detail/interrupter.hpp>
#include <boost/task/exceptions.hpp>
#include <boost/task/future.hpp>
+#include <boost/task/handle.hpp>
namespace boost { namespace task
{
@@ -30,6 +31,7 @@
{
class callable;
}
+
template< typename Channel >
class pool;
@@ -40,38 +42,16 @@
template< typename Channel >
friend class pool;
friend class detail::callable;
- template< typename Iterator >
- friend void waitfor_all( Iterator begin, Iterator end);
- template< typename T1, typename T2 >
- friend void waitfor_all( T1 & t1, T2 & t2);
- template< typename T1, typename T2, typename T3 >
- friend void waitfor_all( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3);
- template< typename T1, typename T2, typename T3, typename T4 >
- friend void waitfor_all( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3, task< T4 > & t4);
- template< typename T1, typename T2, typename T3, typename T4, typename T5 >
- friend void waitfor_all( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3, task< T4 > & t4, task< T5 > & t5);
- template< typename Iterator >
- friend Iterator waitfor_any( Iterator begin, Iterator end);
- template< typename T1, typename T2 >
- friend unsigned int waitfor_any( task< T1 > & t1, task< T2 > & t2);
- template< typename T1, typename T2, typename T3 >
- friend unsigned int waitfor_any( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3);
- template< typename T1, typename T2, typename T3, typename T4 >
- friend unsigned int waitfor_any( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3, task< T4 > & t4);
- template< typename T1, typename T2, typename T3, typename T4, typename T5 >
- friend unsigned int waitfor_any( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3, task< T4 > & t4, task< T5 > & t5);
struct impl
{
promise< R > prom;
- shared_future< R > fut;
detail::interrupter intr;
exception_ptr excep;
impl()
:
prom(),
- fut( prom.get_future() ),
intr(),
excep()
{}
@@ -147,48 +127,6 @@
: impl_( new impl_wrapper< Fn >( fn) )
{}
- void interrupt()
- { impl_->intr.interrupt(); }
-
- void interrupt_and_wait()
- { impl_->intr.interrupt_and_wait(); }
-
- void interrupt_and_wait( system_time const& abs_time)
- { impl_->intr.interrupt_and_wait( abs_time); }
-
- template< typename Duration >
- void interrupt_and_wait( Duration const& rel_time)
- { impl_->intr.interrupt_and_wait( rel_time); }
-
- bool interruption_requested()
- { return impl_->intr.interruption_requested(); }
-
- R get()
- {
- if ( impl_->excep)
- rethrow_exception( impl_->excep);
- return impl_->fut.get();
- }
-
- bool is_ready() const
- { return impl_->fut.is_ready(); }
-
- bool has_value() const
- { return impl_->fut.has_value(); }
-
- bool has_exception() const
- { return impl_->excep ? true : impl_->fut.has_exception(); }
-
- void wait() const
- { impl_->fut.wait(); }
-
- template< typename Duration >
- bool timed_wait( Duration const& rel_time) const
- { return impl_->fut.timed_wait( rel_time); }
-
- bool timed_wait_until( system_time const& abs_time) const
- { return impl_->fut.timed_wait_until( abs_time); }
-
void swap( task< R > & other) // throw()
{ impl_.swap( other.impl_); }
@@ -207,38 +145,16 @@
template< typename Channel >
friend class pool;
friend class detail::callable;
- template< typename Iterator >
- friend void waitfor_all( Iterator begin, Iterator end);
- template< typename T1, typename T2 >
- friend void waitfor_all( T1 & t1, T2 & t2);
- template< typename T1, typename T2, typename T3 >
- friend void waitfor_all( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3);
- template< typename T1, typename T2, typename T3, typename T4 >
- friend void waitfor_all( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3, task< T4 > & t4);
- template< typename T1, typename T2, typename T3, typename T4, typename T5 >
- friend void waitfor_all( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3, task< T4 > & t4, task< T5 > & t5);
- template< typename Iterator >
- friend Iterator waitfor_any( Iterator begin, Iterator end);
- template< typename T1, typename T2 >
- friend unsigned int waitfor_any( task< T1 > & t1, task< T2 > & t2);
- template< typename T1, typename T2, typename T3 >
- friend unsigned int waitfor_any( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3);
- template< typename T1, typename T2, typename T3, typename T4 >
- friend unsigned int waitfor_any( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3, task< T4 > & t4);
- template< typename T1, typename T2, typename T3, typename T4, typename T5 >
- friend unsigned int waitfor_any( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3, task< T4 > & t4, task< T5 > & t5);
struct impl
{
promise< void > prom;
- shared_future< void > fut;
detail::interrupter intr;
exception_ptr excep;
impl()
:
prom(),
- fut( prom.get_future() ),
intr(),
excep()
{}
@@ -317,48 +233,6 @@
: impl_( new impl_wrapper< Fn >( fn) )
{}
- void interrupt()
- { impl_->intr.interrupt(); }
-
- void interrupt_and_wait()
- { impl_->intr.interrupt_and_wait(); }
-
- void interrupt_and_wait( system_time const& abs_time)
- { impl_->intr.interrupt_and_wait( abs_time); }
-
- template< typename Duration >
- void interrupt_and_wait( Duration const& rel_time)
- { impl_->intr.interrupt_and_wait( rel_time); }
-
- bool interruption_requested()
- { return impl_->intr.interruption_requested(); }
-
- void get()
- {
- if ( impl_->excep)
- rethrow_exception( impl_->excep);
- impl_->fut.get();
- }
-
- bool is_ready() const
- { return impl_->fut.is_ready(); }
-
- bool has_value() const
- { return impl_->fut.has_value(); }
-
- bool has_exception() const
- { return impl_->excep ? true : impl_->fut.has_exception(); }
-
- void wait() const
- { impl_->fut.wait(); }
-
- template< typename Duration >
- bool timed_wait( Duration const& rel_time) const
- { return impl_->fut.timed_wait( rel_time); }
-
- bool timed_wait_until( system_time const& abs_time) const
- { return impl_->fut.timed_wait_until( abs_time); }
-
void swap( task< void > & other) // throw()
{ impl_.swap( other.impl_); }
@@ -370,54 +244,6 @@
{ impl_->prom.set_wait_callback( f); }
};
-template< typename Iterator >
-void waitfor_all( Iterator begin, Iterator end)
-{
- for ( Iterator i = begin; i != end; ++i)
- i->wait();
-}
-
-template< typename T1, typename T2 >
-void waitfor_all( T1 & t1, T2 & t2)
-{ wait_for_all( t1.fut_, t2.fut_); }
-
-template< typename T1, typename T2, typename T3 >
-void waitfor_all( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3)
-{ wait_for_all( t1.fut_, t2.fut_, t3.fut_); }
-
-template< typename T1, typename T2, typename T3, typename T4 >
-void waitfor_all( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3, task< T4 > & t4)
-{ wait_for_all( t1.fut_, t2.fut_, t3.fut_, t4.fut_); }
-
-template< typename T1, typename T2, typename T3, typename T4, typename T5 >
-void waitfor_all( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3, task< T4 > & t4, task< T5 > & t5)
-{ wait_for_all( t1.fut_, t2.fut_, t3.fut_, t4.fut_, t5.fut_); }
-
-template< typename Iterator >
-Iterator waitfor_any( Iterator begin, Iterator end)
-{
- boost::detail::future_waiter waiter;
- for ( Iterator i = begin; i != end; ++i)
- waiter.add( i->fut_);
- return next( begin, waiter.wait() );
-}
-
-template< typename T1, typename T2 >
-unsigned int waitfor_any( task< T1 > & t1, task< T2 > & t2)
-{ return wait_for_any( t1.fut_, t2.fut_); }
-
-template< typename T1, typename T2, typename T3 >
-unsigned int waitfor_any( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3)
-{ return wait_for_any( t1.fut_, t2.fut_, t3.fut_); }
-
-template< typename T1, typename T2, typename T3, typename T4 >
-unsigned int waitfor_any( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3, task< T4 > & t4)
-{ return wait_for_any( t1.fut_, t2.fut_, t3.fut_, t4.fut_); }
-
-template< typename T1, typename T2, typename T3, typename T4, typename T5 >
-unsigned int waitfor_any( task< T1 > & t1, task< T2 > & t2, task< T3 > & t3, task< T4 > & t4, task< T5 > & t5)
-{ return wait_for_any( t1.fut_, t2.fut_, t3.fut_, t4.fut_, t5.fut_); }
-
template< typename Fn >
task< typename result_of< Fn() >::type > make_task( Fn fn)
{ return task< typename boost::result_of< Fn() >::type >( fn); }
Modified: sandbox/task/libs/task/examples/bind_to_processors.cpp
==============================================================================
--- sandbox/task/libs/task/examples/bind_to_processors.cpp (original)
+++ sandbox/task/libs/task/examples/bind_to_processors.cpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -42,23 +42,19 @@
if ( n < cutof_) return serial_fib( n);
else
{
- tsk::task< long > t1(
- tsk::make_task(
- & fib_task::execute,
- boost::ref( * this),
- n - 1) ) ;
- tsk::task< long > t2(
- tsk::make_task(
- & fib_task::execute,
- boost::ref( * this),
- n - 2) );
- tsk::launch(
- boost::this_task::get_pool< pool_type >(),
- t1);
- tsk::launch(
- boost::this_task::get_pool< pool_type >(),
- t2);
- return t1.get() + t2.get();
+ tsk::handle< long > h1(
+ tsk::launch(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 1) ) ) ;
+ tsk::handle< long > h2(
+ tsk::launch(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 2) ) );
+ return h1.get() + h2.get();
}
}
};
@@ -76,27 +72,24 @@
{
pool_type pool;
- std::vector< tsk::task< long > > results;
+ std::vector< tsk::handle< long > > results;
results.reserve( 20);
pt::ptime start( pt::microsec_clock::universal_time() );
for ( int i = 0; i < 26; ++i)
- {
- tsk::task< long > t(
- tsk::make_task(
- & parallel_fib,
- i) );
- results.push_back( t);
- tsk::launch( pool, t);
- }
+ results.push_back(
+ tsk::launch(
+ tsk::make_task(
+ & parallel_fib,
+ i) ) );
tsk::waitfor_all( results.begin(), results.end() );
int k = 0;
- std::vector< tsk::task< long > >::iterator e( results.end() );
+ std::vector< tsk::handle< long > >::iterator e( results.end() );
for (
- std::vector< tsk::task< long > >::iterator i( results.begin() );
+ std::vector< tsk::handle< long > >::iterator i( results.begin() );
i != e;
++i)
std::cout << "fibonacci " << k++ << " == " << i->get() << std::endl;
Modified: sandbox/task/libs/task/examples/delay.cpp
==============================================================================
--- sandbox/task/libs/task/examples/delay.cpp (original)
+++ sandbox/task/libs/task/examples/delay.cpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -45,19 +45,19 @@
}
else
{
- tsk::task< long > t1(
- tsk::make_task(
- & fib_task::execute,
- boost::ref( * this),
- n - 1) );
- tsk::task< long > t2(
- tsk::make_task(
- & fib_task::execute,
- boost::ref( * this),
- n - 2) );
- tsk::launch( t1);
- tsk::launch( t2);
- return t1.get() + t2.get();
+ tsk::handle< long > h1(
+ tsk::launch(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 1) ) );
+ tsk::handle< long > h2(
+ tsk::launch(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 2) ) );
+ return h1.get() + h2.get();
}
}
};
Modified: sandbox/task/libs/task/examples/fork_join.cpp
==============================================================================
--- sandbox/task/libs/task/examples/fork_join.cpp (original)
+++ sandbox/task/libs/task/examples/fork_join.cpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -42,23 +42,19 @@
if ( n < cutof_) return serial_fib( n);
else
{
- tsk::task< long > t1(
- tsk::make_task(
- & fib_task::execute,
- boost::ref( * this),
- n - 1) );
- tsk::task< long > t2(
- tsk::make_task(
- & fib_task::execute,
- boost::ref( * this),
- n - 2) );
- tsk::launch(
- boost::this_task::get_pool< pool_type >(),
- t1);
- tsk::launch(
- boost::this_task::get_pool< pool_type >(),
- t2);
- return t1.get() + t2.get();
+ tsk::handle< long > h1(
+ tsk::launch(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 1) ) );
+ tsk::handle< long > h2(
+ tsk::launch(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 2) ) );
+ return h1.get() + h2.get();
}
}
};
@@ -75,27 +71,24 @@
{
pool_type pool( tsk::poolsize( 5) );
- std::vector< tsk::task< long > > results;
+ std::vector< tsk::handle< long > > results;
results.reserve( 20);
pt::ptime start( pt::microsec_clock::universal_time() );
for ( int i = 0; i < 26; ++i)
- {
- tsk::task< long > t(
- tsk::make_task(
- & parallel_fib,
- i) );
- results.push_back( t);
- tsk::launch( pool, t);
- }
+ results.push_back(
+ tsk::launch(
+ tsk::make_task(
+ & parallel_fib,
+ i) ) );
tsk::waitfor_all( results.begin(), results.end() );
int k = 0;
- std::vector< tsk::task< long > >::iterator e( results.end() );
+ std::vector< tsk::handle< long > >::iterator e( results.end() );
for (
- std::vector< tsk::task< long > >::iterator i( results.begin() );
+ std::vector< tsk::handle< long > >::iterator i( results.begin() );
i != e;
++i)
std::cout << "fibonacci " << k++ << " == " << i->get() << std::endl;
Modified: sandbox/task/libs/task/examples/interrupt.cpp
==============================================================================
--- sandbox/task/libs/task/examples/interrupt.cpp (original)
+++ sandbox/task/libs/task/examples/interrupt.cpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -48,13 +48,13 @@
std::cout << "poolsize == " << tsk::get_default_pool().size() << std::endl;
std::cout << "idle threads == " << tsk::get_default_pool().idle() << std::endl;
std::cout << "active threads == " << tsk::get_default_pool().active() << std::endl;
- tsk::task< int > t(
- tsk::make_task(
- fibonacci_fn,
- 10) );
- tsk::launch( t);
- t.interrupt();
- std::cout << t.get() << std::endl;
+ tsk::handle< int > h(
+ tsk::launch(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ h.interrupt();
+ std::cout << h.get() << std::endl;
return EXIT_SUCCESS;
}
Modified: sandbox/task/libs/task/examples/pending.cpp
==============================================================================
--- sandbox/task/libs/task/examples/pending.cpp (original)
+++ sandbox/task/libs/task/examples/pending.cpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -43,16 +43,16 @@
{
try
{
- tsk::task< int > t(
- tsk::make_task(
- fibonacci_fn,
- 10) );
tsk::launch(
tsk::make_task(
long_running_fn) );
- tsk::launch( t);
+ tsk::handle< int > h(
+ tsk::launch(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
std::cout << "pending tasks == " << tsk::get_default_pool().pending() << std::endl;
- std::cout << t.get() << std::endl;
+ std::cout << h.get() << std::endl;
return EXIT_SUCCESS;
}
Modified: sandbox/task/libs/task/examples/reschedule_until.cpp
==============================================================================
--- sandbox/task/libs/task/examples/reschedule_until.cpp (original)
+++ sandbox/task/libs/task/examples/reschedule_until.cpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -51,19 +51,19 @@
if ( n < cutof_) return serial_fib( n);
else
{
- tsk::task< long > t1(
- tsk::make_task(
- & fib_task::execute,
- boost::ref( * this),
- n - 1) );
- tsk::task< long > t2(
- tsk::make_task(
- & fib_task::execute,
- boost::ref( * this),
- n - 2) );
- tsk::launch( t1);
- tsk::launch( t2);
- return t1.get() + t2.get();
+ tsk::handle< long > h1(
+ tsk::launch(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 1) ) );
+ tsk::handle< long > h2(
+ tsk::launch(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 2) ) );
+ return h1.get() + h2.get();
}
}
};
Modified: sandbox/task/libs/task/examples/shutdonw_now.cpp
==============================================================================
--- sandbox/task/libs/task/examples/shutdonw_now.cpp (original)
+++ sandbox/task/libs/task/examples/shutdonw_now.cpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -44,17 +44,18 @@
tsk::unbounded_channel< tsk::fifo >
> pool( tsk::poolsize( 1) );
- tsk::task< int > t(
- tsk::make_task(
- fibonacci_fn,
- 10) );
- tsk::launch( pool, t);
+ tsk::handle< int > h(
+ tsk::launch(
+ pool,
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
boost::this_thread::sleep( pt::milliseconds( 250) );
pool.shutdown_now();
- std::cout << t.get() << std::endl;
+ std::cout << h.get() << std::endl;
return EXIT_SUCCESS;
}
Modified: sandbox/task/libs/task/examples/submit.cpp
==============================================================================
--- sandbox/task/libs/task/examples/submit.cpp (original)
+++ sandbox/task/libs/task/examples/submit.cpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -35,18 +35,12 @@
{
try
{
- tsk::task< int > t1(
- tsk::make_task(
- fibonacci_fn,
- 10) );
- tsk::task< int > t2(
- tsk::make_task(
- fibonacci_fn,
- 10) );
- tsk::launch( t1);
- t2();
- std::cout << t1.get() << std::endl;
- std::cout << t2.get() << std::endl;
+ tsk::handle< int > h(
+ tsk::launch(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ std::cout << h.get() << std::endl;
return EXIT_SUCCESS;
}
Modified: sandbox/task/libs/task/examples/yield.cpp
==============================================================================
--- sandbox/task/libs/task/examples/yield.cpp (original)
+++ sandbox/task/libs/task/examples/yield.cpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -46,27 +46,19 @@
return serial_fib( n);
else
{
- tsk::task< long > t1(
- tsk::make_task(
- & fib_task::execute,
- boost::ref( * this),
- n - 1) );
- tsk::task< long > t2(
- tsk::make_task(
- & fib_task::execute,
- boost::ref( * this),
- n - 2) );
- if ( boost::this_task::runs_in_pool() )
- {
- tsk::launch( t1);
- tsk::launch( t2);
- }
- else
- {
- t1();
- t2();
- }
- return t1.get() + t2.get();
+ tsk::handle< long > h1(
+ tsk::launch(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 1) ) );
+ tsk::handle< long > h2(
+ tsk::launch(
+ tsk::make_task(
+ & fib_task::execute,
+ boost::ref( * this),
+ n - 2) ) );
+ return h1.get() + h2.get();
}
}
};
Modified: sandbox/task/libs/task/src/wsq.cpp
==============================================================================
--- sandbox/task/libs/task/src/wsq.cpp (original)
+++ sandbox/task/libs/task/src/wsq.cpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -71,7 +71,7 @@
if ( tail == 0)
return false;
tail -= 1;
- atomic_write_32( & tail_idx_, tail); // Interlocked.Exchange( & tail_idx_, tail); -> XCHG
+ atomic_exchange( & tail_idx_, tail); // Interlocked.Exchange( & tail_idx_, tail); -> XCHG
if ( head_idx_ <= tail)
{
ca = array_[tail & mask_];
@@ -100,7 +100,7 @@
if ( lk.owns_lock() )
{
uint32_t head( head_idx_);
- atomic_write_32( & head_idx_, head + 1); // Interlocked.Exchange( & head_idx_, head + 1);
+ atomic_exchange( & head_idx_, head + 1); // Interlocked.Exchange( & head_idx_, head + 1);
if ( head < tail_idx_)
{
ca = array_[head & mask_];
Modified: sandbox/task/libs/task/test/test_launch.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_launch.cpp (original)
+++ sandbox/task/libs/task/test/test_launch.cpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -32,12 +32,12 @@
// launch in default pool
void test_case_1()
{
- tsk::task< int > t(
- tsk::make_task(
- fibonacci_fn,
- 10) );
- tsk::launch( t);
- BOOST_CHECK_EQUAL( t.get(), 55);
+ tsk::handle< int > h(
+ tsk::launch(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
}
// launch in custom pool
@@ -46,12 +46,13 @@
tsk::pool<
tsk::unbounded_channel< tsk::fifo >
> pool( tsk::poolsize( 1) );
- tsk::task< int > t(
- tsk::make_task(
- fibonacci_fn,
- 10) );
- tsk::launch( pool, t);
- BOOST_CHECK_EQUAL( t.get(), 55);
+ tsk::handle< int > h(
+ tsk::launch(
+ pool,
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
}
// launch in current thread
@@ -86,11 +87,11 @@
// check runs in pool
void test_case_5()
{
- tsk::task< bool > t(
- tsk::make_task(
- runs_in_pool_fn) );
- tsk::launch( t);
- BOOST_CHECK_EQUAL( t.get(), true);
+ tsk::handle< bool > h(
+ tsk::launch(
+ tsk::make_task(
+ runs_in_pool_fn) ) );
+ BOOST_CHECK_EQUAL( h.get(), true);
}
// check runs not in pool
Modified: sandbox/task/libs/task/test/test_pool_bounded_channel.cpp
==============================================================================
--- sandbox/task/libs/task/test/test_pool_bounded_channel.cpp (original)
+++ sandbox/task/libs/task/test/test_pool_bounded_channel.cpp 2009-04-19 14:40:31 EDT (Sun, 19 Apr 2009)
@@ -52,12 +52,12 @@
tsk::poolsize( 1),
tsk::high_watermark( 10),
tsk::low_watermark( 10) );
- tsk::task< int > t(
- tsk::make_task(
+ tsk::handle< int > h(
+ pool.submit(
+ tsk::make_task(
fibonacci_fn,
- 10) );
- pool.submit( t);
- BOOST_CHECK_EQUAL( t.get(), 55);
+ 10) ) );
+ BOOST_CHECK_EQUAL( h.get(), 55);
}
// check shutdown
@@ -69,14 +69,14 @@
tsk::poolsize( 1),
tsk::high_watermark( 10),
tsk::low_watermark( 10) );
- tsk::task< int > t(
- tsk::make_task(
- fibonacci_fn,
- 10) );
- pool.submit( t);
+ tsk::handle< int > h(
+ pool.submit(
+ tsk::make_task(
+ fibonacci_fn,
+ 10) ) );
pool.shutdown();
BOOST_CHECK( pool.closed() );
- BOOST_CHECK_EQUAL( t.get(), 55);
+ BOOST_CHECK_EQUAL( h.get(), 55);
}
// check runtime_error throw inside task
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