Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r50592 - sandbox/interthreads/boost/interthreads
From: vicente.botet_at_[hidden]
Date: 2009-01-14 12:54:42


Author: viboes
Date: 2009-01-14 12:54:41 EST (Wed, 14 Jan 2009)
New Revision: 50592
URL: http://svn.boost.org/trac/boost/changeset/50592

Log:
interthreads version 0.2
Adding threader/joiner
Adding Asynchronous Executors fmk
Added:
   sandbox/interthreads/boost/interthreads/asynchronous_executor_decorator.hpp (contents, props changed)
   sandbox/interthreads/boost/interthreads/basic_threader_decorator.hpp (contents, props changed)
   sandbox/interthreads/boost/interthreads/scheduler.hpp (contents, props changed)
   sandbox/interthreads/boost/interthreads/thread_decoration.hpp (contents, props changed)
   sandbox/interthreads/boost/interthreads/threader_decorator.hpp (contents, props changed)
Text files modified:
   sandbox/interthreads/boost/interthreads/basic_threader.hpp | 3
   sandbox/interthreads/boost/interthreads/fork.hpp | 17 +++
   sandbox/interthreads/boost/interthreads/fork_all.hpp | 4
   sandbox/interthreads/boost/interthreads/launcher.hpp | 17 --
   sandbox/interthreads/boost/interthreads/thread_decorator.hpp | 195 +++++++++------------------------------
   sandbox/interthreads/boost/interthreads/threader.hpp | 35 ++----
   sandbox/interthreads/boost/interthreads/wait_for_all.hpp | 25 +++--
   sandbox/interthreads/boost/interthreads/wait_for_any.hpp | 162 ++++++++++++++++++++++++++-------
   8 files changed, 221 insertions(+), 237 deletions(-)

Added: sandbox/interthreads/boost/interthreads/asynchronous_executor_decorator.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/asynchronous_executor_decorator.hpp 2009-01-14 12:54:41 EST (Wed, 14 Jan 2009)
@@ -0,0 +1,76 @@
+#ifndef BOOST_INTERTHREADS_ASYNCHRONOUS_EXECUTOR_DECORATOR__HPP
+#define BOOST_INTERTHREADS_ASYNCHRONOUS_EXECUTOR_DECORATOR__HPP
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-20009.
+// 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)
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/utility/result_of.hpp>
+
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace interthreads {
+
+ template <typename AE, template <class> class Decorator>
+ struct asynchronous_executor_decorator : AE {
+ template <typename F>
+ typename AE::template handle< typename boost::result_of<F()>::type >::type
+ fork( F fn ) {
+ typename result_of::fork<AE, F>::type act= this->AE::fork(Decorator<typename boost::result_of<F()>::type>(fn));
+ return boost::move(act);
+ }
+
+ asynchronous_executor_decorator() :AE() {};
+
+ template <typename Nullary>
+#ifdef BOOST_THREAD_HAS_THREAD_ATTR
+ asynchronous_executor_decorator(thread::native_handle_attr_type& attr, Nullary f)
+ : AE(attr, f)
+#else
+ asynchronous_executor_decorator(Nullary f)
+ : AE(f)
+#endif
+ {}
+
+ // move support
+#ifdef BOOST_HAS_RVALUE_REFS
+#else
+ asynchronous_executor_decorator(boost::detail::thread_move_t<asynchronous_executor_decorator> x)
+ : AE(boost::move(*(static_cast<AE*>(&(x.member))))) {}
+
+ asynchronous_executor_decorator& operator=(boost::detail::thread_move_t<asynchronous_executor_decorator> x) {
+ return move();
+ }
+
+ operator boost::detail::thread_move_t<asynchronous_executor_decorator>() {
+ return move();
+ }
+
+ boost::detail::thread_move_t<asynchronous_executor_decorator> move() {
+ return boost::detail::thread_move_t<asynchronous_executor_decorator>(*this);
+ }
+
+#endif
+
+
+ };
+
+ //typedef asynchronous_executor_decorator<threader,thread_decorator> threader_decorator;
+
+}
+}
+
+#include <boost/config/abi_suffix.hpp>
+
+
+#endif
+

Modified: sandbox/interthreads/boost/interthreads/basic_threader.hpp
==============================================================================
--- sandbox/interthreads/boost/interthreads/basic_threader.hpp (original)
+++ sandbox/interthreads/boost/interthreads/basic_threader.hpp 2009-01-14 12:54:41 EST (Wed, 14 Jan 2009)
@@ -51,7 +51,8 @@
 #else
         thread th(f);
 #endif
- return thread(detail::thread_move_t<thread>(th));
+ return boost::move(th);
+ //return thread(boost::detail::thread_move_t<thread>(th));
     }
 };
 

Added: sandbox/interthreads/boost/interthreads/basic_threader_decorator.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/basic_threader_decorator.hpp 2009-01-14 12:54:41 EST (Wed, 14 Jan 2009)
@@ -0,0 +1,38 @@
+#ifndef BOOST_INTERTHREADS_BASIC_THREADER_DECORATOR__HPP
+#define BOOST_INTERTHREADS_BASIC_THREADER_DECORATOR__HPP
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Roland Schwarz 2006.
+// (C) Copyright Vicente J. Botet Escriba 2008-20009.
+// 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)
+//
+// Extension of the init class of the threadalert library of Roland Schwarz
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/interthreads/asynchronous_executor_decorator.hpp>
+#include <boost/interthreads/thread_decorator.hpp>
+#include <boost/interthreads/basic_threader.hpp>
+
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace interthreads {
+
+
+ typedef asynchronous_executor_decorator<basic_threader,thread_decorator> basic_threader_decorator;
+
+}
+}
+
+#include <boost/config/abi_suffix.hpp>
+
+
+#endif
+

Modified: sandbox/interthreads/boost/interthreads/fork.hpp
==============================================================================
--- sandbox/interthreads/boost/interthreads/fork.hpp (original)
+++ sandbox/interthreads/boost/interthreads/fork.hpp 2009-01-14 12:54:41 EST (Wed, 14 Jan 2009)
@@ -38,13 +38,26 @@
     };
 }
 
+//template <typename AE>
+//struct get_future;
 template <typename AE>
-struct get_future;
+struct get_future {
+ template <typename T>
+ shared_future<T>& operator()(typename asynchronous_completion_token<AE,T>::type& act) { return act.get_future(); }
+};
+
+
+template< typename AE, typename F >
+struct fork_aux {
+ static typename result_of::fork<AE,F>::type fork(AE& ae, F fn ) {
+ return ae.fork(fn);
+ }
+};
 
 template< typename AE, typename F >
 typename result_of::fork<AE,F>::type
 fork( AE& ae, F fn ) {
- return ae.fork(fn);
+ return fork_aux<AE,F>::fork(ae,fn);
 }
 
 template< typename AE, typename F, typename A1 >

Modified: sandbox/interthreads/boost/interthreads/fork_all.hpp
==============================================================================
--- sandbox/interthreads/boost/interthreads/fork_all.hpp (original)
+++ sandbox/interthreads/boost/interthreads/fork_all.hpp 2009-01-14 12:54:41 EST (Wed, 14 Jan 2009)
@@ -14,7 +14,7 @@
 //
 //////////////////////////////////////////////////////////////////////////////
 
-//#include <boost/interthreads/fork.hpp>
+#include <boost/interthreads/fork.hpp>
 #include <boost/thread/detail/move.hpp>
 #include <boost/fusion/include/tuple.hpp>
 #include <boost/utility/result_of.hpp>
@@ -54,7 +54,7 @@
     typedef typename result_of::fork_all<AE, fusion::tuple<F1,F2> >::type type;
     typename result_of::fork<AE, F1>::type j1 =ae.fork(f1);
     typename result_of::fork<AE, F2>::type j2 =ae.fork(f2);
- return type(j1.move(),j2.move());
+ return type(j1,j2);
 }
 
 template< typename AE, typename F1, typename F2, typename F3>

Modified: sandbox/interthreads/boost/interthreads/launcher.hpp
==============================================================================
--- sandbox/interthreads/boost/interthreads/launcher.hpp (original)
+++ sandbox/interthreads/boost/interthreads/launcher.hpp 2009-01-14 12:54:41 EST (Wed, 14 Jan 2009)
@@ -14,10 +14,9 @@
 //
 //////////////////////////////////////////////////////////////////////////////
 
-#include <boost/interthreads/detail/config.hpp>
+//#include <boost/interthreads/detail/config.hpp>
 #include <boost/thread/detail/move.hpp>
 #include <boost/thread/thread.hpp>
-//#include <boost/tuple/tuple.hpp>
 #include <boost/futures/future.hpp>
 #include <boost/utility/result_of.hpp>
 
@@ -57,11 +56,7 @@
 #else
         thread th(boost::move(tsk));
 #endif
- //detail::thread_move_t<boost::unique_future<result_type> > resm(res);
- //return res;
- return unique_future<result_type>(detail::thread_move_t<unique_future<result_type> >(res));
-
- //return detail::thread_move_t<boost::unique_future<result_type> >(res);
+ return boost::move(res);
     }
 };
 
@@ -87,17 +82,13 @@
     fork(F f) {
         typedef typename boost::result_of<F()>::type result_type;
         packaged_task<result_type> tsk(f);
- shared_future<result_type> res = tsk.get_future();
+ shared_future<result_type> res(tsk.get_future());
 #ifdef BOOST_THREAD_HAS_THREAD_ATTR
         thread th(attr(), boost::move(tsk));
 #else
         thread th(boost::move(tsk));
 #endif
- //detail::thread_move_t<boost::unique_future<result_type> > resm(res);
- //return res;
- return shared_future<result_type>(detail::thread_move_t<shared_future<result_type> >(res));
-
- //return detail::thread_move_t<boost::unique_future<result_type> >(res);
+ return res;
     }
 };
 

Added: sandbox/interthreads/boost/interthreads/scheduler.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/scheduler.hpp 2009-01-14 12:54:41 EST (Wed, 14 Jan 2009)
@@ -0,0 +1,92 @@
+#ifndef BOOST_INTERTHREADS_SCHEDULER__HPP
+#define BOOST_INTERTHREADS_SCHEDULER__HPP
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-20009.
+// 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)
+//
+// Based on the unique_threader/unique_joiner design from of Kevlin Henney (n1883)
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/thread/detail/move.hpp>
+#include <boost/thread/condition_variable.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/thread/tss.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/bind.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/tp/pool.hpp>
+#include <boost/futures/future.hpp>
+#include <boost/utility/result_of.hpp>
+
+#include <boost/interthreads/fork.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+
+namespace boost {
+namespace interthreads {
+
+
+template <typename C>
+class scheduler {
+ tp::pool<C> _pool;
+public:
+ explicit scheduler(
+ tp::poolsize const& psize
+ ) : _pool(psize)
+ {};
+ template <typename T>
+ struct handle {
+ typedef tp::task<T> type;
+ };
+ template <typename F>
+ tp::task<typename boost::result_of<F()>::type>
+ fork(F f) {
+ return _pool.submit(f);
+ }
+
+};
+
+template <typename Channel>
+struct get_future<scheduler<Channel> > {
+ template <typename T>
+ shared_future<T>& operator()(tp::task<T>& act) { return act.get_future(); }
+};
+
+
+
+template <typename Channel, typename T>
+struct asynchronous_completion_token<boost::tp::pool<Channel>,T> {
+ typedef boost::tp::task<T> type;
+};
+
+
+template< typename Channel, typename F >
+struct fork_aux<boost::tp::pool<Channel>,F> {
+ typename result_of::fork<boost::tp::pool<Channel>, F>::type
+ fork( boost::tp::pool<Channel>& ae, F fn ) {
+ return ae.submit(fn);
+ }
+};
+
+template <typename C>
+struct get_future<tp::pool<C> > {
+ template <typename T>
+ shared_future<T>& operator()(tp::task<T>& act) { return act.get_future(); }
+};
+
+}
+}
+
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif
+

Added: sandbox/interthreads/boost/interthreads/thread_decoration.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/thread_decoration.hpp 2009-01-14 12:54:41 EST (Wed, 14 Jan 2009)
@@ -0,0 +1,78 @@
+#ifndef BOOST_INTERTHREADS_THREAD_DECORATION__HPP
+#define BOOST_INTERTHREADS_THREAD_DECORATION__HPP
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Roland Schwarz 2006.
+// (C) Copyright Vicente J. Botet Escriba 2008-20009.
+// 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)
+//
+// Extension of the init class of the threadalert library of Roland Schwarz
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/interthreads/detail/config.hpp>
+#include <boost/thread/detail/move.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+#include <boost/utility/result_of.hpp>
+#include <boost/interthreads/detail/decorator_function.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace interthreads {
+ class thread_decoration {
+ thread_decoration();
+ thread_decoration(const thread_decoration&);
+ public:
+ template<typename Callable1>
+ thread_decoration(Callable1 setup)
+ : setup_(new detail::decorator_function<Callable1>(setup))
+ , cleanup_(0)
+ , prev_(last_) {
+ // the constructor is not thread-safe so it must only be used on
+ // global objects which are constructed before any threads
+ last_ = this;
+ }
+
+ template<typename Callable1,typename Callable2>
+ thread_decoration(Callable1 setup, Callable2 cleanup)
+ : setup_(new detail::decorator_function<Callable1>(setup))
+// , cleanup_(new detail::decorator_function<Callable2>(cleanup))
+ , cleanup_(cleanup)
+ , prev_(last_) {
+ // the constructor is not thread-safe so it must only be used on
+ // global objects which are constructed before any threads
+ last_ = this;
+ }
+
+ ~thread_decoration() {
+ delete setup_;
+ }
+ static void BOOST_INTERTHREADS_DECL decorate();
+
+ private:
+ template <typename T>
+ friend class basic_thread_decorator;
+ detail::decorator_function_base<void>* setup_;
+ boost::function<void ()> cleanup_;
+ static thread_decoration* last_;
+ thread_decoration* prev_;
+ };
+
+
+}
+}
+
+#include <boost/config/abi_suffix.hpp>
+
+
+#endif
+

Modified: sandbox/interthreads/boost/interthreads/thread_decorator.hpp
==============================================================================
--- sandbox/interthreads/boost/interthreads/thread_decorator.hpp (original)
+++ sandbox/interthreads/boost/interthreads/thread_decorator.hpp 2009-01-14 12:54:41 EST (Wed, 14 Jan 2009)
@@ -22,6 +22,8 @@
 #include <boost/bind.hpp>
 #include <boost/function.hpp>
 #include <boost/utility/result_of.hpp>
+#include <boost/interthreads/detail/decorator_function.hpp>
+#include <boost/interthreads/thread_decoration.hpp>
 
 //#define BOOST_INTERTHREADS_THREAD_DECORATOR_MOVE
 
@@ -29,122 +31,22 @@
 
 namespace boost {
 namespace interthreads {
-
- namespace detail {
- struct decorator_function_base {
- virtual ~decorator_function_base() {}
- virtual void operator()() const=0;
- };
-
- template<typename F>
- struct BOOST_INTERTHREADS_DECL decorator_function : decorator_function_base {
- F f;
-#ifdef BOOST_INTERTHREADS_THREAD_DECORATION_MOVE
-#ifdef BOOST_HAS_RVALUE_REFS
- decorator_function(F&& f_):
- f(static_cast<F&&>(f_))
- {}
-#else
- decorator_function(F f_): f(f_) {}
- decorator_function(boost::detail::thread_move_t<F> f_): f(f_) {}
-#endif
-#else
- decorator_function(F f_): f(f_) {}
-#endif
-
- void operator()() const {
- f();
- }
- private:
-// void operator=(decorator_function&);
- decorator_function();
-// decorator_function(decorator_function&);
-
- };
-
-#ifdef BOOST_INTERTHREADS_THREAD_DECORATOR_MOVE
-#ifdef BOOST_HAS_RVALUE_REFS
- template<typename F>
- static inline boost::shared_ptr<decorator_function_base> make_decorator_function(F&& f)
- {
- return boost::shared_ptr<decorator_function_base>(
- new decorator_function<typename boost::remove_reference<F>::type> >(static_cast<F&&>(f)));
- }
- static inline boost::shared_ptr<decorator_function_base> make_decorator_function(void (*f)())
- {
- return boost::shared_ptr<decorator_function_base>(new decorator_function<void(*)()> >(f));
- }
-#else
- struct dummy;
+ inline void decorate();
 
- template<typename F>
- static inline boost::shared_ptr<decorator_function_base> make_decorator_function(F f)
- {
- return boost::shared_ptr<decorator_function_base>(new decorator_function<F>(f));
- }
- template<typename F>
- static inline boost::shared_ptr<decorator_function_base> make_decorator_function(boost::detail::thread_move_t<F> f)
- {
- return boost::shared_ptr<decorator_function_base>(new decorator_function<F>(f));
- }
-#endif
-#else
- template<typename F>
- static inline boost::shared_ptr<decorator_function_base> make_decorator_function(F f)
- {
- return boost::shared_ptr<decorator_function_base>(new decorator_function<F>(f));
- }
-
-#endif
- }
- class thread_decoration {
- thread_decoration();
- thread_decoration(const thread_decoration&);
+ template <typename T>
+ class basic_thread_decorator {
     public:
- template<typename Callable1>
- thread_decoration(Callable1 setup)
- : setup_(new detail::decorator_function<Callable1>(setup))
- , cleanup_(0)
- , prev_(last_) {
- // the constructor is not thread-safe so it must only be used on
- // global objects which are constructed before any threads
- last_ = this;
- }
-
- template<typename Callable1,typename Callable2>
- thread_decoration(Callable1 setup, Callable2 cleanup)
- : setup_(new detail::decorator_function<Callable1>(setup))
-// , cleanup_(new detail::decorator_function<Callable2>(cleanup))
- , cleanup_(cleanup)
- , prev_(last_) {
- // the constructor is not thread-safe so it must only be used on
- // global objects which are constructed before any threads
- last_ = this;
- }
-
- ~thread_decoration() {
- delete setup_;
- }
- static void BOOST_INTERTHREADS_DECL decorate();
-
- private:
- friend class thread_decorator;
- detail::decorator_function_base* setup_;
- boost::function<void ()> cleanup_;
- static thread_decoration* last_;
- thread_decoration* prev_;
- };
+ typedef T result_type;
 
- class thread_decorator {
- public:
         // copy/constructor operators (functor)
- thread_decorator() {}
- thread_decorator(const thread_decorator& other) {
+ basic_thread_decorator() {}
+ ~basic_thread_decorator() {}
+ basic_thread_decorator(const basic_thread_decorator& other) {
             func_ =other.func_;
         }
         
- thread_decorator& operator=(const thread_decorator& other) {
- thread_decorator tmp(other);
+ basic_thread_decorator& operator=(const basic_thread_decorator& other) {
+ basic_thread_decorator tmp(other);
             tmp.swap(*this);
             return *this;
         }
@@ -152,109 +54,114 @@
 #if defined(BOOST_HAS_VARIADIC_TMPL)
 #if defined(BOOST_HAS_RVALUE_REFS)
         template <typename Callable, typename Arg...>
- explicit thread_decorator(Callable&& f, ...Arg&& args)
+ explicit basic_thread_decorator(Callable&& f, ...Arg&& args)
             : func_(detail::make_decorator_function(boost::bind(boost::type<void>(),static_cast<F&&>(f),...args))) {};
 #else
         template <typename Callable, typename Arg...>
- explicit thread_decorator(Callable f, ...Arg args)
+ explicit basic_thread_decorator(Callable f, ...Arg args)
             : func_(detail::make_decorator_function(boost::bind(boost::type<void>(),f,...args))) {};
 #endif
 #else // !defined(BOOST_HAS_VARIADIC_TMPL)
 #if defined(BOOST_HAS_RVALUE_REFS)
         template <typename Callable>
- explicit thread_decorator(Callable&& f)
+ explicit basic_thread_decorator(Callable&& f)
             : func_(detail::make_decorator_function(static_cast<F&&>(f))) {};
 #else // !defined(BOOST_HAS_RVALUE_REFS)
 #ifdef BOOST_INTERTHREADS_THREAD_DECORATOR_MOVE
 #ifndef BOOST_NO_SFINAE
         template <class Callable>
- explicit thread_decorator(Callable f): func_(detail::make_decorator_function(f)) {}
+ explicit basic_thread_decorator(Callable f): func_(detail::make_decorator_function(f)) {}
 #else // BOOST_NO_SFINAE
         template <class Callable>
- explicit thread_decorator(Callable f
+ explicit basic_thread_decorator(Callable f
             ,typename disable_if<boost::is_convertible<F&,boost::detail::thread_move_t<F> >, detail::dummy* >::type=0)
             : func_(detail::make_decorator_function(f)) {}
 #endif // BOOST_NO_SFINAE
         template <class Callable>
- explicit thread_decorator(boost::detail::thread_move_t<Callable> f):
+ explicit basic_thread_decorator(boost::detail::thread_move_t<Callable> f):
             func_(detail::make_decorator_function(f)) {}
 #else // ! BOOST_INTERTHREADS_THREAD_DECORATOR_MOVE
         template <class Callable>
- explicit thread_decorator(Callable f): func_(detail::make_decorator_function(f)) {}
+ explicit basic_thread_decorator(Callable f): func_(detail::make_decorator_function(f)) {}
 #endif // ! BOOST_INTERTHREADS_THREAD_DECORATOR_MOVE
             
                 
         template <typename Callable, typename A1>
- thread_decorator(Callable f, A1 a1)
+ basic_thread_decorator(Callable f, A1 a1)
             : func_(detail::make_decorator_function(boost::bind(boost::type<void>(),f,a1))) {};
                 
         template <typename Callable, typename A1, typename A2>
- thread_decorator(Callable f, A1 a1, A2 a2)
+ basic_thread_decorator(Callable f, A1 a1, A2 a2)
             : func_(detail::make_decorator_function(boost::bind(boost::type<void>(),f,a1,a2))) {};
                 
         template <typename Callable, typename A1, typename A2, typename A3>
- thread_decorator(Callable f, A1 a1, A2 a2, A3 a3)
+ basic_thread_decorator(Callable f, A1 a1, A2 a2, A3 a3)
             : func_(detail::make_decorator_function(boost::bind(boost::type<void>(),f,a1,a2,a3))) {};
                 
         template <typename Callable, typename A1, typename A2, typename A3, typename A4>
- thread_decorator(Callable f, A1 a1, A2 a2, A3 a3, A4 a4)
+ basic_thread_decorator(Callable f, A1 a1, A2 a2, A3 a3, A4 a4)
             : func_(detail::make_decorator_function(boost::bind(boost::type<void>(),f,a1,a2,a3,a4))) {};
 #endif
 #endif
         // move semantics
 #if defined(BOOST_HAS_RVALUE_REFS)
- thread_decorator(thread_decorator&& other) {
+ basic_thread_decorator(basic_thread_decorator&& other) {
             func_.swap(other.func_);
         }
         
- thread_decorator& operator=(thread_decorator&& other) {
+ basic_thread_decorator& operator=(basic_thread_decorator&& other) {
             func_=other.func_;
             other.func_.reset();
             return *this;
         }
 
- thread_decorator&& move() {
- return static_cast<thread_decorator&&>(*this);
+ basic_thread_decorator&& move() {
+ return static_cast<basic_thread_decorator&&>(*this);
         }
         
 #else // ! defined(BOOST_HAS_RVALUE_REFS)
 #ifdef BOOST_INTERTHREADS_THREAD_DECORATOR_MOVE
- thread_decorator(boost::detail::thread_move_t<thread_decorator> x) {
+ basic_thread_decorator(boost::detail::thread_move_t<basic_thread_decorator> x) {
             func_=x->func_;
             x->func_.reset();
         }
         
- thread_decorator& operator=(boost::detail::thread_move_t<thread_decorator> x) {
- thread_decorator new_decorator(x);
+ basic_thread_decorator& operator=(boost::detail::thread_move_t<basic_thread_decorator> x) {
+ basic_thread_decorator new_decorator(x);
             swap(new_decorator);
             return *this;
         }
         
- operator boost::detail::thread_move_t<thread_decorator>() {
+ operator boost::detail::thread_move_t<basic_thread_decorator>() {
             return move();
         }
         
- boost::detail::thread_move_t<thread_decorator> move() {
- boost::detail::thread_move_t<thread_decorator> x(*this);
+ boost::detail::thread_move_t<basic_thread_decorator> move() {
+ boost::detail::thread_move_t<basic_thread_decorator> x(*this);
             return x;
         }
 #endif // ! BOOST_INTERTHREADS_THREAD_DECORATOR_MOVE
 #endif // ! defined(BOOST_HAS_RVALUE_REFS)
 
- void swap(thread_decorator& x) {
+ void swap(basic_thread_decorator& x) {
             func_.swap(x.func_);
         }
- void operator()() const;
+ T operator()() const {
+ decorate();
+ return (*func_)();
+ }
     private:
- boost::shared_ptr<detail::decorator_function_base> func_;
+ boost::shared_ptr<detail::decorator_function_base<T> > func_;
     };
  
+ typedef basic_thread_decorator<void> thread_decorator;
+
     template <class F>
- thread_decorator make_decorator(F f) {
+ basic_thread_decorator<typename boost::result_of<F()>::type> make_decorator(F f) {
 #ifdef BOOST_INTERTHREADS_THREAD_DECORATOR_MOVE
- return move(thread_decorator(f));
+ return move(basic_thread_decorator<typename boost::result_of<F()>::type>(f));
 #else
- return thread_decorator(f);
+ return basic_thread_decorator<typename boost::result_of<F()>::type>(f);
 #endif
     }
    
@@ -268,20 +175,8 @@
         return thread(make_decorator(f));
     }
 
- inline static void decorate() {thread_decoration::decorate();}
-
- template <typename AE, typename Decorator>
- struct asynchronous_executor_decorator : AE {
- //typedef typename boost::result_of<F()>::type result_type;
- template <typename F>
- typename AE::template handle< typename boost::result_of<F()>::type >::type
- fork( F fn ) {
- return this->AE::fork(Decorator(fn));
- }
- };
-
- //typedef asynchronous_executor_decorator<threader,thread_decorator> threader_decorator;
-
+ inline void decorate() {thread_decoration::decorate();}
+
 }
 }
 

Modified: sandbox/interthreads/boost/interthreads/threader.hpp
==============================================================================
--- sandbox/interthreads/boost/interthreads/threader.hpp (original)
+++ sandbox/interthreads/boost/interthreads/threader.hpp 2009-01-14 12:54:41 EST (Wed, 14 Jan 2009)
@@ -14,7 +14,6 @@
 //
 //////////////////////////////////////////////////////////////////////////////
 
-//#include <boost/interthreads/detail/config.hpp>
 #include <boost/thread/detail/move.hpp>
 #include <boost/thread/condition_variable.hpp>
 #include <boost/thread/thread.hpp>
@@ -59,9 +58,12 @@
         unique_joiner_data(Nullary f) {
             packaged_task<result_type> tsk(f);
             fut_ = tsk.get_future();
- //th_ = boost::move(tsk);
+#if 0
+ th_ = boost::move(tsk);
+#else
             thread th(boost::move(tsk));
             th_ = boost::move(th);
+#endif
         }
 #endif
 
@@ -73,7 +75,7 @@
     unique_joiner(unique_joiner& other);
     this_type& operator=(unique_joiner& other);
 
-protected:
+public:
     friend class unique_threader;
     template <typename Nullary>
     // requires result_of<Nullary>::type is convertible to ResultType
@@ -268,9 +270,12 @@
         shared_joiner_data(Nullary f) {
             packaged_task<result_type> tsk(f);
             fut_ = tsk.get_future();
- //th_ = boost::move(tsk);
+#if 0
+ th_ = boost::move(tsk);
+#else
             thread th(boost::move(tsk));
             th_ = boost::move(th);
+#endif
         }
 #endif
 
@@ -279,10 +284,8 @@
     typedef shared_joiner_data this_impl_type;
     typedef shared_joiner this_type;
 
- shared_joiner(shared_joiner& other);
- this_type& operator=(shared_joiner& other);
-
-protected:
+//protected:
+public:
     friend class shared_threader;
     template <typename Nullary>
     // requires result_of<Nullary>::type is convertible to ResultType
@@ -464,20 +467,12 @@
         return t;
     }
 #else
-#if 1
     template <typename T>
     inline boost::detail::thread_move_t<interthreads::unique_joiner<T> >
     move(boost::interthreads::unique_joiner<T>& t)
     {
         return boost::detail::thread_move_t<interthreads::unique_joiner<T> >(t);
     }
-#else
- template <typename T>
- inline interthreads::unique_joiner<T> move(boost::detail::thread_move_t<boost::interthreads::unique_joiner<T> > t)
- {
- return interthreads::unique_joiner<T>(t);
- }
-#endif
 #endif
 #ifdef BOOST_HAS_RVALUE_REFS
     template <typename T>
@@ -486,20 +481,12 @@
         return t;
     }
 #else
-#if 1
     template <typename T>
     inline boost::detail::thread_move_t<interthreads::shared_joiner<T> >
     move(boost::interthreads::shared_joiner<T>& t)
     {
         return boost::detail::thread_move_t<interthreads::shared_joiner<T> >(t);
     }
-#else
- template <typename T>
- inline interthreads::shared_joiner<T> move(boost::detail::thread_move_t<boost::interthreads::shared_joiner<T> > t)
- {
- return interthreads::shared_joiner<T>(t);
- }
-#endif
 #endif
 }
 

Added: sandbox/interthreads/boost/interthreads/threader_decorator.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/threader_decorator.hpp 2009-01-14 12:54:41 EST (Wed, 14 Jan 2009)
@@ -0,0 +1,39 @@
+#ifndef BOOST_INTERTHREADS_THREADER_DECORATOR__HPP
+#define BOOST_INTERTHREADS_THREADER_DECORATOR__HPP
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Roland Schwarz 2006.
+// (C) Copyright Vicente J. Botet Escriba 2008-20009.
+// 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)
+//
+// Extension of the init class of the threadalert library of Roland Schwarz
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/interthreads/asynchronous_executor_decorator.hpp>
+#include <boost/interthreads/thread_decorator.hpp>
+#include <boost/interthreads/threader.hpp>
+
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace interthreads {
+
+
+ typedef asynchronous_executor_decorator<unique_threader,basic_thread_decorator> unique_threader_decorator;
+ typedef asynchronous_executor_decorator<shared_threader,basic_thread_decorator> shared_threader_decorator;
+
+}
+}
+
+#include <boost/config/abi_suffix.hpp>
+
+
+#endif
+

Modified: sandbox/interthreads/boost/interthreads/wait_for_all.hpp
==============================================================================
--- sandbox/interthreads/boost/interthreads/wait_for_all.hpp (original)
+++ sandbox/interthreads/boost/interthreads/wait_for_all.hpp 2009-01-14 12:54:41 EST (Wed, 14 Jan 2009)
@@ -15,6 +15,7 @@
 //////////////////////////////////////////////////////////////////////////////
 
 #include <boost/interthreads/fork_all.hpp>
+#include <boost/interthreads/algorithm/get_all.hpp>
 #include <boost/fusion/include/tuple.hpp>
 #include <boost/futures/future.hpp>
 #include <boost/utility/result_of.hpp>
@@ -47,18 +48,22 @@
 }
 
 
-template< typename Launcher, typename F1, typename F2>
-typename result_of::wait_for_all<Launcher, fusion::tuple<F1,F2> >::type
-wait_for_all( Launcher& launcher, F1 f1, F2 f2 ) {
- typename result_of::fork_all<Launcher, fusion::tuple<F1,F2> >::type tmp=fork_all(launcher, f1, f2);
- return get_all(tmp);
+template< typename AE, typename F1, typename F2>
+typename result_of::wait_for_all<AE, fusion::tuple<F1,F2> >::type
+wait_for_all( AE& ae, F1 f1, F2 f2 ) {
+ typename result_of::fork_all<AE, fusion::tuple<F1,F2> >::type handles(fork_all(ae, f1, f2));
+ typename result_of::wait_for_all<AE, fusion::tuple<F1,F2> >::type values;
+ set_all(handles,values);
+ return values;
 }
 
-template< typename Launcher, typename F1, typename F2, typename F3>
-typename result_of::wait_for_all<Launcher, fusion::tuple<F1,F2,F3> >::type
-wait_for_all( Launcher& launcher, F1 f1, F2 f2 , F3 f3 ) {
- typename result_of::fork_all<Launcher, fusion::tuple<F1,F2> >::type tmp=fork_all(launcher, f1, f2, f3);
- return get_all(tmp);
+template< typename AE, typename F1, typename F2, typename F3>
+typename result_of::wait_for_all<AE, fusion::tuple<F1,F2,F3> >::type
+wait_for_all( AE& ae, F1 f1, F2 f2 , F3 f3 ) {
+ typename result_of::fork_all<AE, fusion::tuple<F1,F2,F3> >::type handles(fork_all(ae, f1, f2, f3));
+ typename result_of::wait_for_all<AE, fusion::tuple<F1,F2,F3> >::type values;
+ set_all(handles,values);
+ return values;
 }
 
 }

Modified: sandbox/interthreads/boost/interthreads/wait_for_any.hpp
==============================================================================
--- sandbox/interthreads/boost/interthreads/wait_for_any.hpp (original)
+++ sandbox/interthreads/boost/interthreads/wait_for_any.hpp 2009-01-14 12:54:41 EST (Wed, 14 Jan 2009)
@@ -8,12 +8,11 @@
 // (See accompanying file LICENSE_1_0.txt or
 // copy at http://www.boost.org/LICENSE_1_0.txt)
 //
-// Based on the threader/joiner design from of Kevlin Henney (n1883)
-//
 // See http://www.boost.org/libs/interthreads for documentation.
 //
 //////////////////////////////////////////////////////////////////////////////
 
+#include <boost/interthreads/algorithm/interrupt_all.hpp>
 #include <boost/interthreads/fork_all.hpp>
 #include <boost/fusion/include/tuple.hpp>
 #include <boost/futures/future.hpp>
@@ -26,16 +25,104 @@
 namespace boost {
 namespace interthreads {
 
+namespace detail {
+
+ template <typename T>
+ struct pair_void {
+ typedef std::pair<unsigned,T> type;
+ typedef T value_type;
+ };
+ template <>
+ struct pair_void<void> {
+ typedef std::pair<unsigned,unsigned> type;
+ typedef void value_type;
+ };
+
+ template <unsigned size, typename T>
+ struct partial;
+ template <typename P>
+ struct partial<2,P> {
+#if 1
+ typedef typename pair_void<P>::value_type T;
+ typedef typename pair_void<P>::type type;
+#else
+ typedef P T;
+ typedef std::pair<unsigned, P> type;
+#endif
+ template <typename H>
+ static type make(unsigned r, H &handles) {
+ return std::make_pair(r,get(r,handles));
+ }
+ template <typename H>
+ static T get(unsigned r, H &handles) {
+ switch (r) {
+ case 0:
+ return fusion::at_c<0>(handles).get();
+ case 1:
+ return fusion::at_c<1>(handles).get();
+ default:
+ throw std::range_error("");
+ }
+ }
+ };
+ template <typename P>
+ struct partial<3,P> {
+#if 1
+ typedef typename pair_void<P>::value_type T;
+ typedef typename pair_void<P>::type type;
+#else
+ typedef P T;
+ typedef std::pair<unsigned, P> type;
+#endif
+ template <typename H>
+ static type make(unsigned r, H &handles) {
+ return std::make_pair(r,get(r,handles));
+ }
+ template <typename H>
+ static T get(unsigned r, H &handles) {
+ switch (r) {
+ case 0:
+ return fusion::at_c<0>(handles).get();
+ case 1:
+ return fusion::at_c<1>(handles).get();
+ case 2:
+ return fusion::at_c<2>(handles).get();
+ default:
+ throw std::range_error("");
+ }
+ }
+ };
+
+ struct partial_aux {
+ typedef pair_void<void>::value_type T;
+ typedef pair_void<void>::type type;
+ //typedef void T;
+ //typedef std::pair<unsigned,unsigned> type;
+ //typedef std::make_pair<unsigned, P> type;
+
+ template <typename H>
+ static type make(unsigned i,H &h) {
+ return std::make_pair(i,i);
+ }
+ };
+
+ template <>
+ struct partial<2, void > : partial_aux{};
+
+ template <>
+ struct partial<3, void > : partial_aux{};
+}
+
 namespace result_of {
     template <typename L, typename T>
     struct wait_for_any;
     template <typename L, typename F1, typename F2>
     struct wait_for_any<L, fusion::tuple<F1,F2> > {
- typedef std::pair<unsigned,typename boost::result_of<F1()>::type> type;
+ typedef typename detail::pair_void<typename boost::result_of<F1()>::type>::type type;
     };
     template <typename L, typename F1, typename F2, typename F3>
     struct wait_for_any<L, fusion::tuple<F1,F2,F3> > {
- typedef std::pair<unsigned,typename boost::result_of<F1()>::type> type;
+ typedef typename detail::pair_void<typename boost::result_of<F1()>::type>::type type;
     };
     
 }
@@ -44,42 +131,47 @@
 template< typename AE, typename F1, typename F2>
 typename result_of::wait_for_any<AE, fusion::tuple<F1,F2> >::type
 wait_for_any( AE& ae, F1 f1, F2 f2 ) {
- typename result_of::fork_all<AE, fusion::tuple<F1,F2> >::type tmp=fork_all(ae, f1, f2);
- unsigned r = boost::wait_for_any(get_future<AE>()(fusion::at_c<0>(tmp)), get_future<AE>()(fusion::at_c<1>(tmp)));
- typename boost::result_of<F1()>::type val;
- switch (r) {
- case 0:
- val = fusion::at_c<0>(tmp).get();
- break;
- case 1:
- val = fusion::at_c<1>(tmp).get();
- break;
- default:
- std::cout << "boost::wait_for_any=" << r << std::endl;
- throw std::range_error("");
- }
- interrupt_all(tmp);
- return std::make_pair(r, val);
+ typename result_of::fork_all<AE, fusion::tuple<F1,F2> >::type handles=fork_all(ae, f1, f2);
+ unsigned r = boost::wait_for_any(get_future<AE>()(fusion::at_c<0>(handles)), get_future<AE>()(fusion::at_c<1>(handles)));
+ std::cout << "boost::wait_for_any=" << r << std::endl;
+ typename result_of::wait_for_any<AE, fusion::tuple<F1,F2> >::type res =
+ detail::partial<2,typename boost::result_of<F1()>::type >::make(r,handles);
+
+ return res;
 }
 
 template< typename AE, typename F1, typename F2, typename F3>
 typename result_of::wait_for_any<AE, fusion::tuple<F1,F2,F3> >::type
 wait_for_any( AE& ae, F1 f1, F2 f2 , F3 f3 ) {
- typename result_of::fork_all<AE, fusion::tuple<F1,F2,F3> >::type tmp=fork_all(ae, f1, f2, f3);
- unsigned r = boost::wait_for_any(get_future<AE>()(fusion::at_c<0>(tmp)), get_future<AE>()(fusion::at_c<1>(tmp)), get_future<AE>()(fusion::at_c<2>(tmp)));
- typename boost::result_of<F1()>::type val;
- switch (r) {
- case 0:
- val = fusion::at_c<0>(tmp).get();
- case 1:
- val = fusion::at_c<1>(tmp).get();
- case 2:
- val = fusion::at_c<2>(tmp).get();
- default:
- std::cout << "boost::wait_for_any=" << r << std::endl;
- //throw std::range_error("");
- }
- return std::make_pair(r, val);
+ typename result_of::fork_all<AE, fusion::tuple<F1,F2,F3> >::type handles=fork_all(ae, f1, f2, f3);
+ unsigned r = boost::wait_for_any(get_future<AE>()(fusion::at_c<0>(handles)), get_future<AE>()(fusion::at_c<1>(handles)), get_future<AE>()(fusion::at_c<2>(handles)));
+ typename result_of::wait_for_any<AE, fusion::tuple<F1,F2,F3> >::type res =
+ detail::partial<3, typename boost::result_of<F1()>::type >::make(r,handles);
+ return res;
+}
+
+template< typename AE, typename F1, typename F2>
+typename result_of::wait_for_any<AE, fusion::tuple<F1,F2> >::type
+wait_for_any_and_interrupt( AE& ae, F1 f1, F2 f2 ) {
+ typename result_of::fork_all<AE, fusion::tuple<F1,F2> >::type handles=fork_all(ae, f1, f2);
+ unsigned r = boost::wait_for_any(get_future<AE>()(fusion::at_c<0>(handles)), get_future<AE>()(fusion::at_c<1>(handles)));
+ std::cout << "boost::wait_for_any=" << r << std::endl;
+ typename result_of::wait_for_any<AE, fusion::tuple<F1,F2> >::type res =
+ detail::partial<2,typename boost::result_of<F1()>::type >::make(r,handles);
+
+ interrupt_all(handles);
+ return res;
+}
+
+template< typename AE, typename F1, typename F2, typename F3>
+typename result_of::wait_for_any<AE, fusion::tuple<F1,F2,F3> >::type
+wait_for_any_and_interrupt( AE& ae, F1 f1, F2 f2 , F3 f3 ) {
+ typename result_of::fork_all<AE, fusion::tuple<F1,F2,F3> >::type handles=fork_all(ae, f1, f2, f3);
+ unsigned r = boost::wait_for_any(get_future<AE>()(fusion::at_c<0>(handles)), get_future<AE>()(fusion::at_c<1>(handles)), get_future<AE>()(fusion::at_c<2>(handles)));
+ typename result_of::wait_for_any<AE, fusion::tuple<F1,F2,F3> >::type res =
+ detail::partial<3, typename boost::result_of<F1()>::type >::make(r,handles);
+ interrupt_all(handles);
+ return res;
 }
 
 }


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