|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r50588 - sandbox/interthreads/boost/interthreads
From: vicente.botet_at_[hidden]
Date: 2009-01-14 12:43:26
Author: viboes
Date: 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
New Revision: 50588
URL: http://svn.boost.org/trac/boost/changeset/50588
Log:
interthreads version 0.2
Adding threader/joiner
Adding Asynchronous Executors fmk
Added:
sandbox/interthreads/boost/interthreads/algorithm.hpp (contents, props changed)
sandbox/interthreads/boost/interthreads/basic_threader.hpp (contents, props changed)
sandbox/interthreads/boost/interthreads/fork.hpp (contents, props changed)
sandbox/interthreads/boost/interthreads/fork_all.hpp (contents, props changed)
sandbox/interthreads/boost/interthreads/launcher.hpp (contents, props changed)
sandbox/interthreads/boost/interthreads/thread_algo.hpp (contents, props changed)
sandbox/interthreads/boost/interthreads/threader.hpp (contents, props changed)
sandbox/interthreads/boost/interthreads/wait_for_all.hpp (contents, props changed)
sandbox/interthreads/boost/interthreads/wait_for_any.hpp (contents, props changed)
Text files modified:
sandbox/interthreads/boost/interthreads/set_once.hpp | 2 +-
sandbox/interthreads/boost/interthreads/thread_and_join.hpp | 2 +-
sandbox/interthreads/boost/interthreads/thread_decorator.hpp | 2 +-
sandbox/interthreads/boost/interthreads/thread_group_once.hpp | 2 +-
sandbox/interthreads/boost/interthreads/thread_keep_alive.hpp | 2 +-
sandbox/interthreads/boost/interthreads/thread_specific_shared_ptr.hpp | 2 +-
sandbox/interthreads/boost/interthreads/thread_tuple.hpp | 2 +-
sandbox/interthreads/boost/interthreads/thread_tuple_once.hpp | 2 +-
8 files changed, 8 insertions(+), 8 deletions(-)
Added: sandbox/interthreads/boost/interthreads/algorithm.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/algorithm.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -0,0 +1,31 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTERTHREADS_ALGORITHM__HPP
+#define BOOST_INTERTHREADS_ALGORITHM__HPP
+
+#include <boost/interthreads/fork_all.hpp>
+#include <boost/interthreads/wait_for_all.hpp>
+#include <boost/interthreads/wait_for_any.hpp>
+#include <boost/interthreads/algorithm/detach_all.hpp>
+#include <boost/interthreads/algorithm/interrupt_all.hpp>
+#include <boost/interthreads/algorithm/interruption_requested_on_all.hpp>
+#include <boost/interthreads/algorithm/join_all.hpp>
+#include <boost/interthreads/algorithm/join_all_until.hpp>
+//#include <boost/interthreads/algorithm/join_all_for.hpp>
+#include <boost/interthreads/algorithm/get_all.hpp>
+#include <boost/interthreads/algorithm/get_all_until.hpp>
+//#include <boost/interthreads/algorithm/get_all_for.hpp>
+#include <boost/interthreads/algorithm/wait_all.hpp>
+#include <boost/interthreads/algorithm/wait_all_until.hpp>
+//#include <boost/interthreads/algorithm/wait_all_for.hpp>
+
+
+#endif
Added: sandbox/interthreads/boost/interthreads/basic_threader.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/basic_threader.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -0,0 +1,66 @@
+#ifndef BOOST_INTERTHREADS_BASIC_THREADER__HPP
+#define BOOST_INTERTHREADS_BASIC_THREADER__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 threader/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/thread.hpp>
+//#include <boost/thread/tss.hpp>
+
+#include <boost/interthreads/fork.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+
+namespace boost {
+namespace interthreads {
+
+
+class basic_threader {
+#ifdef BOOST_THREAD_HAS_THREAD_ATTR
+private:
+ thread::native_handle_attr_type attr_;
+public:
+ thread::native_handle_attr_type& attr() {
+ return attr_;
+ }
+#endif
+
+public:
+ template <typename T>
+ struct handle {
+ typedef thread type;
+ };
+
+ template <typename F>
+ thread
+ fork(F f) {
+#ifdef BOOST_THREAD_HAS_THREAD_ATTR
+ thread th(attr(), f);
+#else
+ thread th(f);
+#endif
+ return thread(detail::thread_move_t<thread>(th));
+ }
+};
+
+
+}
+}
+
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif
+
Added: sandbox/interthreads/boost/interthreads/fork.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/fork.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -0,0 +1,75 @@
+#ifndef BOOST_INTERTHREADS_FORK__HPP
+#define BOOST_INTERTHREADS_FORK__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 threader/joiner design from of Kevlin Henney (n1883)
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/bind.hpp>
+#include <boost/utility/result_of.hpp>
+#include <boost/futures/future.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+
+namespace boost {
+namespace interthreads {
+
+template <typename AE, typename T>
+struct asynchronous_completion_token {
+ typedef typename AE::template handle<T>::type type;
+};
+
+
+namespace result_of {
+ template <typename AE,typename F>
+ struct fork {
+ typedef typename boost::result_of<F()>::type result_type;
+ typedef typename asynchronous_completion_token<AE, result_type>::type type;
+ };
+}
+
+template <typename AE>
+struct get_future;
+
+template< typename AE, typename F >
+typename result_of::fork<AE,F>::type
+fork( AE& ae, F fn ) {
+ return ae.fork(fn);
+}
+
+template< typename AE, typename F, typename A1 >
+typename asynchronous_completion_token<AE, typename boost::result_of<F(A1)>::type >::type
+fork( AE& ae, F fn, A1 a1 ) {
+ return ae.fork( bind( fn, a1 ) );
+}
+
+template< typename AE, typename F, typename A1, typename A2 >
+typename asynchronous_completion_token<AE, typename boost::result_of<F(A1,A2)>::type >::type
+fork( AE& ae, F fn, A1 a1, A2 a2 ) {
+ return ae.fork( bind( fn, a1, a2 ) );
+}
+
+template< typename AE, typename F, typename A1, typename A2, typename A3 >
+typename asynchronous_completion_token<AE, typename boost::result_of<F(A1,A2,A3)>::type >::type
+fork( AE& ae, F fn, A1 a1, A2 a2, A3 a3 ) {
+ return ae.fork( bind( fn, a1, a2, a3 ) );
+}
+
+}
+}
+
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif
+
Added: sandbox/interthreads/boost/interthreads/fork_all.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/fork_all.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -0,0 +1,74 @@
+#ifndef BOOST_INTERTHREADS_FORK_ALL__HPP
+#define BOOST_INTERTHREADS_FORK_ALL__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 threader/joiner design from of Kevlin Henney (n1883)
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+//#include <boost/interthreads/fork.hpp>
+#include <boost/thread/detail/move.hpp>
+#include <boost/fusion/include/tuple.hpp>
+#include <boost/utility/result_of.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+
+namespace boost {
+namespace interthreads {
+
+
+namespace result_of {
+ template <typename AE, typename T>
+ struct fork_all;
+ template <typename AE, typename F1, typename F2>
+ struct fork_all<AE, fusion::tuple<F1,F2> > {
+ typedef fusion::tuple<
+ typename result_of::fork<AE,F1>::type,
+ typename result_of::fork<AE,F2>::type
+ > type;
+ };
+ template <typename AE, typename F1, typename F2, typename F3>
+ struct fork_all<AE, fusion::tuple<F1,F2,F3> > {
+ typedef fusion::tuple<
+ typename fork<AE,F1>::type,
+ typename fork<AE,F2>::type,
+ typename fork<AE,F3>::type
+ > type;
+ };
+
+}
+
+
+template< typename AE, typename F1, typename F2>
+typename result_of::fork_all<AE, fusion::tuple<F1,F2> >::type
+fork_all( AE& ae, F1 f1, F2 f2 ) {
+ 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());
+}
+
+template< typename AE, typename F1, typename F2, typename F3>
+typename result_of::fork_all<AE, fusion::tuple<F1,F2,F3> >::type
+fork_all( AE& ae, F1 f1, F2 f2, F3 f3 ) {
+ typedef typename result_of::fork_all<AE, fusion::tuple<F1,F2,F3> >::type type;
+ return type(ae.fork(f1),ae.fork(f2),ae.fork(f3));
+}
+
+}
+}
+
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif
+
Added: sandbox/interthreads/boost/interthreads/launcher.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/launcher.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -0,0 +1,124 @@
+#ifndef BOOST_INTERTHREADS_LAUNCHER__HPP
+#define BOOST_INTERTHREADS_LAUNCHER__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 threader/joiner design from of Kevlin Henney (n1883)
+//
+// 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/tuple/tuple.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 {
+
+
+class launcher {
+#ifdef BOOST_THREAD_HAS_THREAD_ATTR
+private:
+ thread::native_handle_attr_type attr_;
+public:
+ thread::native_handle_attr_type& attr() {
+ return attr_;
+ }
+#endif
+
+public:
+ template <typename T>
+ struct handle {
+ typedef unique_future<T> type;
+ };
+
+ template <typename F>
+ unique_future<typename boost::result_of<F()>::type>
+ fork(F f) {
+ typedef typename boost::result_of<F()>::type result_type;
+ packaged_task<result_type> tsk(f);
+ unique_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 unique_future<result_type>(detail::thread_move_t<unique_future<result_type> >(res));
+
+ //return detail::thread_move_t<boost::unique_future<result_type> >(res);
+ }
+};
+
+
+class shared_launcher {
+#ifdef BOOST_THREAD_HAS_THREAD_ATTR
+private:
+ thread::native_handle_attr_type attr_;
+public:
+ thread::native_handle_attr_type& attr() {
+ return attr_;
+ }
+#endif
+
+public:
+ template <typename T>
+ struct handle {
+ typedef shared_future<T> type;
+ };
+
+ template <typename F>
+ shared_future<typename boost::result_of<F()>::type>
+ 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();
+#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);
+ }
+};
+
+template <>
+struct get_future<launcher> {
+ template <typename T>
+ unique_future<T>& operator()(unique_future<T>& f) { return f; }
+};
+
+template <>
+struct get_future<shared_launcher> {
+ template <typename T>
+ shared_future<T>& operator()(shared_future<T>& f) { return f; }
+};
+
+
+}
+}
+
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif
+
Modified: sandbox/interthreads/boost/interthreads/set_once.hpp
==============================================================================
--- sandbox/interthreads/boost/interthreads/set_once.hpp (original)
+++ sandbox/interthreads/boost/interthreads/set_once.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////
//
-// (C) Copyright Vicente J. Botet Escriba 2008. Distributed under the Boost
+// (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)
//
Added: sandbox/interthreads/boost/interthreads/thread_algo.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/thread_algo.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -0,0 +1,90 @@
+//////////////////////////////////////////////////////////////////////////////
+//
+// (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.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef BOOST_INTERTHREADS_THREAD_ALGO_HPP
+#define BOOST_INTERTHREADS_THREAD_ALGO_HPP
+
+#include <boost/bind.hpp>
+#include <boost/thread/detail/move.hpp>
+#ifdef BOOST_HAS_MOVE_LIB
+#include <boost/move/move.hpp>
+#endif
+#ifdef BOOST_HAS_CHRONO_LIB
+#include <boost/chono/chono.hpp>
+#endif
+#include <boost/thread/thread_time.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/array.hpp>
+#include <boost/shared_ptr.hpp>
+#include <utility>
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace interthreads {
+
+ template <typename THREADS>
+ bool joinables(THREADS& threads) const {
+ for (std::size_t i=0; i<threads.size(); i++) {
+ if (!threads[i].joinable()) return false;
+ }
+ return true;
+ }
+
+ template <typename THREADS>
+ void join_all(THREADS& threads) {
+ for (std::size_t i=0; i<threads.size(); i++) {
+ threads[i].join();
+ }
+ }
+
+ template <typename THREADS>
+ bool join_all_until(THREADS& threads, const system_time& wait_until) {
+ for (std::size_t i=0; i<threads.size(); i++) {
+ if (!threads[i].timed_join(wait_until)) return false;
+ }
+ return true;
+ }
+
+ template<typename THREADS, typename TimeDuration>
+ inline bool join_all_for(THREADS& threads, TimeDuration const& rel_time)
+ {
+ return join_all_until(get_system_time()+rel_time);
+ }
+
+ template <typename THREADS>
+ void detach_all(THREADS& threads) {
+ for (std::threads.sizet i=0; i<threads.size; i++) {
+ threads[i].detach();
+ }
+ }
+
+ template <typename THREADS>
+ void interrupt_all(THREADS& threads) {
+ for (std::threads.sizet i=0; i<threads.size; i++) {
+ threads[i].interrupt();
+ }
+ }
+
+ template <typename THREADS>
+ bool interruption_requested(THREADS& threads) const {
+ for (std::threads.sizet i=0; i<threads.size; i++) {
+ if (!threads[i].interruption_requested()) return false;
+ }
+ return true;
+ }
+
+
+}
+} // namespace boost
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif
Modified: sandbox/interthreads/boost/interthreads/thread_and_join.hpp
==============================================================================
--- sandbox/interthreads/boost/interthreads/thread_and_join.hpp (original)
+++ sandbox/interthreads/boost/interthreads/thread_and_join.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////
//
-// (C) Copyright Vicente J. Botet Escriba 2008. Distributed under the Boost
+// (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)
//
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:43:24 EST (Wed, 14 Jan 2009)
@@ -4,7 +4,7 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Roland Schwarz 2006.
-// (C) Copyright Vicente J. Botet Escriba 2008.
+// (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)
Modified: sandbox/interthreads/boost/interthreads/thread_group_once.hpp
==============================================================================
--- sandbox/interthreads/boost/interthreads/thread_group_once.hpp (original)
+++ sandbox/interthreads/boost/interthreads/thread_group_once.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////
//
-// (C) Copyright Vicente J. Botet Escriba 2008. Distributed under the Boost
+// (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)
//
Modified: sandbox/interthreads/boost/interthreads/thread_keep_alive.hpp
==============================================================================
--- sandbox/interthreads/boost/interthreads/thread_keep_alive.hpp (original)
+++ sandbox/interthreads/boost/interthreads/thread_keep_alive.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -3,7 +3,7 @@
//////////////////////////////////////////////////////////////////////////////
//
-// (C) Copyright Vicente J. Botet Escriba 2008.
+// (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)
Modified: sandbox/interthreads/boost/interthreads/thread_specific_shared_ptr.hpp
==============================================================================
--- sandbox/interthreads/boost/interthreads/thread_specific_shared_ptr.hpp (original)
+++ sandbox/interthreads/boost/interthreads/thread_specific_shared_ptr.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -4,7 +4,7 @@
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Roland Schwarz 2006.
-// (C) Copyright Vicente J. Botet Escriba 2008.
+// (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)
Modified: sandbox/interthreads/boost/interthreads/thread_tuple.hpp
==============================================================================
--- sandbox/interthreads/boost/interthreads/thread_tuple.hpp (original)
+++ sandbox/interthreads/boost/interthreads/thread_tuple.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////
//
-// (C) Copyright Vicente J. Botet Escriba 2008. Distributed under the Boost
+// (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)
//
Modified: sandbox/interthreads/boost/interthreads/thread_tuple_once.hpp
==============================================================================
--- sandbox/interthreads/boost/interthreads/thread_tuple_once.hpp (original)
+++ sandbox/interthreads/boost/interthreads/thread_tuple_once.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////
//
-// (C) Copyright Vicente J. Botet Escriba 2008. Distributed under the Boost
+// (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)
//
Added: sandbox/interthreads/boost/interthreads/threader.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/threader.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -0,0 +1,510 @@
+#ifndef BOOST_INTERTHREADS_THREADER__HPP
+#define BOOST_INTERTHREADS_THREADER__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/interthreads/detail/config.hpp>
+#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/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 ResultType>
+class unique_joiner;
+
+template <typename ResultType>
+class unique_joiner {
+public:
+ typedef ResultType result_type;
+private:
+ struct unique_joiner_data {
+ unique_future< result_type > fut_;
+ thread th_;
+
+ unique_joiner_data() {}
+
+ template <typename Nullary>
+#ifdef BOOST_THREAD_HAS_THREAD_ATTR
+ unique_joiner_data(thread::native_handle_attr_type& attr, Nullary f) {
+ packaged_task<result_type> tsk(f);
+ fut_ = tsk.get_future();
+ thread th(attr, boost::move(tsk));
+ th_ = boost::move(th);
+ }
+#else
+ unique_joiner_data(Nullary f) {
+ packaged_task<result_type> tsk(f);
+ fut_ = tsk.get_future();
+ //th_ = boost::move(tsk);
+ thread th(boost::move(tsk));
+ th_ = boost::move(th);
+ }
+#endif
+
+ };
+ shared_ptr<unique_joiner_data> data_;
+ typedef unique_joiner_data this_impl_type;
+ typedef unique_joiner this_type;
+
+ unique_joiner(unique_joiner& other);
+ this_type& operator=(unique_joiner& other);
+
+protected:
+ friend class unique_threader;
+ template <typename Nullary>
+ // requires result_of<Nullary>::type is convertible to ResultType
+#ifdef BOOST_THREAD_HAS_THREAD_ATTR
+ unique_joiner(thread::native_handle_attr_type& attr, Nullary f)
+ : data_(new this_impl_type(attr, f))
+#else
+ unique_joiner(Nullary f)
+ : data_(new this_impl_type(f))
+#endif
+ {}
+
+public:
+ // move support
+#ifdef BOOST_HAS_RVALUE_REFS
+ unique_joiner(this_type&& other) {
+ data_.swap(other.data_);
+ }
+ unique_joiner& operator=(unique_joiner&& other) {
+ data_=other.data_;
+ other.data_.reset(new this_impl_type());
+ return *this;
+ }
+
+ unique_joiner&& move() {
+ return static_cast<unique_joiner&&>(*this);
+ }
+#else
+ unique_joiner(boost::detail::thread_move_t<unique_joiner> x) {
+ data_=x->data_;
+ x->data_.reset(new this_impl_type());
+ }
+
+ unique_joiner& operator=(boost::detail::thread_move_t<unique_joiner> x) {
+ this_type tmp_(x);
+ swap(tmp_);
+ return *this;
+ }
+
+ operator boost::detail::thread_move_t<unique_joiner>() {
+ return move();
+ }
+
+ boost::detail::thread_move_t<unique_joiner> move() {
+ return boost::detail::thread_move_t<unique_joiner>(*this);
+ }
+
+#endif
+
+ void swap(this_type& x) {
+ data_.swap(x.data_);
+ }
+
+ bool joinable() {
+ return data_->th_.joinable();
+ }
+
+ void join() {
+ data_->th_.join();
+// wait();
+ }
+
+ bool join_until(const system_time& abs_time) {
+ return data_->th_.timed_join(abs_time);
+// return wait_until(abs_time);
+ }
+
+ template<typename TimeDuration>
+ inline bool join_for(TimeDuration const& rel_time)
+ {
+ return join_until(get_system_time()+rel_time);
+ }
+
+ result_type get() const {
+ //data_->th_.join();
+ return const_cast<unique_future< result_type >*>(&(data_->fut_))->get();
+ }
+
+ result_type operator()() const { return get(); }
+ result_type get() {
+ //data_->th_.join();
+ return data_->fut_.get();
+ }
+ result_type operator()() { return get(); }
+
+ bool is_ready() const {
+ return data_->fut_.is_ready();
+ }
+ bool has_exception() const {
+ return data_->fut_.has_exception();
+ }
+ bool has_value() const {
+ return data_->fut_.has_value();
+ }
+
+ void wait() {
+ data_->fut_.wait();
+ }
+ bool wait_until(const system_time& abs_time) {
+ return data_->fut_.timed_wait_until(abs_time);
+ }
+
+ template<typename TimeDuration>
+ inline bool wait_for(TimeDuration const& rel_time)
+ {
+ return wait_until(get_system_time()+rel_time);
+ }
+
+ void detach() {
+ data_->th_.detach();
+ }
+
+ void interrupt() {
+ data_->th_.interrupt();
+ }
+
+ bool interruption_requested() const {
+ return data_->th_.interruption_requested();
+ }
+
+ thread::id get_id() const {
+ return data_->th_.get_id();
+ }
+
+ unique_future<result_type>& get_future() {
+ return data_->fut_;
+ }
+};
+
+class unique_threader {
+#ifdef BOOST_THREAD_HAS_THREAD_ATTR
+private:
+ thread_specific_ptr<thread::native_handle_attr_type> attr_;
+public:
+ thread::native_handle_attr_type& attr() {
+ if(attr_.get() ==0) {
+ attr_.reset(new thread::native_handle_attr_type());
+ };
+ return *attr_.get();
+ }
+#endif
+
+public:
+ template <typename T>
+ struct handle {
+ typedef unique_joiner<T> type;
+ };
+ template <typename F>
+ unique_joiner<typename boost::result_of<F()>::type>
+ fork(F f) {
+ typedef typename boost::result_of<F()>::type result_type;
+#ifdef BOOST_THREAD_HAS_THREAD_ATTR
+ unique_joiner<result_type> unique_joiner_(attr(), f);
+#else
+ unique_joiner<result_type> unique_joiner_(f);
+#endif
+ return boost::move(unique_joiner_);
+ }
+
+};
+
+template <>
+struct get_future<unique_threader> {
+ template <typename T>
+ unique_future<T>& operator()(unique_joiner<T>& j) { return j.get_future(); }
+};
+
+
+template <typename ResultType>
+class shared_joiner;
+
+template <typename ResultType>
+class shared_joiner {
+public:
+ typedef ResultType result_type;
+private:
+ struct shared_joiner_data {
+ shared_future< result_type > fut_;
+ thread th_;
+
+ shared_joiner_data() {}
+
+ template <typename Nullary>
+#ifdef BOOST_THREAD_HAS_THREAD_ATTR
+ shared_joiner_data(thread::native_handle_attr_type& attr, Nullary f) {
+ packaged_task<result_type> tsk(f);
+ fut_ = tsk.get_future();
+ thread th(attr, boost::move(tsk));
+ th_ = boost::move(th);
+ }
+#else
+ shared_joiner_data(Nullary f) {
+ packaged_task<result_type> tsk(f);
+ fut_ = tsk.get_future();
+ //th_ = boost::move(tsk);
+ thread th(boost::move(tsk));
+ th_ = boost::move(th);
+ }
+#endif
+
+ };
+ shared_ptr<shared_joiner_data> data_;
+ typedef shared_joiner_data this_impl_type;
+ typedef shared_joiner this_type;
+
+ shared_joiner(shared_joiner& other);
+ this_type& operator=(shared_joiner& other);
+
+protected:
+ friend class shared_threader;
+ template <typename Nullary>
+ // requires result_of<Nullary>::type is convertible to ResultType
+#ifdef BOOST_THREAD_HAS_THREAD_ATTR
+ shared_joiner(thread::native_handle_attr_type& attr, Nullary f)
+ : data_(new this_impl_type(attr, f))
+#else
+ shared_joiner(Nullary f)
+ : data_(new this_impl_type(f))
+#endif
+ {}
+
+public:
+ shared_joiner(const shared_joiner& other) : data_(other.data_){
+ }
+ this_type& operator=(const shared_joiner& other) {
+ data_=other.data_;
+ other.data_.reset(new this_impl_type());
+ return *this;
+ }
+
+ // move support
+#ifdef BOOST_HAS_RVALUE_REFS
+ shared_joiner(this_type&& other) {
+ data_.swap(other.data_);
+ }
+ shared_joiner& operator=(shared_joiner&& other) {
+ data_=other.data_;
+ other.data_.reset(new this_impl_type());
+ return *this;
+ }
+
+ shared_joiner&& move() {
+ return static_cast<shared_joiner&&>(*this);
+ }
+#else
+ shared_joiner(boost::detail::thread_move_t<shared_joiner> x) {
+ data_=x->data_;
+ x->data_.reset(new this_impl_type());
+ }
+
+ shared_joiner& operator=(boost::detail::thread_move_t<shared_joiner> x) {
+ this_type tmp_(x);
+ swap(tmp_);
+ return *this;
+ }
+
+ operator boost::detail::thread_move_t<shared_joiner>() {
+ return move();
+ }
+
+ boost::detail::thread_move_t<shared_joiner> move() {
+ return boost::detail::thread_move_t<shared_joiner>(*this);
+ }
+
+#endif
+
+ void swap(this_type& x) {
+ data_.swap(x.data_);
+ }
+
+ bool joinable() {
+ return data_->th_.joinable();
+ }
+
+ void join() {
+ data_->th_.join();
+// wait();
+ }
+
+ bool join_until(const system_time& abs_time) {
+ return data_->th_.timed_join(abs_time);
+// return wait_until(abs_time);
+ }
+
+ template<typename TimeDuration>
+ inline bool join_for(TimeDuration const& rel_time)
+ {
+ return join_until(get_system_time()+rel_time);
+ }
+ result_type get() {
+ //data_->th_.join();
+ return data_->fut_.get();
+ }
+ result_type operator()() { return get(); }
+ result_type get() const {
+ //data_->th_.join();
+ return const_cast<shared_future< result_type >*>(&(data_->fut_))->get();
+ }
+
+ result_type operator()() const { return get(); }
+
+ bool is_ready() const {
+ return data_->fut_.is_ready();
+ }
+ bool has_exception() const {
+ return data_->fut_.has_exception();
+ }
+ bool has_value() const {
+ return data_->fut_.has_value();
+ }
+
+ void wait() {
+ data_->fut_.wait();
+ }
+ bool wait_until(const system_time& abs_time) {
+ return data_->fut_.timed_wait_until(abs_time);
+ }
+
+ template<typename TimeDuration>
+ inline bool wait_for(TimeDuration const& rel_time)
+ {
+ return wait_until(get_system_time()+rel_time);
+ }
+
+ void detach() {
+ data_->th_.detach();
+ }
+
+ void interrupt() {
+ data_->th_.interrupt();
+ }
+
+ bool interruption_requested() const {
+ return data_->th_.interruption_requested();
+ }
+
+ thread::id get_id() const {
+ return data_->th_.get_id();
+ }
+
+ shared_future<result_type>& get_future() {
+ return data_->fut_;
+ }
+};
+
+class shared_threader {
+#ifdef BOOST_THREAD_HAS_THREAD_ATTR
+private:
+ thread_specific_ptr<thread::native_handle_attr_type> attr_;
+public:
+ thread::native_handle_attr_type& attr() {
+ if(attr_.get() ==0) {
+ attr_.reset(new thread::native_handle_attr_type());
+ };
+ return *attr_.get();
+ }
+#endif
+
+public:
+ template <typename T>
+ struct handle {
+ typedef shared_joiner<T> type;
+ };
+ template <typename F>
+ shared_joiner<typename boost::result_of<F()>::type>
+ fork(F f) {
+ typedef typename boost::result_of<F()>::type result_type;
+#ifdef BOOST_THREAD_HAS_THREAD_ATTR
+ return shared_joiner<result_type>(attr(), f);
+#else
+ return shared_joiner<result_type>(f);
+#endif
+ }
+
+};
+
+template <>
+struct get_future<shared_threader> {
+ template <typename T>
+ shared_future<T>& operator()(shared_joiner<T>& j) { return j.get_future(); }
+};
+
+}
+#ifdef BOOST_HAS_RVALUE_REFS
+ template <typename T>
+ inline interthreads::unique_joiner<T>&& move(interthreads::unique_joiner<T>&& t)
+ {
+ 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>
+ inline interthreads::shared_joiner<T>&& move(interthreads::shared_joiner<T>&& t)
+ {
+ 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
+}
+
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif
+
Added: sandbox/interthreads/boost/interthreads/wait_for_all.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/wait_for_all.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -0,0 +1,71 @@
+#ifndef BOOST_INTERTHREADS_WAIT_FOR_ALL__HPP
+#define BOOST_INTERTHREADS_WAIT_FOR_ALL__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 threader/joiner design from of Kevlin Henney (n1883)
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/interthreads/fork_all.hpp>
+#include <boost/fusion/include/tuple.hpp>
+#include <boost/futures/future.hpp>
+#include <boost/utility/result_of.hpp>
+
+#include <boost/config/abi_prefix.hpp>
+
+
+namespace boost {
+namespace interthreads {
+
+namespace result_of {
+ template <typename L, typename T>
+ struct wait_for_all;
+ template <typename L, typename F1, typename F2>
+ struct wait_for_all<L,fusion::tuple<F1,F2> > {
+ typedef fusion::tuple<
+ typename boost::result_of<F1()>::type,
+ typename boost::result_of<F2()>::type
+ > type;
+ };
+ template <typename L, typename F1, typename F2, typename F3>
+ struct wait_for_all<L, fusion::tuple<F1,F2,F3> > {
+ typedef fusion::tuple<
+ typename boost::result_of<F1()>::type,
+ typename boost::result_of<F2()>::type,
+ typename boost::result_of<F3()>::type
+ > type;
+ };
+
+}
+
+
+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 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);
+}
+
+}
+}
+
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif
+
Added: sandbox/interthreads/boost/interthreads/wait_for_any.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/wait_for_any.hpp 2009-01-14 12:43:24 EST (Wed, 14 Jan 2009)
@@ -0,0 +1,92 @@
+#ifndef BOOST_INTERTHREADS_WAIT_FOR_ANY__HPP
+#define BOOST_INTERTHREADS_WAIT_FOR_ANY__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 threader/joiner design from of Kevlin Henney (n1883)
+//
+// See http://www.boost.org/libs/interthreads for documentation.
+//
+//////////////////////////////////////////////////////////////////////////////
+
+#include <boost/interthreads/fork_all.hpp>
+#include <boost/fusion/include/tuple.hpp>
+#include <boost/futures/future.hpp>
+#include <boost/utility/result_of.hpp>
+#include <exception>
+
+#include <boost/config/abi_prefix.hpp>
+
+
+namespace boost {
+namespace interthreads {
+
+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;
+ };
+ 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;
+ };
+
+}
+
+
+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);
+}
+
+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);
+}
+
+}
+}
+
+
+#include <boost/config/abi_suffix.hpp>
+
+#endif
+
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