Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51117 - sandbox/interthreads/boost/interthreads
From: vicente.botet_at_[hidden]
Date: 2009-02-08 16:31:37


Author: viboes
Date: 2009-02-08 16:31:36 EST (Sun, 08 Feb 2009)
New Revision: 51117
URL: http://svn.boost.org/trac/boost/changeset/51117

Log:
interthreads version 0.4
    * New free functions for all the AsynchronousCompletionToken operations, providing a higher degree of freedom.
    * Missing have_all_values(), have_all_exception() and are_all_ready() functions on AsynchronousCompletionToken fusion tuples.
    * get_all: getting all the values from a tuple of AsynchronousCompletionToken works now.
    * fork_after overloaded for a single dependency
    * wait_all overloaded for a single ACT.
    * wait_for_all evaluate one of its elements on the current thread
    * No need to use wait_and_get() on thread_specific_shared_ptr<> to synchronize with the decoration if the thread is created using a AsynchronousExecutor decorator. In this case the synchro is done before returning the AsynchronousCompletionToken. See the tutorial and the mono_thread_id example.

Added:
   sandbox/interthreads/boost/interthreads/asynchronous_executor_wait_decorator.hpp (contents, props changed)
   sandbox/interthreads/boost/interthreads/wait_thread_decorator.hpp (contents, props changed)

Added: sandbox/interthreads/boost/interthreads/asynchronous_executor_wait_decorator.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/asynchronous_executor_wait_decorator.hpp 2009-02-08 16:31:36 EST (Sun, 08 Feb 2009)
@@ -0,0 +1,104 @@
+#ifndef BOOST_INTERTHREADS_ASYNCHRONOUS_WAIT_EXECUTOR_DECORATOR__HPP
+#define BOOST_INTERTHREADS_ASYNCHRONOUS_WAIT_EXECUTOR_DECORATOR__HPP
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Vicente J. Botet Escriba 2008-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)
+//
+// 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_wait_decorator : AE {
+
+#if 0
+ template <typename F>
+ static typename boost::result_of<F()>::type waiter(bool started, condition_variable cond, F f) {
+ typename boost::result_of<F()>::type res = f();
+ started
+ }
+#endif
+ template <typename T>
+ struct handle {
+ typedef typename AE::template handle<T>::type type;
+ };
+
+ template <typename F>
+ typename AE::template handle< typename boost::result_of<F()>::type >::type
+ fork( F fn ) {
+ bool started;
+ condition_variable cond;
+ typename result_of::fork<AE, F>::type act= this->AE::fork(Decorator<typename boost::result_of<F()>::type>(fn));
+ while (!started) cond.wait();
+ return boost::move(act);
+ }
+
+ asynchronous_executor_wait_decorator() :AE() {};
+
+ template <typename Nullary>
+#ifdef BOOST_THREAD_HAS_THREAD_ATTR
+ asynchronous_executor_wait_decorator(thread::native_handle_attr_type& attr, Nullary f)
+ : AE(attr, f)
+#else
+ asynchronous_executor_wait_decorator(Nullary f)
+ : AE(f)
+#endif
+ {}
+
+ // move support
+#ifdef BOOST_HAS_RVALUE_REFS
+#else
+ asynchronous_executor_wait_decorator(boost::detail::thread_move_t<asynchronous_executor_wait_decorator> x)
+ : AE(boost::move(*(static_cast<AE*>(&(x.member))))) {}
+
+ asynchronous_executor_wait_decorator& operator=(boost::detail::thread_move_t<asynchronous_executor_wait_decorator> x) {
+ return move();
+ }
+
+ operator boost::detail::thread_move_t<asynchronous_executor_wait_decorator>() {
+ return move();
+ }
+
+ boost::detail::thread_move_t<asynchronous_executor_wait_decorator> move() {
+ return boost::detail::thread_move_t<asynchronous_executor_wait_decorator>(*this);
+ }
+
+#endif
+
+
+ };
+
+
+ template <typename AE, template <class> class Decorator>
+ struct get_future<asynchronous_executor_wait_decorator<AE, Decorator> > {
+ template <typename T>
+ struct future_type {
+ typedef typename AE::template get_future<AE>::type type;
+ };
+ template <typename T>
+ typename future_type<T>::type&
+ operator()(typename AE::template handle<T>::type & j)
+ { return j.get_future(); }
+ };
+
+}
+}
+
+#include <boost/config/abi_suffix.hpp>
+
+
+#endif
+

Added: sandbox/interthreads/boost/interthreads/wait_thread_decorator.hpp
==============================================================================
--- (empty file)
+++ sandbox/interthreads/boost/interthreads/wait_thread_decorator.hpp 2009-02-08 16:31:36 EST (Sun, 08 Feb 2009)
@@ -0,0 +1,192 @@
+#ifndef BOOST_INTERTHREADS_WAIT_THREAD_DECORATOR__HPP
+#define BOOST_INTERTHREADS_WAIT_THREAD_DECORATOR__HPP
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// (C) Copyright Roland Schwarz 2006.
+// (C) Copyright Vicente J. Botet Escriba 2008-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)
+//
+// 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/interthreads/detail/wait_decorator_function.hpp>
+#include <boost/interthreads/thread_decoration.hpp>
+
+//#define BOOST_INTERTHREADS_THREAD_DECORATOR_MOVE
+
+#include <boost/config/abi_prefix.hpp>
+
+namespace boost {
+namespace interthreads {
+ inline void decorate();
+
+ template <typename T>
+ class basic_thread_decorator {
+ public:
+ typedef T result_type;
+
+ // copy/constructor operators (functor)
+ basic_thread_decorator() {}
+ ~basic_thread_decorator() {}
+ basic_thread_decorator(const basic_thread_decorator& other) {
+ func_ =other.func_;
+ }
+
+ basic_thread_decorator& operator=(const basic_thread_decorator& other) {
+ basic_thread_decorator tmp(other);
+ tmp.swap(*this);
+ return *this;
+ }
+
+#if defined(BOOST_HAS_VARIADIC_TMPL)
+#if defined(BOOST_HAS_RVALUE_REFS)
+ template <typename Callable, typename Arg...>
+ 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 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 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 basic_thread_decorator(Callable f): func_(detail::make_decorator_function(f)) {}
+#else // BOOST_NO_SFINAE
+ template <class Callable>
+ 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 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 basic_thread_decorator(Callable f): func_(detail::make_decorator_function(f)) {}
+#endif // ! BOOST_INTERTHREADS_THREAD_DECORATOR_MOVE
+
+
+ template <typename Callable, typename 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>
+ 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>
+ 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>
+ 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)
+ basic_thread_decorator(basic_thread_decorator&& other) {
+ func_.swap(other.func_);
+ }
+
+ basic_thread_decorator& operator=(basic_thread_decorator&& other) {
+ func_=other.func_;
+ other.func_.reset();
+ return *this;
+ }
+
+ basic_thread_decorator&& move() {
+ return static_cast<basic_thread_decorator&&>(*this);
+ }
+
+#else // ! defined(BOOST_HAS_RVALUE_REFS)
+#ifdef BOOST_INTERTHREADS_THREAD_DECORATOR_MOVE
+ basic_thread_decorator(boost::detail::thread_move_t<basic_thread_decorator> x) {
+ func_=x->func_;
+ x->func_.reset();
+ }
+
+ 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<basic_thread_decorator>() {
+ return move();
+ }
+
+ 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(basic_thread_decorator& x) {
+ func_.swap(x.func_);
+ }
+
+ T operator()() const {
+ decorate();
+ return (*func_)();
+ }
+ private:
+ boost::shared_ptr<detail::decorator_function_base<T> > func_;
+ bool synchronided_;
+ bool started_;
+ boost::condition_variable cond_;
+ };
+
+ typedef basic_thread_decorator<void> thread_decorator;
+
+ template <class F>
+ basic_thread_decorator<typename boost::result_of<F()>::type> make_decorator(F f) {
+#ifdef BOOST_INTERTHREADS_THREAD_DECORATOR_MOVE
+ return move(basic_thread_decorator<typename boost::result_of<F()>::type>(f));
+#else
+ return basic_thread_decorator<typename boost::result_of<F()>::type>(f);
+#endif
+ }
+
+ template <class F>
+#ifdef BOOST_HAS_RVALUE_REFS
+ thread&&
+#else
+ boost::detail::thread_move_t<thread>
+#endif
+ create_decorated_thread(F f) {
+ return thread(make_decorator(f));
+ }
+
+ inline void decorate() {thread_decoration::decorate();}
+
+}
+}
+
+#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