#include <boost/type_traits.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/shared_ptr.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
#if DEAL_II_USE_MT == 1
# if defined(DEAL_II_USE_MT_POSIX)
*/
void dump () {}
- /** @addtogroup Exceptions
- * @{ */
+ /** @addtogroup Exceptions
+ * @{ */
/**
* Exception.
namespace Threads
{
- namespace internal
- {
- /**
- * @internal
- * A type that is used to
- * distinguish argument lists of
- * functions by enumeration.
- */
- template <int> struct int2type
- {
- };
- }
-
-
namespace internal
{
/**
* a function get() that returns
* void.
*/
- template <> struct return_value<void> {
+ template <> struct return_value<void>
+ {
static inline void get () {}
};
}
namespace internal
{
- /**
- * @internal
- * Call arbitrary functions with
- * return type RT. For each number
- * of arguments to these functions,
- * there is an instance of the
- * do_call function in this class
- * that unpacks the argument list
- * (which is passed by reference)
- * and calls the function. The
- * number of arguments is
- * distinguished by the last
- * argument. The return value
- * object is the second last. A
- * second version of the do_call
- * function is used to call member
- * function pointers, in which case
- * there is an additional argument
- * at second position holding a
- * reference to the object with
- * which the member function
- * pointer is to be called.
- *
- * There is a specialization of
- * this class for the case that the
- * return type is void, in which
- * case there is no return value to
- * be set.
- */
template <typename RT>
- struct Caller
+ inline void call (boost::function<RT ()> &function,
+ internal::return_value<RT> &ret_val)
{
- /**
- * Call a function with 0
- * arguments, and set the
- * return value.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &,
- internal::return_value<RT> &ret_val,
- const int2type<0> &)
- {
- ret_val.set ((*fun_ptr) ());
- }
-
- /**
- * Call a member function with
- * 0 arguments, and set the
- * return value.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &,
- internal::return_value<RT> &ret_val,
- const int2type<0> &)
- {
- ret_val.set ((obj.*fun_ptr) ());
- }
-
-
- /**
- * Call a function with 1
- * argument, and set the
- * return value.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<1> &)
- {
- ret_val.set ((*fun_ptr) (arg_list.template get<0>()));
- }
-
- /**
- * Call a member function with
- * 1 argument, and set the
- * return value.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<1> &)
- {
- ret_val.set ((obj.*fun_ptr) (arg_list.template get<0>()));
- }
-
-
-
-
- /**
- * Call a function with 2
- * arguments, and set the
- * return value.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<2> &)
- {
- ret_val.set ((*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>()));
- }
-
- /**
- * Call a member function with
- * 2 arguments, and set the
- * return value.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<2> &)
- {
- ret_val.set ((obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>()));
- }
-
-
- /**
- * Call a function with 3
- * arguments, and set the
- * return value.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<3> &)
- {
- ret_val.set ((*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>()));
- }
+ ret_val.set (function());
+ }
- /**
- * Call a member function with
- * 3 arguments, and set the
- * return value.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<3> &)
- {
- ret_val.set ((obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>()));
- }
+ inline void call (boost::function<void ()> &function,
+ internal::return_value<void> &)
+ {
+ function();
+ }
+ }
- /**
- * Call a function with 4
- * arguments, and set the
- * return value.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<4> &)
- {
- ret_val.set ((*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>()));
- }
- /**
- * Call a member function with
- * 4 arguments, and set the
- * return value.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<4> &)
- {
- ret_val.set ((obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>()));
- }
+ namespace internal
+ {
+ /**
+ * @internal
+ * Construct a pointer to non-member
+ * function based on the template
+ * arguments, and whether the
+ * second argument is a const or
+ * non-const class, dependening on
+ * which the member function will
+ * also me const or
+ * non-const. There are
+ * specializations of this class
+ * for each number of arguments.
+ */
+ template <typename RT, typename ArgList,
+ int length = boost::tuples::length<ArgList>::value>
+ struct fun_ptr_helper;
+
- /**
- * Call a function with 5
- * arguments, and set the
- * return value.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<5> &)
- {
- ret_val.set ((*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>()));
- }
+ /**
+ * @internal
+ * Construct a pointer to non-member
+ * function based on the template
+ * arguments. This is the
+ * specialization for 0 arguments.
+ */
+ template <typename RT, typename ArgList>
+ struct fun_ptr_helper<RT, ArgList, 0>
+ {
+ typedef RT (type) ();
+ };
- /**
- * Call a member function with
- * 5 arguments, and set the
- * return value.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<5> &)
- {
- ret_val.set ((obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>()));
- }
+ /**
+ * @internal
+ * Construct a pointer to non-member
+ * function based on the template
+ * arguments. This is the
+ * specialization for 1 argument.
+ */
+ template <typename RT, typename ArgList>
+ struct fun_ptr_helper<RT, ArgList, 1>
+ {
+ typedef RT (type) (typename boost::tuples::element<0,ArgList>::type);
+ };
- /**
- * Call a function with 6
- * arguments, and set the
- * return value.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<6> &)
- {
- ret_val.set ((*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>()));
- }
- /**
- * Call a member function with
- * 6 arguments, and set the
- * return value.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<6> &)
- {
- ret_val.set ((obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>()));
- }
+ /**
+ * @internal
+ * Construct a pointer to non-member
+ * function based on the template
+ * arguments. This is the
+ * specialization for 2 arguments.
+ */
+ template <typename RT, typename ArgList>
+ struct fun_ptr_helper<RT, ArgList, 2>
+ {
+ typedef RT (type) (typename boost::tuples::element<0,ArgList>::type,
+ typename boost::tuples::element<1,ArgList>::type);
+ };
- /**
- * Call a function with 7
- * arguments, and set the
- * return value.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<7> &)
- {
- ret_val.set ((*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>()));
- }
+ /**
+ * @internal
+ * Construct a pointer to non-member
+ * function based on the template
+ * arguments. This is the
+ * specialization for 3 arguments.
+ */
+ template <typename RT, typename ArgList>
+ struct fun_ptr_helper<RT, ArgList, 3>
+ {
+ typedef RT (type) (typename boost::tuples::element<0,ArgList>::type,
+ typename boost::tuples::element<1,ArgList>::type,
+ typename boost::tuples::element<2,ArgList>::type);
+ };
- /**
- * Call a member function with
- * 7 arguments, and set the
- * return value.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<7> &)
- {
- ret_val.set ((obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>()));
- }
+ /**
+ * @internal
+ * Construct a pointer to non-member
+ * function based on the template
+ * arguments. This is the
+ * specialization for 4 arguments.
+ */
+ template <typename RT, typename ArgList>
+ struct fun_ptr_helper<RT, ArgList, 4>
+ {
+ typedef RT (type) (typename boost::tuples::element<0,ArgList>::type,
+ typename boost::tuples::element<1,ArgList>::type,
+ typename boost::tuples::element<2,ArgList>::type,
+ typename boost::tuples::element<3,ArgList>::type);
+ };
- /**
- * Call a function with 8
- * arguments, and set the
- * return value.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<8> &)
- {
- ret_val.set ((*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>(),
- arg_list.template get<7>()));
- }
- /**
- * Call a member function with
- * 8 arguments, and set the
- * return value.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<8> &)
- {
- ret_val.set ((obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>(),
- arg_list.template get<7>()));
- }
+ /**
+ * @internal
+ * Construct a pointer to non-member
+ * function based on the template
+ * arguments. This is the
+ * specialization for 5 arguments.
+ */
+ template <typename RT, typename ArgList>
+ struct fun_ptr_helper<RT, ArgList, 5>
+ {
+ typedef RT (type) (typename boost::tuples::element<0,ArgList>::type,
+ typename boost::tuples::element<1,ArgList>::type,
+ typename boost::tuples::element<2,ArgList>::type,
+ typename boost::tuples::element<3,ArgList>::type,
+ typename boost::tuples::element<4,ArgList>::type);
+ };
- /**
- * Call a function with 9
- * arguments, and set the
- * return value.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<9> &)
- {
- ret_val.set ((*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>(),
- arg_list.template get<7>(),
- arg_list.template get<8>()));
- }
+ /**
+ * @internal
+ * Construct a pointer to non-member
+ * function based on the template
+ * arguments. This is the
+ * specialization for 6 arguments.
+ */
+ template <typename RT, typename ArgList>
+ struct fun_ptr_helper<RT, ArgList, 6>
+ {
+ typedef RT (type) (typename boost::tuples::element<0,ArgList>::type,
+ typename boost::tuples::element<1,ArgList>::type,
+ typename boost::tuples::element<2,ArgList>::type,
+ typename boost::tuples::element<3,ArgList>::type,
+ typename boost::tuples::element<4,ArgList>::type,
+ typename boost::tuples::element<5,ArgList>::type);
+ };
- /**
- * Call a member function with
- * 9 arguments, and set the
- * return value.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<9> &)
- {
- ret_val.set ((obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>(),
- arg_list.template get<7>(),
- arg_list.template get<8>()));
- }
+ /**
+ * @internal
+ * Construct a pointer to non-member
+ * function based on the template
+ * arguments. This is the
+ * specialization for 7 arguments.
+ */
+ template <typename RT, typename ArgList>
+ struct fun_ptr_helper<RT, ArgList, 7>
+ {
+ typedef RT (type) (typename boost::tuples::element<0,ArgList>::type,
+ typename boost::tuples::element<1,ArgList>::type,
+ typename boost::tuples::element<2,ArgList>::type,
+ typename boost::tuples::element<3,ArgList>::type,
+ typename boost::tuples::element<4,ArgList>::type,
+ typename boost::tuples::element<5,ArgList>::type,
+ typename boost::tuples::element<6,ArgList>::type);
+ };
- /**
- * Call a function with 10
- * arguments, and set the
- * return value.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<10> &)
- {
- ret_val.set ((*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>(),
- arg_list.template get<7>(),
- arg_list.template get<8>(),
- arg_list.template get<9>()));
- }
- /**
- * Call a member function with
- * 10 arguments, and set the
- * return value.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val,
- const int2type<10> &)
- {
- ret_val.set ((obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>(),
- arg_list.template get<7>(),
- arg_list.template get<8>(),
- arg_list.template get<9>()));
- }
+ /**
+ * @internal
+ * Construct a pointer to non-member
+ * function based on the template
+ * arguments. This is the
+ * specialization for 8 arguments.
+ */
+ template <typename RT, typename ArgList>
+ struct fun_ptr_helper<RT, ArgList, 8>
+ {
+ typedef RT (type) (typename boost::tuples::element<0,ArgList>::type,
+ typename boost::tuples::element<1,ArgList>::type,
+ typename boost::tuples::element<2,ArgList>::type,
+ typename boost::tuples::element<3,ArgList>::type,
+ typename boost::tuples::element<4,ArgList>::type,
+ typename boost::tuples::element<5,ArgList>::type,
+ typename boost::tuples::element<6,ArgList>::type,
+ typename boost::tuples::element<7,ArgList>::type);
};
-
-
/**
* @internal
- * Call arbitrary functions with
- * void return type. For each
- * number of arguments to these
- * functions, there is an instance
- * of the do_call function in this
- * class that unpacks the argument
- * list (which is passed by
- * reference) and calls the
- * function. The number of
- * arguments is distinguished by
- * the last argument. The return
- * value object is the second last,
- * but since the return type is
- * void, this is of course simply
- * ignored. A second version of the
- * do_call function is used to call
- * member function pointers, in
- * which case there is an
- * additional argument at second
- * position holding a reference to
- * the object with which the member
- * function pointer is to be
- * called.
+ * Construct a pointer to non-member
+ * function based on the template
+ * arguments. This is the
+ * specialization for 9 arguments.
*/
- template <>
- struct Caller<void>
+ template <typename RT, typename ArgList>
+ struct fun_ptr_helper<RT, ArgList, 9>
{
- /**
- * Call a void function with 0
- * arguments.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &,
- internal::return_value<void> &,
- const int2type<0> &)
- {
- (*fun_ptr) ();
- }
+ typedef RT (type) (typename boost::tuples::element<0,ArgList>::type,
+ typename boost::tuples::element<1,ArgList>::type,
+ typename boost::tuples::element<2,ArgList>::type,
+ typename boost::tuples::element<3,ArgList>::type,
+ typename boost::tuples::element<4,ArgList>::type,
+ typename boost::tuples::element<5,ArgList>::type,
+ typename boost::tuples::element<6,ArgList>::type,
+ typename boost::tuples::element<7,ArgList>::type,
+ typename boost::tuples::element<8,ArgList>::type);
+ };
- /**
- * Call a void member function
- * with 0 arguments.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &,
- internal::return_value<void> &,
- const int2type<0> &)
- {
- (obj.*fun_ptr) ();
- }
- /**
- * Call a void function with 1
- * argument.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<1> &)
- {
- (*fun_ptr) (arg_list.template get<0>());
- }
-
- /**
- * Call a void member function
- * with 1 argument.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<1> &)
- {
- (obj.*fun_ptr) (arg_list.template get<0>());
- }
-
-
-
-
- /**
- * Call a void function with 2
- * arguments.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<2> &)
- {
- (*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>());
- }
-
- /**
- * Call a void member function
- * with 2 arguments.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<2> &)
- {
- (obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>());
- }
-
-
- /**
- * Call a void function with 3
- * arguments.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<3> &)
- {
- (*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>());
- }
-
- /**
- * Call a void member function
- * with 3 arguments.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<3> &)
- {
- (obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>());
- }
-
-
- /**
- * Call a void function with 4
- * arguments.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<4> &)
- {
- (*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>());
- }
-
- /**
- * Call a void member function
- * with 4 arguments.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<4> &)
- {
- (obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>());
- }
+ /**
+ * @internal
+ * Construct a pointer to non-member
+ * function based on the template
+ * arguments. This is the
+ * specialization for 10 arguments.
+ */
+ template <typename RT, typename ArgList>
+ struct fun_ptr_helper<RT, ArgList, 10>
+ {
+ typedef RT (type) (typename boost::tuples::element<0,ArgList>::type,
+ typename boost::tuples::element<1,ArgList>::type,
+ typename boost::tuples::element<2,ArgList>::type,
+ typename boost::tuples::element<3,ArgList>::type,
+ typename boost::tuples::element<4,ArgList>::type,
+ typename boost::tuples::element<5,ArgList>::type,
+ typename boost::tuples::element<6,ArgList>::type,
+ typename boost::tuples::element<7,ArgList>::type,
+ typename boost::tuples::element<8,ArgList>::type,
+ typename boost::tuples::element<9,ArgList>::type);
+ };
+
- /**
- * Call a void function with 5
- * arguments.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<5> &)
- {
- (*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>());
- }
+ /**
+ * @internal
+ * Construct a pointer to
+ * non-member function based on the
+ * template arguments. We do this
+ * by dispatching to the
+ * fun_ptr_helper classes that are
+ * overloaded on the number of
+ * elements.
+ *
+ * Note that the last template
+ * argument for the
+ * fun_ptr_helper class is
+ * automatically computed in the
+ * default argument to the general
+ * template.
+ */
+ template <typename RT, typename ArgList>
+ struct fun_ptr
+ {
+ typedef typename fun_ptr_helper<RT,ArgList>::type type;
+ };
+ }
- /**
- * Call a void member function
- * with 5 arguments.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<5> &)
- {
- (obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>());
- }
- /**
- * Call a void function with 6
- * arguments.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<6> &)
- {
- (*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>());
- }
+ namespace internal
+ {
+#if (DEAL_II_USE_MT == 1)
+# if defined(DEAL_II_USE_MT_POSIX)
+ /**
+ * @internal
+ * Base class describing a
+ * thread. This is the basic
+ * class abstracting the
+ * operating system's POSIX
+ * implementation into a C++
+ * class. It provides a mechanism
+ * to start a new thread, as well
+ * as for joining it.
+ *
+ * @author Wolfgang Bangerth, 2003
+ */
+ struct thread_description_base
+ {
+ private:
/**
- * Call a void member function
- * with 6 arguments.
+ * Variable holding the data
+ * the operating system needs
+ * to work with a thread.
*/
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<6> &)
- {
- (obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>());
- }
-
+ pthread_t thread;
/**
- * Call a void function with 7
- * arguments.
+ * Store whether the
+ * <tt>join()</tt> member function
+ * as already been called. If
+ * <tt>true</tt>, then <tt>join</tt>
+ * will return immediately,
+ * otherwise it needs to go
+ * through a call to the
+ * operating system.
+ *
+ * This class is generated
+ * exactly once per thread,
+ * but is kept in the
+ * background: user's should
+ * not directly access this
+ * class. Access to it is
+ * performed through counted
+ * pointers, both from
+ * <tt>Thread<></tt> objects as
+ * well as from the thread
+ * entry point function on
+ * the new thread. It is only
+ * deleted when all users
+ * have freed it, which means
+ * that also the new thread
+ * has ended.
*/
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<7> &)
- {
- (*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>());
- }
+ mutable volatile bool was_joined;
/**
- * Call a void member function
- * with 7 arguments.
+ * Mutex used to synchronise
+ * calls to the <tt>join()</tt>
+ * function.
*/
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<7> &)
- {
- (obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>());
- }
+ mutable ThreadMutex join_mutex;
+ public:
/**
- * Call a void function with 8
- * arguments.
+ * Constructor.
*/
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<8> &)
- {
- (*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>(),
- arg_list.template get<7>());
- }
+ thread_description_base ();
/**
- * Call a void member function
- * with 8 arguments.
+ * Destructor.
*/
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<8> &)
- {
- (obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>(),
- arg_list.template get<7>());
- }
-
+ virtual ~thread_description_base ();
/**
- * Call a void function with 9
- * arguments.
+ * Create a new thread with
+ * the given thread entry
+ * point and arguments. Store
+ * the result of the
+ * operation in the
+ * <tt>thread</tt> member variable
+ * for further use.
*/
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<9> &)
- {
- (*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>(),
- arg_list.template get<7>(),
- arg_list.template get<8>());
- }
+ void create (void * (*p) (void *), void *d);
/**
- * Call a void member function
- * with 9 arguments.
+ * Join a thread, i.e. wait
+ * for it to finish. This
+ * function can safely be
+ * called from different
+ * threads at the same time,
+ * and can also be called
+ * more than once.
*/
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<9> &)
- {
- (obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>(),
- arg_list.template get<7>(),
- arg_list.template get<8>());
- }
+ void join () const;
+ /**
+ * Exception
+ */
+ DeclException1 (ExcThreadCreationError,
+ int,
+ << "pthread_create return code is " << arg1);
+ };
- /**
- * Call a void function with 10
- * arguments.
- */
- template <typename PFun, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<10> &)
- {
- (*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>(),
- arg_list.template get<7>(),
- arg_list.template get<8>(),
- arg_list.template get<9>());
- }
+# else // some other threading model
+# error Not Implemented
+# endif // defined(DEAL_II_USE_MT_POSIX)
- /**
- * Call a void member function
- * with 10 arguments.
- */
- template <typename PFun, typename C, typename ArgList>
- static inline void do_call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<void> &,
- const int2type<10> &)
- {
- (obj.*fun_ptr) (arg_list.template get<0>(),
- arg_list.template get<1>(),
- arg_list.template get<2>(),
- arg_list.template get<3>(),
- arg_list.template get<4>(),
- arg_list.template get<5>(),
- arg_list.template get<6>(),
- arg_list.template get<7>(),
- arg_list.template get<8>(),
- arg_list.template get<9>());
- }
- };
-
-
+#else // no threading enabled
- /**
- * @internal
- * Call an arbitrary function by
- * dispatching to the functions in
- * the Caller class based on the
- * number of elements in the
- * argument list and the return
- * type.
- */
- template <typename RT, typename PFun, typename ArgList>
- inline void call (PFun fun_ptr,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val)
+ struct thread_description_base
{
- Caller<RT>::do_call (fun_ptr, arg_list, ret_val,
- int2type<boost::tuples::length<ArgList>::value>());
- }
-
+ static void join () {}
+ };
+
+#endif
-
/**
* @internal
- * Call an arbitrary member
- * function by dispatching to the
- * functions in the Caller class
- * based on the number of elements
- * in the argument list and the
- * return type.
+ * Class derived from
+ * thread_description_base()
+ * that also provides the
+ * possibility to store a return
+ * value.
+ *
+ * @author Wolfgang Bangerth, 2003
*/
- template <typename RT, typename PFun, typename C, typename ArgList>
- inline void call (PFun fun_ptr,
- C &obj,
- ArgList &arg_list,
- internal::return_value<RT> &ret_val)
+ template <typename RT>
+ struct thread_description : public thread_description_base
{
- Caller<RT>::do_call (fun_ptr, obj, arg_list, ret_val,
- int2type<boost::tuples::length<ArgList>::value>());
- }
+ return_value<RT> ret_val;
+ };
+
+ // forward declare another class
+ template <typename> struct fun_wrapper;
}
- namespace internal
+ /**
+ * User visible class describing a
+ * thread. Relays all real calls to
+ * the internal thread object
+ * abstracting the operating
+ * system's functions, to which it
+ * keeps a shared pointer. This
+ * object can be freely copied
+ * around in user space.
+ *
+ * The default value of the
+ * template argument is <tt>void</tt>,
+ * so if the function you are
+ * calling on a new thread has no
+ * return value, you can omit the
+ * template argument.
+ *
+ * @author Wolfgang Bangerth, 2003
+ */
+ template <typename RT = void>
+ class Thread
{
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments, and whether the
- * second argument is a const or
- * non-const class, dependening on
- * which the member function will
- * also me const or
- * non-const. There are
- * specializations of this class
- * for each number of arguments,
- * and the const and non-const
- * versions.
- */
- template <typename RT, class C, typename ArgList,
- int length = boost::tuples::length<ArgList>::value>
- struct mem_fun_ptr_helper;
-
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 0 arguments
- * and non-const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, C, ArgList, 0>
- {
- typedef RT (C::*type) ();
- };
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 0 arguments
- * and const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, const C, ArgList, 0>
- {
- typedef RT (C::*type) () const;
- };
-
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 1 argument
- * and non-const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, C, ArgList, 1>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type);
- };
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 1 argument
- * and const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, const C, ArgList, 1>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type) const;
- };
-
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 2 arguments
- * and non-const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, C, ArgList, 2>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type);
- };
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 2 arguments
- * and const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, const C, ArgList, 2>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type) const;
- };
-
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 3 arguments
- * and non-const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, C, ArgList, 3>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type);
- };
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 3 arguments
- * and const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, const C, ArgList, 3>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type) const;
- };
-
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 4 arguments
- * and non-const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, C, ArgList, 4>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type);
- };
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 4 arguments
- * and const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, const C, ArgList, 4>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type) const;
- };
-
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 5 arguments
- * and non-const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, C, ArgList, 5>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type);
- };
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 5 arguments
- * and const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, const C, ArgList, 5>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type) const;
- };
-
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 6 arguments
- * and non-const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, C, ArgList, 6>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type,
- typename boost::tuples::element<5,ArgList>::type);
- };
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 6 arguments
- * and const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, const C, ArgList, 6>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type,
- typename boost::tuples::element<5,ArgList>::type) const;
- };
-
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 7 arguments
- * and non-const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, C, ArgList, 7>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type,
- typename boost::tuples::element<5,ArgList>::type,
- typename boost::tuples::element<6,ArgList>::type);
- };
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 7 arguments
- * and const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, const C, ArgList, 7>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type,
- typename boost::tuples::element<5,ArgList>::type,
- typename boost::tuples::element<6,ArgList>::type) const;
- };
-
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 8 arguments
- * and non-const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, C, ArgList, 8>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type,
- typename boost::tuples::element<5,ArgList>::type,
- typename boost::tuples::element<6,ArgList>::type,
- typename boost::tuples::element<7,ArgList>::type);
- };
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 8 arguments
- * and const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, const C, ArgList, 8>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type,
- typename boost::tuples::element<5,ArgList>::type,
- typename boost::tuples::element<6,ArgList>::type,
- typename boost::tuples::element<7,ArgList>::type) const;
- };
-
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 9 arguments
- * and non-const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, C, ArgList, 9>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type,
- typename boost::tuples::element<5,ArgList>::type,
- typename boost::tuples::element<6,ArgList>::type,
- typename boost::tuples::element<7,ArgList>::type,
- typename boost::tuples::element<8,ArgList>::type);
- };
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 9 arguments
- * and const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, const C, ArgList, 9>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type,
- typename boost::tuples::element<5,ArgList>::type,
- typename boost::tuples::element<6,ArgList>::type,
- typename boost::tuples::element<7,ArgList>::type,
- typename boost::tuples::element<8,ArgList>::type) const;
- };
-
-
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 10 arguments
- * and non-const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, C, ArgList, 10>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type,
- typename boost::tuples::element<5,ArgList>::type,
- typename boost::tuples::element<6,ArgList>::type,
- typename boost::tuples::element<7,ArgList>::type,
- typename boost::tuples::element<8,ArgList>::type,
- typename boost::tuples::element<9,ArgList>::type);
- };
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments. This is the
- * specialization for 10 arguments
- * and const member functions.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr_helper<RT, const C, ArgList, 10>
- {
- typedef RT (C::*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type,
- typename boost::tuples::element<5,ArgList>::type,
- typename boost::tuples::element<6,ArgList>::type,
- typename boost::tuples::element<7,ArgList>::type,
- typename boost::tuples::element<8,ArgList>::type,
- typename boost::tuples::element<9,ArgList>::type) const;
- };
-
-
-
- /**
- * @internal
- * Construct a pointer to member
- * function based on the template
- * arguments, and whether the
- * second argument is a const or
- * non-const class, dependening on
- * which the member function will
- * also me const or non-const. We
- * do this by dispatching to the
- * mem_fun_ptr_helper classes that
- * are overloaded on the number of
- * elements and the const/non-const
- * decision.
- *
- * Note that the last template
- * argument for the
- * mem_fun_ptr_helper class is
- * automatically computed in the
- * default argument to the general
- * template.
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_ptr
- {
- typedef typename mem_fun_ptr_helper<RT,C,ArgList>::type type;
- };
- }
-
-
- namespace internal
- {
- /**
- * @internal
- * Construct a pointer to non-member
- * function based on the template
- * arguments, and whether the
- * second argument is a const or
- * non-const class, dependening on
- * which the member function will
- * also me const or
- * non-const. There are
- * specializations of this class
- * for each number of arguments.
- */
- template <typename RT, typename ArgList,
- int length = boost::tuples::length<ArgList>::value>
- struct fun_ptr_helper;
-
-
- /**
- * @internal
- * Construct a pointer to non-member
- * function based on the template
- * arguments. This is the
- * specialization for 0 arguments.
- */
- template <typename RT, typename ArgList>
- struct fun_ptr_helper<RT, ArgList, 0>
- {
- typedef RT (*type) ();
- };
-
-
- /**
- * @internal
- * Construct a pointer to non-member
- * function based on the template
- * arguments. This is the
- * specialization for 1 argument.
- */
- template <typename RT, typename ArgList>
- struct fun_ptr_helper<RT, ArgList, 1>
- {
- typedef RT (*type) (typename boost::tuples::element<0,ArgList>::type);
- };
-
-
- /**
- * @internal
- * Construct a pointer to non-member
- * function based on the template
- * arguments. This is the
- * specialization for 2 arguments.
- */
- template <typename RT, typename ArgList>
- struct fun_ptr_helper<RT, ArgList, 2>
- {
- typedef RT (*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type);
- };
-
-
- /**
- * @internal
- * Construct a pointer to non-member
- * function based on the template
- * arguments. This is the
- * specialization for 3 arguments.
- */
- template <typename RT, typename ArgList>
- struct fun_ptr_helper<RT, ArgList, 3>
- {
- typedef RT (*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type);
- };
-
-
- /**
- * @internal
- * Construct a pointer to non-member
- * function based on the template
- * arguments. This is the
- * specialization for 4 arguments.
- */
- template <typename RT, typename ArgList>
- struct fun_ptr_helper<RT, ArgList, 4>
- {
- typedef RT (*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type);
- };
-
-
- /**
- * @internal
- * Construct a pointer to non-member
- * function based on the template
- * arguments. This is the
- * specialization for 5 arguments.
- */
- template <typename RT, typename ArgList>
- struct fun_ptr_helper<RT, ArgList, 5>
- {
- typedef RT (*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type);
- };
-
-
- /**
- * @internal
- * Construct a pointer to non-member
- * function based on the template
- * arguments. This is the
- * specialization for 6 arguments.
- */
- template <typename RT, typename ArgList>
- struct fun_ptr_helper<RT, ArgList, 6>
- {
- typedef RT (*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type,
- typename boost::tuples::element<5,ArgList>::type);
- };
-
-
- /**
- * @internal
- * Construct a pointer to non-member
- * function based on the template
- * arguments. This is the
- * specialization for 7 arguments.
- */
- template <typename RT, typename ArgList>
- struct fun_ptr_helper<RT, ArgList, 7>
- {
- typedef RT (*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type,
- typename boost::tuples::element<5,ArgList>::type,
- typename boost::tuples::element<6,ArgList>::type);
- };
-
-
- /**
- * @internal
- * Construct a pointer to non-member
- * function based on the template
- * arguments. This is the
- * specialization for 8 arguments.
- */
- template <typename RT, typename ArgList>
- struct fun_ptr_helper<RT, ArgList, 8>
- {
- typedef RT (*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type,
- typename boost::tuples::element<5,ArgList>::type,
- typename boost::tuples::element<6,ArgList>::type,
- typename boost::tuples::element<7,ArgList>::type);
- };
-
-
- /**
- * @internal
- * Construct a pointer to non-member
- * function based on the template
- * arguments. This is the
- * specialization for 9 arguments.
- */
- template <typename RT, typename ArgList>
- struct fun_ptr_helper<RT, ArgList, 9>
- {
- typedef RT (*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type,
- typename boost::tuples::element<5,ArgList>::type,
- typename boost::tuples::element<6,ArgList>::type,
- typename boost::tuples::element<7,ArgList>::type,
- typename boost::tuples::element<8,ArgList>::type);
- };
-
-
-
- /**
- * @internal
- * Construct a pointer to non-member
- * function based on the template
- * arguments. This is the
- * specialization for 10 arguments.
- */
- template <typename RT, typename ArgList>
- struct fun_ptr_helper<RT, ArgList, 10>
- {
- typedef RT (*type) (typename boost::tuples::element<0,ArgList>::type,
- typename boost::tuples::element<1,ArgList>::type,
- typename boost::tuples::element<2,ArgList>::type,
- typename boost::tuples::element<3,ArgList>::type,
- typename boost::tuples::element<4,ArgList>::type,
- typename boost::tuples::element<5,ArgList>::type,
- typename boost::tuples::element<6,ArgList>::type,
- typename boost::tuples::element<7,ArgList>::type,
- typename boost::tuples::element<8,ArgList>::type,
- typename boost::tuples::element<9,ArgList>::type);
- };
-
-
-
- /**
- * @internal
- * Construct a pointer to
- * non-member function based on the
- * template arguments. We do this
- * by dispatching to the
- * fun_ptr_helper classes that are
- * overloaded on the number of
- * elements.
- *
- * Note that the last template
- * argument for the
- * fun_ptr_helper class is
- * automatically computed in the
- * default argument to the general
- * template.
- */
- template <typename RT, typename ArgList>
- struct fun_ptr
- {
- typedef typename fun_ptr_helper<RT,ArgList>::type type;
- };
- }
-
-
- namespace internal
- {
- /**
- * @internal
- * Extract the Nth element of the
- * type list and make it a
- * reference.
- */
- template <int N, typename Tuple>
- struct add_reference_to_Nth
- {
- typedef typename boost::tuples::element<N,Tuple>::type ArgType;
- typedef typename boost::add_reference<ArgType>::type type;
- };
-
- /**
- * @internal
- * Specializations of this template
- * declare a typedef to a tuple
- * type that has the same basic
- * types as the first template
- * argument, but all references
- * instead of values. The second
- * argument is used to distinguish
- * between the lengths of argument
- * lists. The default argument
- * makes it possible to omit this
- * length argument.
- */
- template <typename Tuple, int = boost::tuples::length<Tuple>::value>
- struct tie_args_helper;
-
-
- /**
- * @internal
- * Make a tuple type of all
- * references out of the given
- * tuple. Specialization for tuple
- * of length 0.
- */
- template <typename Tuple>
- struct tie_args_helper<Tuple,0>
- {
- typedef Tuple type;
- };
-
-
- /**
- * @internal
- * Make a tuple type of all
- * references out of the given
- * tuple. Specialization for tuple
- * of length 1.
- */
- template <typename Tuple>
- struct tie_args_helper<Tuple,1>
- {
- typedef
- boost::tuple<typename add_reference_to_Nth<0,Tuple>::type>
- type;
- };
-
-
- /**
- * @internal
- * Make a tuple type of all
- * references out of the given
- * tuple. Specialization for tuple
- * of length 2.
- */
- template <typename Tuple>
- struct tie_args_helper<Tuple,2>
- {
- typedef
- boost::tuple<typename add_reference_to_Nth<0,Tuple>::type,
- typename add_reference_to_Nth<1,Tuple>::type>
- type;
- };
-
-
- /**
- * @internal
- * Make a tuple type of all
- * references out of the given
- * tuple. Specialization for tuple
- * of length 3.
- */
- template <typename Tuple>
- struct tie_args_helper<Tuple,3>
- {
- typedef
- boost::tuple<typename add_reference_to_Nth<0,Tuple>::type,
- typename add_reference_to_Nth<1,Tuple>::type,
- typename add_reference_to_Nth<2,Tuple>::type>
- type;
- };
-
-
- /**
- * @internal
- * Make a tuple type of all
- * references out of the given
- * tuple. Specialization for tuple
- * of length 4.
- */
- template <typename Tuple>
- struct tie_args_helper<Tuple,4>
- {
- typedef
- boost::tuple<typename add_reference_to_Nth<0,Tuple>::type,
- typename add_reference_to_Nth<1,Tuple>::type,
- typename add_reference_to_Nth<2,Tuple>::type,
- typename add_reference_to_Nth<3,Tuple>::type>
- type;
- };
-
-
- /**
- * @internal
- * Make a tuple type of all
- * references out of the given
- * tuple. Specialization for tuple
- * of length 5.
- */
- template <typename Tuple>
- struct tie_args_helper<Tuple,5>
- {
- typedef
- boost::tuple<typename add_reference_to_Nth<0,Tuple>::type,
- typename add_reference_to_Nth<1,Tuple>::type,
- typename add_reference_to_Nth<2,Tuple>::type,
- typename add_reference_to_Nth<3,Tuple>::type,
- typename add_reference_to_Nth<4,Tuple>::type>
- type;
- };
-
-
- /**
- * @internal
- * Make a tuple type of all
- * references out of the given
- * tuple. Specialization for tuple
- * of length 6.
- */
- template <typename Tuple>
- struct tie_args_helper<Tuple,6>
- {
- typedef
- boost::tuple<typename add_reference_to_Nth<0,Tuple>::type,
- typename add_reference_to_Nth<1,Tuple>::type,
- typename add_reference_to_Nth<2,Tuple>::type,
- typename add_reference_to_Nth<3,Tuple>::type,
- typename add_reference_to_Nth<4,Tuple>::type,
- typename add_reference_to_Nth<5,Tuple>::type>
- type;
- };
-
-
-
- /**
- * @internal
- * Make a tuple type of all
- * references out of the given
- * tuple. Specialization for tuple
- * of length 7.
- */
- template <typename Tuple>
- struct tie_args_helper<Tuple,7>
- {
- typedef
- boost::tuple<typename add_reference_to_Nth<0,Tuple>::type,
- typename add_reference_to_Nth<1,Tuple>::type,
- typename add_reference_to_Nth<2,Tuple>::type,
- typename add_reference_to_Nth<3,Tuple>::type,
- typename add_reference_to_Nth<4,Tuple>::type,
- typename add_reference_to_Nth<5,Tuple>::type,
- typename add_reference_to_Nth<6,Tuple>::type>
- type;
- };
-
-
- /**
- * @internal
- * Make a tuple type of all
- * references out of the given
- * tuple. Specialization for tuple
- * of length 8.
- */
- template <typename Tuple>
- struct tie_args_helper<Tuple,8>
- {
- typedef
- boost::tuple<typename add_reference_to_Nth<0,Tuple>::type,
- typename add_reference_to_Nth<1,Tuple>::type,
- typename add_reference_to_Nth<2,Tuple>::type,
- typename add_reference_to_Nth<3,Tuple>::type,
- typename add_reference_to_Nth<4,Tuple>::type,
- typename add_reference_to_Nth<5,Tuple>::type,
- typename add_reference_to_Nth<6,Tuple>::type,
- typename add_reference_to_Nth<7,Tuple>::type>
- type;
- };
-
-
- /**
- * @internal
- * Make a tuple type of all
- * references out of the given
- * tuple. Specialization for tuple
- * of length 9.
- */
- template <typename Tuple>
- struct tie_args_helper<Tuple,9>
- {
- typedef
- boost::tuple<typename add_reference_to_Nth<0,Tuple>::type,
- typename add_reference_to_Nth<1,Tuple>::type,
- typename add_reference_to_Nth<2,Tuple>::type,
- typename add_reference_to_Nth<3,Tuple>::type,
- typename add_reference_to_Nth<4,Tuple>::type,
- typename add_reference_to_Nth<5,Tuple>::type,
- typename add_reference_to_Nth<6,Tuple>::type,
- typename add_reference_to_Nth<7,Tuple>::type,
- typename add_reference_to_Nth<8,Tuple>::type>
- type;
- };
-
-
- /**
- * @internal
- * Make a tuple type of all
- * references out of the given
- * tuple. Specialization for tuple
- * of length 10.
- */
- template <typename Tuple>
- struct tie_args_helper<Tuple,10>
- {
- typedef
- boost::tuple<typename add_reference_to_Nth<0,Tuple>::type,
- typename add_reference_to_Nth<1,Tuple>::type,
- typename add_reference_to_Nth<2,Tuple>::type,
- typename add_reference_to_Nth<3,Tuple>::type,
- typename add_reference_to_Nth<4,Tuple>::type,
- typename add_reference_to_Nth<5,Tuple>::type,
- typename add_reference_to_Nth<6,Tuple>::type,
- typename add_reference_to_Nth<7,Tuple>::type,
- typename add_reference_to_Nth<8,Tuple>::type,
- typename add_reference_to_Nth<9,Tuple>::type>
- type;
- };
-
-
-
- /**
- * @internal
- * Declare a typedef to a tuple
- * type that has the same basic
- * types as the template
- * argument, but all references
- * instead of values.
- *
- * Do so by redirecting to the
- * tie_args_helper specializations;
- * note that the second argument of
- * these templates is computed
- * automatically by the default
- * argument specification.
- */
- template <typename Tuple>
- struct tie_args
- {
- typedef typename tie_args_helper<Tuple>::type type;
- };
- }
-
-
-#if (DEAL_II_USE_MT == 1)
-# if defined(DEAL_II_USE_MT_POSIX)
-
- namespace internal
- {
- /**
- * @internal
- * Base class describing a
- * thread. This is the basic
- * class abstracting the
- * operating system's POSIX
- * implementation into a C++
- * class. It provides a mechanism
- * to start a new thread, as well
- * as for joining it.
- *
- * @author Wolfgang Bangerth, 2003
- */
- struct thread_description_base
- {
- private:
- /**
- * Variable holding the data
- * the operating system needs
- * to work with a thread.
- */
- pthread_t thread;
-
- /**
- * Store whether the
- * <tt>join()</tt> member function
- * as already been called. If
- * <tt>true</tt>, then <tt>join</tt>
- * will return immediately,
- * otherwise it needs to go
- * through a call to the
- * operating system.
- *
- * This class is generated
- * exactly once per thread,
- * but is kept in the
- * background: user's should
- * not directly access this
- * class. Access to it is
- * performed through counted
- * pointers, both from
- * <tt>Thread<></tt> objects as
- * well as from the thread
- * entry point function on
- * the new thread. It is only
- * deleted when all users
- * have freed it, which means
- * that also the new thread
- * has ended.
- */
- mutable volatile bool was_joined;
-
- /**
- * Mutex used to synchronise
- * calls to the <tt>join()</tt>
- * function.
- */
- mutable ThreadMutex join_mutex;
-
- public:
-
- /**
- * Constructor.
- */
- thread_description_base ();
-
- /**
- * Destructor.
- */
- virtual ~thread_description_base ();
-
- /**
- * Create a new thread with
- * the given thread entry
- * point and arguments. Store
- * the result of the
- * operation in the
- * <tt>thread</tt> member variable
- * for further use.
- */
- void create (void * (*p) (void *), void *d);
-
- /**
- * Join a thread, i.e. wait
- * for it to finish. This
- * function can safely be
- * called from different
- * threads at the same time,
- * and can also be called
- * more than once.
- */
- void join () const;
-
- /**
- * Exception
- */
- DeclException1 (ExcThreadCreationError,
- int,
- << "pthread_create return code is " << arg1);
- };
-
-# else // some other threading model
-# error Not Implemented
-# endif // defined(DEAL_II_USE_MT_POSIX)
-
- /**
- * @internal
- * Class derived from
- * thread_description_base()
- * that also provides the
- * possibility to store a return
- * value.
- *
- * @author Wolfgang Bangerth, 2003
- */
- template <typename RT>
- struct thread_description : public thread_description_base
- {
- return_value<RT> ret_val;
- };
-
- // forward declare another class
- template <typename, typename> struct wrapper_base;
- }
-
-
-
- /**
- * User visible class describing a
- * thread. Relays all real calls to
- * the internal thread object
- * abstracting the operating
- * system's functions, to which it
- * keeps a shared pointer. This
- * object can be freely copied
- * around in user space.
- *
- * The default value of the
- * template argument is <tt>void</tt>,
- * so if the function you are
- * calling on a new thread has no
- * return value, you can omit the
- * template argument.
- *
- * @author Wolfgang Bangerth, 2003
- */
- template <typename RT = void>
- class Thread
- {
- /**
- * Construct a thread object
- * with a pointer to an
- * internal thread object. This
- * is the constructor used to
- * the <tt>spawn</tt> family of
- * functions.
- *
- * We would like to make this
- * constructor private and only
- * grant the
- * <tt>wrapper_base::fire_up</tt>
- * function friendship, but
- * granting friendship to
- * functions in other
- * namespaces doesn't work with
- * some compilers, so only do
- * so if the configure script
- * decided that this is safe.
- */
-#if defined(DEAL_II_NAMESP_TEMPL_FRIEND_BUG2) || defined(DEAL_II_NAMESP_TEMPL_FRIEND_BUG)
- public:
-#endif
- Thread (const boost::shared_ptr<internal::thread_description<RT> > &td)
- : thread_descriptor (td) {}
-
- public:
-
- /**
- * Default constructor. You
- * can't do much with a thread
- * object constructed this way,
- * except for assigning it a
- * thread object that holds
- * data created by the
- * <tt>spawn</tt> functions.
- */
- Thread () {}
-
- /**
- * Join the thread represented
- * by this object, i.e. wait
- * for it to finish. You can't
- * call this function if you
- * have used the default
- * constructor of this class
- * and have not assigned a
- * thread object to it.
- */
- void join () const {
- AssertThrow (thread_descriptor, ExcNoThread());
- thread_descriptor->join ();
- }
-
- /**
- * Get the return value of the
- * function of the
- * thread. Since this is only
- * available once the thread
- * finishes, this implicitely
- * also calls <tt>join()</tt>.
- */
- RT return_value () {
- join ();
- return thread_descriptor->ret_val.get();
- }
-
-
- /**
- * Check for equality of thread
- * objects. Since objects of
- * this class store an implicit
- * pointer to an object that
- * exists exactly once for each
- * thread, the check is simply
- * to compare these pointers.
- */
- bool operator == (const Thread &t) {
- return thread_descriptor == t.thread_descriptor;
- }
-
- /** @addtogroup Exceptions
- * @{ */
-
- /**
- * Exception
- */
- DeclException0 (ExcNoThread);
- //@}
- private:
- /**
- * Shared pointer to the object
- * representing the thread, and
- * abstracting operating system
- * functions to work on
- * it. Boost's shared pointer
- * implementation will make
- * sure that that object lives
- * as long as there is at least
- * one subscriber to it.
- */
- boost::shared_ptr<internal::thread_description<RT> > thread_descriptor;
-
-#if !defined(DEAL_II_NAMESP_TEMPL_FRIEND_BUG2) && !defined(DEAL_II_NAMESP_TEMPL_FRIEND_BUG)
- template <typename, typename> friend struct internal::wrapper_base;
-#endif
- };
-
-
-
- namespace internal
- {
-
- /**
- * @internal
- * Base class for the classes
- * wrapping function pointers and
- * arguments for non-member and
- * member functions. The first
- * template class denotes the
- * return type of the function
- * being called. The second one
- * is a class that provides a
- * function <tt>entry_point</tt>,
- * which will be used as an entry
- * point for the new thread. In
- * the classes derived from this
- * one, the second template
- * argument is actually the
- * derived class itself, using
- * something like the
- * Barton-Nackman trick.
- *
- * @author Wolfgang Bangerth, 2003
- */
- template <typename RT, typename EntryPointClass>
- struct wrapper_base
- {
-
- /**
- * Start a new thread, wait
- * until it has copied the
- * data out of this object,
- * and return the thread
- * descriptor.
- */
- Thread<RT> fire_up () {
- thread_descriptor =
- DescriptionPointer(new internal::thread_description<RT>());
-
- ThreadMutex::ScopedLock lock (mutex);
- thread_descriptor->create (&EntryPointClass::entry_point,
- (void *)this);
- condition.wait (mutex);
-
- return thread_descriptor;
- }
-
- protected:
- /**
- * Typedef for shared
- * pointers to the objects
- * describing threads on the
- * OS level.
- */
- typedef
- boost::shared_ptr<internal::thread_description<RT> >
- DescriptionPointer;
-
- /**
- * Shared pointer to the
- * unique object describing a
- * thread on the OS level.
- */
- DescriptionPointer thread_descriptor;
-
- /**
- * Mutex and condition
- * variable used to
- * synchronise calling and
- * called thread.
- */
- mutable ThreadMutex mutex;
- mutable ThreadCondition condition;
- };
-
-
- /**
- * @internal
- * Wrap the arguments to a
- * non-member or static member
- * function and provide an entry
- * point for a new thread that
- * unwraps this data and calls
- * the function with them.
- *
- * @author Wolfgang Bangerth, 2003
- */
- template <typename RT, typename ArgList>
- struct fun_wrapper : public wrapper_base<RT, fun_wrapper<RT,ArgList> >
- {
- /**
- * Typedef for the type of
- * the function to be called
- * on the new thread.
- */
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- /**
- * Typedef for a typelist of
- * reference arguments to the
- * function to be called.
- */
- typedef typename internal::tie_args<ArgList>::type ArgReferences;
-
- /**
- * Constructor. Store the
- * necessary information
- * about the function to be
- * called and with which
- * arguments.
- *
- * Pass down the address of
- * this class's thread entry
- * point function. This way,
- * we can ensure that object
- * and thread entry point
- * function always are in
- * synch with respect to
- * their knowledge of the
- * types involved.
- */
- fun_wrapper (FunPtr fun_ptr,
- const ArgReferences &args)
- : fun_ptr (fun_ptr),
- args (args) {}
- private:
- /**
- * Default constructor. Made
- * private and not
- * implemented to prevent
- * calling.
- */
- fun_wrapper ();
-
- /**
- * Copy constructor. Made
- * private and not
- * implemented to prevent
- * calling.
- */
- fun_wrapper (const fun_wrapper &);
-
- /**
- * Pointer to the function to
- * be called on the new
- * thread.
- */
- FunPtr fun_ptr;
-
- /**
- * References to the
- * arguments with which the
- * function is to be called.
- */
- ArgReferences args;
-
-
- /**
- * Entry point for the new
- * thread.
- */
- static void * entry_point (void *arg)
- {
- const wrapper_base<RT, fun_wrapper> *w
- = reinterpret_cast<const wrapper_base<RT, fun_wrapper>*> (arg);
- const fun_wrapper *wrapper
- = static_cast<const fun_wrapper*> (w);
-
- // copy information from
- // the stack of the
- // calling thread
- FunPtr fun_ptr = wrapper->fun_ptr;
- ArgList args = wrapper->args;
-
- boost::shared_ptr<internal::thread_description<RT> >
- thread_descriptor = wrapper->thread_descriptor;
-
- // signal the fact that
- // we have copied all the
- // information that is
- // needed
- {
- ThreadMutex::ScopedLock lock (wrapper->mutex);
- wrapper->condition.signal ();
- }
-
- // call the
- // function. since an
- // exception that is
- // thrown from one of the
- // called functions will
- // not propagate to the
- // main thread, it will
- // kill the program if
- // not treated here
- // before we return to
- // the operating system's
- // thread library
- internal::register_thread ();
- try
- {
- internal::call (fun_ptr, args,
- thread_descriptor->ret_val);
- }
- catch (const std::exception &exc)
- {
- internal::handle_std_exception (exc);
- }
- catch (...)
- {
- internal::handle_unknown_exception ();
- }
- internal::deregister_thread ();
-
- return 0;
- }
-
-
- /**
- * Make the base class a
- * friend, so that it can
- * access the thread entry
- * point function.
- */
- template <typename, typename> friend class wrapper_base;
- };
-
-
-
- /**
- * @internal
- * Wrap the arguments to a member
- * function and provide an entry
- * point for a new thread that
- * unwraps this data and calls
- * the function with them.
- *
- * @author Wolfgang Bangerth, 2003
- */
- template <typename RT, class C, typename ArgList>
- struct mem_fun_wrapper : public wrapper_base<RT, mem_fun_wrapper<RT,C,ArgList> >
- {
- /**
- * Typedef for the type of
- * the function to be called
- * on the new thread.
- */
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
- /**
- * Typedef for a typelist of
- * reference arguments to the
- * function to be called.
- */
- typedef typename internal::tie_args<ArgList>::type ArgReferences;
-
- /**
- * Constructor. Store the
- * necessary information
- * about the function to be
- * called and with which
- * arguments.
- *
- * Pass down the address of
- * this class's thread entry
- * point function. This way,
- * we can ensure that object
- * and thread entry point
- * function always are in
- * synch with respect to
- * their knowledge of the
- * types involved.
- */
- mem_fun_wrapper (MemFunPtr mem_fun_ptr,
- C &c,
- const ArgReferences &args)
- :
- c (c),
- mem_fun_ptr (mem_fun_ptr),
- args (args) {}
- private:
- /**
- * Default constructor. Made
- * private and not
- * implemented to prevent
- * calling.
- */
- mem_fun_wrapper ();
-
- /**
- * Copy constructor. Made
- * private and not
- * implemented to prevent
- * calling.
- */
- mem_fun_wrapper (const mem_fun_wrapper &);
-
- /**
- * Pointer to the function to
- * be called on the new
- * thread, as well as the
- * object with which this has
- * to happen.
- */
- C &c;
- MemFunPtr mem_fun_ptr;
-
- /**
- * References to the
- * arguments with which the
- * function is to be called.
- */
- ArgReferences args;
-
- /**
- * Entry point for the new
- * thread.
- */
- static void * entry_point (void *arg)
- {
- const wrapper_base<RT,mem_fun_wrapper> *w
- = reinterpret_cast<const wrapper_base<RT,mem_fun_wrapper>*> (arg);
- const mem_fun_wrapper *wrapper
- = static_cast<const mem_fun_wrapper*> (w);
-
- // copy information from
- // the stack of the
- // calling thread
- MemFunPtr mem_fun_ptr = wrapper->mem_fun_ptr;
- C &c = wrapper->c;
- ArgList args = wrapper->args;
-
- boost::shared_ptr<internal::thread_description<RT> >
- thread_descriptor = wrapper->thread_descriptor;
-
- // signal the fact that
- // we have copied all the
- // information that is
- // needed
- {
- ThreadMutex::ScopedLock lock (wrapper->mutex);
- wrapper->condition.signal ();
- }
-
- // call the
- // function. since an
- // exception that is
- // thrown from one of the
- // called functions will
- // not propagate to the
- // main thread, it will
- // kill the program if
- // not treated here
- // before we return to
- // the operating system's
- // thread library
- internal::register_thread ();
- try
- {
- internal::call (mem_fun_ptr, c, args,
- thread_descriptor->ret_val);
- }
- catch (const std::exception &exc)
- {
- internal::handle_std_exception (exc);
- }
- catch (...)
- {
- internal::handle_unknown_exception ();
- }
- internal::deregister_thread ();
-
- return 0;
- }
-
- /**
- * Make the base class a
- * friend, so that it can
- * access the thread entry
- * point function.
- */
- template <typename, typename> friend class wrapper_base;
- };
- }
-
-
- namespace internal
- {
- /**
- * @internal
- * General template declaration
- * of a class that is used to
- * encapsulate arguments to
- * global and static member
- * functions, make sure a new
- * thread is created and that
- * function being run on that
- * thread.
- *
- * Although this general template
- * is not implemented at all, the
- * default template argument
- * makes sure that whenever using
- * the name of this class, the
- * last template argument will be
- * computed correctly from the
- * previous arguments, and the
- * correct specialization for
- * this last template argument be
- * used, even though we need to
- * specify it.
- */
- template <typename RT, typename ArgList,
- int length>
- class fun_encapsulator;
-
-
- /**
- * @internal
- * General template declaration
- * of a class that is used to
- * encapsulate arguments to
- * non-static member functions,
- * make sure a new thread is
- * created and that function
- * being run on that thread.
- *
- * Although this general template
- * is not implemented at all, the
- * default template argument
- * makes sure that whenever using
- * the name of this class, the
- * last template argument will be
- * computed correctly from the
- * previous arguments, and the
- * correct specialization for
- * this last template argument be
- * used, even though we need to
- * specify it.
- */
- template <typename RT, typename C, typename ArgList,
- int length>
- class mem_fun_encapsulator;
- }
-
-
-// ----------- encapsulators for member functions not taking any parameters
-
- namespace internal
- {
- /**
- * @internal
- * Encapsulator class for member
- * functions with no arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_encapsulator<RT, C, ArgList, 0>
- {
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
- public:
- inline mem_fun_encapsulator (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() () {
- return mem_fun_wrapper<RT,C,ArgList> (mem_fun_ptr, c,
- ArgList()).fire_up ();
- }
-
- private:
- C &c;
- MemFunPtr mem_fun_ptr;
- };
-
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions with
- * no arguments.
- */
- template <typename RT, typename C>
- inline
- internal::mem_fun_encapsulator<RT,C,boost::tuple<>,0>
- spawn (C &c, RT (C::*fun_ptr)()) {
- return internal::mem_fun_encapsulator<RT, C, boost::tuple<>,0> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function for
- * const member functions with no
- * arguments.
- */
- template <typename RT, typename C>
- inline
- internal::mem_fun_encapsulator<RT,const C,boost::tuple<>,0>
- spawn (const C &c, RT (C::*fun_ptr)() const) {
- return internal::mem_fun_encapsulator<RT, const C, boost::tuple<>,0> (c,fun_ptr);
- }
-
-
-
-
-// ----------- encapsulators for unary member functions
-
- namespace internal
- {
- /**
- * @internal
- * Encapsulator class for member
- * functions with 1 argument.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_encapsulator<RT, C, ArgList, 1>
- {
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
- public:
- inline mem_fun_encapsulator (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1) {
- return mem_fun_wrapper<RT,C,ArgList> (mem_fun_ptr, c,
- boost::tie(arg1)).fire_up ();
- }
-
- private:
- C &c;
- MemFunPtr mem_fun_ptr;
- };
-
- }
-
-
- /**
- * Overload of the non-const spawn
- * function for member functions with
- * 1 argument.
- */
- template <typename RT, typename C, typename Arg1>
- inline
- internal::mem_fun_encapsulator<RT,C,boost::tuple<Arg1>,1>
- spawn (C &c, RT (C::*fun_ptr)(Arg1)) {
- return internal::mem_fun_encapsulator<RT, C, boost::tuple<Arg1>,1> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function for
- * const member functions with 1
- * argument.
- */
- template <typename RT, typename C, typename Arg1>
- inline
- internal::mem_fun_encapsulator<RT,const C,boost::tuple<Arg1>,1>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1) const) {
- return internal::mem_fun_encapsulator<RT, const C, boost::tuple<Arg1>,1> (c,fun_ptr);
- }
-
-
-
-
-// ----------- encapsulators for binary member functions
-
- namespace internal
- {
- /**
- * @internal
- * Encapsulator class for member
- * functions with 2 arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_encapsulator<RT, C, ArgList, 2>
- {
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
- public:
- inline mem_fun_encapsulator (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2) {
- return mem_fun_wrapper<RT,C,ArgList> (mem_fun_ptr, c,
- boost::tie(arg1,
- arg2)).fire_up ();
- }
-
- private:
- C &c;
- MemFunPtr mem_fun_ptr;
- };
-
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions with
- * 2 arguments.
- */
- template <typename RT, typename C, typename Arg1, typename Arg2>
- inline
- internal::mem_fun_encapsulator<RT,C,boost::tuple<Arg1, Arg2>,2>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2)) {
- return internal::mem_fun_encapsulator<RT, C, boost::tuple<Arg1, Arg2>,2> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function for
- * const member functions with 2
- * arguments.
- */
- template <typename RT, typename C, typename Arg1, typename Arg2>
- inline
- internal::mem_fun_encapsulator<RT,const C,boost::tuple<Arg1, Arg2>,2>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2) const) {
- return internal::mem_fun_encapsulator<RT, const C, boost::tuple<Arg1, Arg2>,2> (c,fun_ptr);
- }
-
-
-
-// ----------- encapsulators for ternary member functions
-
- namespace internal
- {
- /**
- * @internal
- * Encapsulator class for member
- * functions with 3 arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_encapsulator<RT, C, ArgList, 3>
- {
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
- public:
- inline mem_fun_encapsulator (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3) {
- return mem_fun_wrapper<RT,C,ArgList> (mem_fun_ptr, c,
- boost::tie(arg1,
- arg2,
- arg3)).fire_up ();
- }
-
- private:
- C &c;
- MemFunPtr mem_fun_ptr;
- };
-
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions with
- * 3 arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3>
- inline
- internal::mem_fun_encapsulator<RT,C,boost::tuple<Arg1, Arg2, Arg3>,3>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3)) {
- return internal::mem_fun_encapsulator<RT, C,
- boost::tuple<Arg1, Arg2, Arg3>,3> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function for
- * const member functions with 3
- * arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3>
- inline
- internal::mem_fun_encapsulator<RT,const C,boost::tuple<Arg1, Arg2, Arg3>,3>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3) const) {
- return internal::mem_fun_encapsulator<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3>,3> (c,fun_ptr);
- }
-
-
-
-
-// ----------- encapsulators for member functions with 4 arguments
-
- namespace internal
- {
- /**
- * @internal
- * Encapsulator class for member
- * functions with 4 arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_encapsulator<RT, C, ArgList, 4>
- {
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
- public:
- inline mem_fun_encapsulator (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4) {
- return mem_fun_wrapper<RT,C,ArgList> (mem_fun_ptr, c,
- boost::tie(arg1,arg2,
- arg3,arg4)).fire_up ();
- }
-
- private:
- C &c;
- MemFunPtr mem_fun_ptr;
- };
-
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions with
- * 4 arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3, typename Arg4>
- inline
- internal::mem_fun_encapsulator<RT,C,boost::tuple<Arg1, Arg2, Arg3, Arg4>,4>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4)) {
- return internal::mem_fun_encapsulator<RT, C,
- boost::tuple<Arg1, Arg2, Arg3, Arg4>,4> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function for
- * const member functions with 4
- * arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3, typename Arg4>
- inline
- internal::mem_fun_encapsulator<RT,const C,boost::tuple<Arg1, Arg2, Arg3, Arg4>,4>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4) const) {
- return internal::mem_fun_encapsulator<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3, Arg4>,4> (c,fun_ptr);
- }
-
-
-
-
-// ----------- encapsulators for member functions with 5 arguments
-
- namespace internal
- {
- /**
- * @internal
- * Encapsulator class for member
- * functions with 5 arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_encapsulator<RT, C, ArgList, 5>
- {
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
- public:
- inline mem_fun_encapsulator (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5) {
- return mem_fun_wrapper<RT,C,ArgList> (mem_fun_ptr, c,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5)).fire_up ();
- }
-
- private:
- C &c;
- MemFunPtr mem_fun_ptr;
- };
-
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions with
- * 5 arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5>
- inline
- internal::mem_fun_encapsulator<RT,C,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5>,5>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5)) {
- return internal::mem_fun_encapsulator<RT, C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5>,5> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function for
- * const member functions with 5
- * arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5>
- inline
- internal::mem_fun_encapsulator<RT,const C,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5>,5>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5) const) {
- return internal::mem_fun_encapsulator<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5>,5> (c,fun_ptr);
- }
-
-
-// ----------- encapsulators for member functions with 6 arguments
-
- namespace internal
- {
- /**
- * @internal
- * Encapsulator class for member
- * functions with 6 arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_encapsulator<RT, C, ArgList, 6>
- {
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
- public:
- inline mem_fun_encapsulator (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6) {
- return mem_fun_wrapper<RT,C,ArgList> (mem_fun_ptr, c,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6)).fire_up ();
- }
-
- private:
- C &c;
- MemFunPtr mem_fun_ptr;
- };
-
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions with
- * 6 arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6>
- inline
- internal::mem_fun_encapsulator<RT,C,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>,6>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6)) {
- return internal::mem_fun_encapsulator<RT, C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6>,6> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function for
- * const member functions with 6
- * arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6>
- inline
- internal::mem_fun_encapsulator<RT,const C,
- boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>,6>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6) const) {
- return internal::mem_fun_encapsulator<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6>,6> (c,fun_ptr);
- }
-
-
-// ----------- encapsulators for member functions with 7 arguments
-
- namespace internal
- {
- /**
- * @internal
- * Encapsulator class for member
- * functions with 7 arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_encapsulator<RT, C, ArgList, 7>
- {
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
- public:
- inline mem_fun_encapsulator (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7) {
- return mem_fun_wrapper<RT,C,ArgList> (mem_fun_ptr, c,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7)).fire_up ();
- }
-
- private:
- C &c;
- MemFunPtr mem_fun_ptr;
- };
-
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions with
- * 7 arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7>
- inline
- internal::mem_fun_encapsulator<RT,C,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6, Arg7>,7>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7)) {
- return internal::mem_fun_encapsulator<RT, C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7>,7> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function for
- * const member functions with 7
- * arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7>
- inline
- internal::mem_fun_encapsulator<RT,const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6, Arg7>,7>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7) const) {
- return internal::mem_fun_encapsulator<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7>,7> (c,fun_ptr);
- }
-
-
-// ----------- encapsulators for member functions with 8 arguments
-
- namespace internal
- {
- /**
- * @internal
- * Encapsulator class for member
- * functions with 8 arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_encapsulator<RT, C, ArgList, 8>
- {
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
- public:
- inline mem_fun_encapsulator (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7,
- typename boost::tuples::element<7,ArgList>::type arg8) {
- return mem_fun_wrapper<RT,C,ArgList> (mem_fun_ptr, c,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7,arg8)).fire_up ();
- }
-
- private:
- C &c;
- MemFunPtr mem_fun_ptr;
- };
-
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions with
- * 8 arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8>
- inline
- internal::mem_fun_encapsulator<RT,C,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8>,8>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8)) {
- return internal::mem_fun_encapsulator<RT, C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8>,8> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function for
- * const member functions with 8
- * arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8>
- inline
- internal::mem_fun_encapsulator<RT,const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8>,8>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8) const) {
- return internal::mem_fun_encapsulator<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8>,8> (c,fun_ptr);
- }
-
-
-// ----------- encapsulators for member functions with 9 arguments
-
- namespace internal
- {
- /**
- * @internal
- * Encapsulator class for member
- * functions with 9 arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_encapsulator<RT, C, ArgList, 9>
- {
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
- public:
- inline mem_fun_encapsulator (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7,
- typename boost::tuples::element<7,ArgList>::type arg8,
- typename boost::tuples::element<8,ArgList>::type arg9) {
- return mem_fun_wrapper<RT,C,ArgList> (mem_fun_ptr, c,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7,arg8,
- arg9)).fire_up ();
- }
-
- private:
- C &c;
- MemFunPtr mem_fun_ptr;
- };
-
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions with
- * 9 arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8, typename Arg9>
- inline
- internal::mem_fun_encapsulator<RT,C,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9>,9>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8,Arg9)) {
- return internal::mem_fun_encapsulator<RT, C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9>,9> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function for
- * const member functions with 9
- * arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8, typename Arg9>
- inline
- internal::mem_fun_encapsulator<RT,const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9>,9>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8,Arg9) const) {
- return internal::mem_fun_encapsulator<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9>,9> (c,fun_ptr);
- }
-
-
-// ----------- encapsulators for member functions with 10 arguments
-
- namespace internal
- {
- /**
- * @internal
- * Encapsulator class for member
- * functions with 10 arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_encapsulator<RT, C, ArgList, 10>
- {
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
- public:
- inline mem_fun_encapsulator (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7,
- typename boost::tuples::element<7,ArgList>::type arg8,
- typename boost::tuples::element<8,ArgList>::type arg9,
- typename boost::tuples::element<9,ArgList>::type arg10) {
- return mem_fun_wrapper<RT,C,ArgList> (mem_fun_ptr, c,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7,arg8,
- arg9, arg10)).fire_up ();
- }
-
- private:
- C &c;
- MemFunPtr mem_fun_ptr;
- };
-
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions with
- * 10 arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8, typename Arg9,
- typename Arg10>
- inline
- internal::mem_fun_encapsulator<RT,C,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9, Arg10>,10>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8,Arg9,Arg10)) {
- return internal::mem_fun_encapsulator<RT, C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9,
- Arg10>,10> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function for
- * const member functions with 10
- * arguments.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8, typename Arg9,
- typename Arg10>
- inline
- internal::mem_fun_encapsulator<RT,const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9, Arg10>,10>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8,Arg9,Arg10) const) {
- return internal::mem_fun_encapsulator<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9,
- Arg10>,10> (c,fun_ptr);
- }
-
-
-
-// ----------- encapsulators for functions not taking any parameters
-
- namespace internal
- {
- /**
- * @internal
- * Encapsulator class for
- * functions with no arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 0>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_encapsulator (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
-
- inline
- Thread<RT>
- operator() () {
- return fun_wrapper<RT,ArgList> (fun_ptr,
- ArgList()).fire_up ();
- }
-
- private:
- FunPtr fun_ptr;
- };
-
- }
-
- /**
- * Overload of the spawn function for
- * non-member or static member
- * functions with no arguments.
- */
- template <typename RT>
- inline
- internal::fun_encapsulator<RT,boost::tuple<>,0>
- spawn (RT (*fun_ptr)()) {
- return internal::fun_encapsulator<RT, boost::tuple<>,0> (fun_ptr);
- }
-
-
-
-
-// ----------- encapsulators for unary functions
-
- namespace internal
- {
- /**
- * @internal
- * Encapsulator class for
- * functions with 1 argument.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 1>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_encapsulator (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1) {
- return fun_wrapper<RT,ArgList> (fun_ptr,
- boost::tie(arg1)).fire_up ();
- }
-
- private:
- FunPtr fun_ptr;
- };
-
- }
-
- /**
- * Overload of the spawn function for
- * non-member or static member
- * functions with 1 argument.
- */
- template <typename RT, typename Arg1>
- inline
- internal::fun_encapsulator<RT,boost::tuple<Arg1>,1>
- spawn (RT (*fun_ptr)(Arg1)) {
- return internal::fun_encapsulator<RT, boost::tuple<Arg1>,1> (fun_ptr);
- }
-
-
-
-
-// ----------- encapsulators for binary functions
-
- namespace internal
- {
- /**
- * Encapsulator class for
- * functions with 2 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 2>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_encapsulator (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2) {
- return fun_wrapper<RT,ArgList> (fun_ptr,
- boost::tie(arg1,
- arg2)).fire_up ();
- }
-
- private:
- FunPtr fun_ptr;
- };
-
- }
-
- /**
- * Overload of the spawn function for
- * non-member or static member
- * functions with 2 arguments.
- */
- template <typename RT, typename Arg1, typename Arg2>
- inline
- internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2>,2>
- spawn (RT (*fun_ptr)(Arg1,Arg2)) {
- return internal::fun_encapsulator<RT, boost::tuple<Arg1, Arg2>,2> (fun_ptr);
- }
-
-
-
-// ----------- encapsulators for ternary functions
-
- namespace internal
- {
- /**
- * Encapsulator class for
- * functions with 3 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 3>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_encapsulator (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3) {
- return fun_wrapper<RT,ArgList> (fun_ptr,
- boost::tie(arg1,
- arg2,
- arg3)).fire_up ();
- }
-
- private:
- FunPtr fun_ptr;
- };
-
- }
-
- /**
- * Overload of the spawn function for
- * non-member or static member
- * functions with 3 arguments.
- */
- template <typename RT,
- typename Arg1, typename Arg2, typename Arg3>
- inline
- internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3>,3>
- spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3)) {
- return internal::fun_encapsulator<RT,
- boost::tuple<Arg1, Arg2, Arg3>,3> (fun_ptr);
- }
-
-
-
-
-// ----------- encapsulators for functions with 4 arguments
-
- namespace internal
- {
- /**
- * Encapsulator class for
- * functions with 4 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 4>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_encapsulator (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4) {
- return fun_wrapper<RT,ArgList> (fun_ptr,
- boost::tie(arg1,arg2,
- arg3,arg4)).fire_up ();
- }
-
- private:
- FunPtr fun_ptr;
- };
-
- }
-
- /**
- * Overload of the spawn function for
- * non-member or static member
- * functions with 4 arguments.
- */
- template <typename RT,
- typename Arg1, typename Arg2, typename Arg3, typename Arg4>
- inline
- internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4>,4>
- spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4)) {
- return internal::fun_encapsulator<RT,
- boost::tuple<Arg1, Arg2, Arg3, Arg4>,4> (fun_ptr);
- }
-
-
-
-
-// ----------- encapsulators for functions with 5 arguments
-
- namespace internal
- {
- /**
- * Encapsulator class for
- * functions with 5 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 5>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_encapsulator (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5) {
- return fun_wrapper<RT,ArgList> (fun_ptr,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5)).fire_up ();
- }
-
- private:
- FunPtr fun_ptr;
- };
-
- }
-
- /**
- * Overload of the spawn function for
- * non-member or static member
- * functions with 5 arguments.
- */
- template <typename RT,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5>
- inline
- internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5>,5>
- spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5)) {
- return internal::fun_encapsulator<RT,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5>,5> (fun_ptr);
- }
-
-
-// ----------- encapsulators for functions with 6 arguments
-
- namespace internal
- {
- /**
- * Encapsulator class for
- * functions with 6 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 6>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_encapsulator (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6) {
- return fun_wrapper<RT,ArgList> (fun_ptr,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6)).fire_up ();
- }
-
- private:
- FunPtr fun_ptr;
- };
-
- }
-
- /**
- * Overload of the spawn function for
- * non-member or static member
- * functions with 6 arguments.
- */
- template <typename RT,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6>
- inline
- internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>,6>
- spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6)) {
- return internal::fun_encapsulator<RT,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6>,6> (fun_ptr);
- }
-
-
-// ----------- encapsulators for functions with 7 arguments
-
- namespace internal
- {
- /**
- * Encapsulator class for
- * functions with 7 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 7>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_encapsulator (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7) {
- return fun_wrapper<RT,ArgList> (fun_ptr,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7)).fire_up ();
- }
-
- private:
- FunPtr fun_ptr;
- };
-
- }
-
- /**
- * Overload of the spawn function for
- * non-member or static member
- * functions with 7 arguments.
- */
- template <typename RT,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7>
- inline
- internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6, Arg7>,7>
- spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7)) {
- return internal::fun_encapsulator<RT,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7>,7> (fun_ptr);
- }
-
-
-// ----------- encapsulators for functions with 8 arguments
-
- namespace internal
- {
- /**
- * Encapsulator class for
- * functions with 8 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 8>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_encapsulator (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7,
- typename boost::tuples::element<7,ArgList>::type arg8) {
- return fun_wrapper<RT,ArgList> (fun_ptr,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7,arg8)).fire_up ();
- }
-
- private:
- FunPtr fun_ptr;
- };
-
- }
+ /**
+ * Construct a thread object
+ * with a pointer to an
+ * internal thread object. This
+ * is the constructor used to
+ * the <tt>spawn</tt> family of
+ * functions.
+ *
+ * We would like to make this
+ * constructor private and only
+ * grant the
+ * <tt>fun_wrapper::fire_up</tt>
+ * function friendship, but
+ * granting friendship to
+ * functions in other
+ * namespaces doesn't work with
+ * some compilers, so only do
+ * so if the configure script
+ * decided that this is safe.
+ */
+#if defined(DEAL_II_NAMESP_TEMPL_FRIEND_BUG2) || defined(DEAL_II_NAMESP_TEMPL_FRIEND_BUG)
+ public:
+#endif
+ Thread (const boost::shared_ptr<internal::thread_description<RT> > &td)
+ : thread_descriptor (td) {}
- /**
- * Overload of the spawn function for
- * non-member or static member
- * functions with 8 arguments.
- */
- template <typename RT,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8>
- inline
- internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8>,8>
- spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8)) {
- return internal::fun_encapsulator<RT,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8>,8> (fun_ptr);
- }
+ public:
+
+ /**
+ * Default constructor. You
+ * can't do much with a thread
+ * object constructed this way,
+ * except for assigning it a
+ * thread object that holds
+ * data created by the
+ * <tt>spawn</tt> functions.
+ */
+ Thread () {}
+ /**
+ * Join the thread represented
+ * by this object, i.e. wait
+ * for it to finish. You can't
+ * call this function if you
+ * have used the default
+ * constructor of this class
+ * and have not assigned a
+ * thread object to it.
+ */
+ void join () const
+ {
+ AssertThrow (thread_descriptor, ExcNoThread());
+ thread_descriptor->join ();
+ }
-// ----------- encapsulators for functions with 9 arguments
+ /**
+ * Get the return value of the
+ * function of the
+ * thread. Since this is only
+ * available once the thread
+ * finishes, this implicitely
+ * also calls <tt>join()</tt>.
+ */
+ RT return_value ()
+ {
+ join ();
+ return thread_descriptor->ret_val.get();
+ }
- namespace internal
- {
- /**
- * Encapsulator class for
- * functions with 9 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 9>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
- public:
- inline fun_encapsulator (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
+ /**
+ * Check for equality of thread
+ * objects. Since objects of
+ * this class store an implicit
+ * pointer to an object that
+ * exists exactly once for each
+ * thread, the check is simply
+ * to compare these pointers.
+ */
+ bool operator == (const Thread &t)
+ {
+ return thread_descriptor == t.thread_descriptor;
+ }
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7,
- typename boost::tuples::element<7,ArgList>::type arg8,
- typename boost::tuples::element<8,ArgList>::type arg9) {
- return fun_wrapper<RT,ArgList> (fun_ptr,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7,arg8,
- arg9)).fire_up ();
- }
-
- private:
- FunPtr fun_ptr;
- };
-
- }
+ /** @addtogroup Exceptions
+ * @{ */
+
+ /**
+ * Exception
+ */
+ DeclException0 (ExcNoThread);
+ //@}
+ private:
+ /**
+ * Shared pointer to the object
+ * representing the thread, and
+ * abstracting operating system
+ * functions to work on
+ * it. Boost's shared pointer
+ * implementation will make
+ * sure that that object lives
+ * as long as there is at least
+ * one subscriber to it.
+ */
+ boost::shared_ptr<internal::thread_description<RT> > thread_descriptor;
- /**
- * Overload of the spawn function for
- * non-member or static member
- * functions with 9 arguments.
- */
- template <typename RT,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8, typename Arg9>
- inline
- internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9>,9>
- spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8,Arg9)) {
- return internal::fun_encapsulator<RT,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9>,9> (fun_ptr);
- }
+#if !defined(DEAL_II_NAMESP_TEMPL_FRIEND_BUG2) && !defined(DEAL_II_NAMESP_TEMPL_FRIEND_BUG)
+ template <typename> friend struct internal::fun_wrapper;
+#endif
+ };
-// ----------- encapsulators for functions with 10 arguments
namespace internal
{
/**
- * Encapsulator class for
- * functions with 10 arguments.
+ * @internal
+ * Wrap the arguments to a
+ * non-member or static member
+ * function and provide an entry
+ * point for a new thread that
+ * unwraps this data and calls
+ * the function with them.
+ *
+ * @author Wolfgang Bangerth, 2003
*/
- template <typename RT, typename ArgList>
- class fun_encapsulator<RT, ArgList, 10>
+ template <typename RT>
+ struct fun_wrapper
{
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
+ /**
+ * Constructor. Store the
+ * necessary information
+ * about the function to be
+ * called and with which
+ * arguments.
+ *
+ * Pass down the address of
+ * this class's thread entry
+ * point function. This way,
+ * we can ensure that object
+ * and thread entry point
+ * function always are in
+ * synch with respect to
+ * their knowledge of the
+ * types involved.
+ */
+ fun_wrapper (const boost::function<RT ()> &function)
+ : function (function) {}
- public:
- inline fun_encapsulator (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7,
- typename boost::tuples::element<7,ArgList>::type arg8,
- typename boost::tuples::element<8,ArgList>::type arg9,
- typename boost::tuples::element<9,ArgList>::type arg10) {
- return fun_wrapper<RT,ArgList> (fun_ptr,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7,arg8,
- arg9, arg10)).fire_up ();
- }
-
+ /**
+ * Start a new thread, wait
+ * until it has copied the
+ * data out of this object,
+ * and return the thread
+ * descriptor.
+ *
+ * In the non-multithreaded case,
+ * simply call the function.
+ */
+ Thread<RT> fire_up ()
+ {
+ thread_descriptor =
+ DescriptionPointer(new internal::thread_description<RT>());
+
+#if (DEAL_II_USE_MT == 1)
+ ThreadMutex::ScopedLock lock (mutex);
+ thread_descriptor->create (&entry_point, (void *)this);
+ condition.wait (mutex);
+#else
+ call (function, thread_descriptor->ret_val);
+#endif
+ return thread_descriptor;
+ }
+
private:
- FunPtr fun_ptr;
- };
-
- }
+ /**
+ * Default constructor. Made
+ * private and not
+ * implemented to prevent
+ * calling.
+ */
+ fun_wrapper ();
- /**
- * Overload of the spawn function for
- * non-member or static member
- * functions with 10 arguments.
- */
- template <typename RT,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8, typename Arg9,
- typename Arg10>
- inline
- internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9, Arg10>,10>
- spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8,Arg9,Arg10)) {
- return internal::fun_encapsulator<RT,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9,
- Arg10>,10> (fun_ptr);
- }
+ /**
+ * Copy constructor. Made
+ * private and not
+ * implemented to prevent
+ * calling.
+ */
+ fun_wrapper (const fun_wrapper &);
-#else // #if (DEAL_II_USE_MT == 1)
+ /**
+ * Typedef for shared
+ * pointers to the objects
+ * describing threads on the
+ * OS level.
+ */
+ typedef
+ boost::shared_ptr<internal::thread_description<RT> >
+ DescriptionPointer;
- template <typename RT = void>
- class Thread
- {
- public:
- /**
- * Default constructor.
- */
- Thread () {}
+ /**
+ * Shared pointer to the
+ * unique object describing a
+ * thread on the OS level.
+ */
+ DescriptionPointer thread_descriptor;
- /**
- * Initialize the return value
- * of this object using the
- * given member-function
- * pointer, object, and
- * argument list.
- */
- template <typename PFun, typename C, typename ArgRefs>
- Thread (PFun fun_ptr,
- C &obj,
- ArgRefs arg_refs)
- {
- internal::call (fun_ptr, obj, arg_refs, rv);
- }
+ /**
+ * Mutex and condition
+ * variable used to
+ * synchronise calling and
+ * called thread.
+ */
+ mutable ThreadMutex mutex;
+ mutable ThreadCondition condition;
- /**
- * Initialize the return value
- * of this object using the
- * given function pointer, and
- * argument list.
- */
- template <typename PFun, typename ArgRefs>
- Thread (PFun fun_ptr,
- ArgRefs arg_refs)
- {
- internal::call (fun_ptr, arg_refs, rv);
- }
+ /**
+ * Pointer to the function to
+ * be called on the new
+ * thread.
+ */
+ boost::function<RT ()> function;
- /**
- * Get the return value of the
- * function of the
- * thread.
- */
- RT return_value () const
- {
- return rv.get();
- }
+ /**
+ * Entry point for the new
+ * thread.
+ */
+ static void * entry_point (void *arg)
+ {
+ const fun_wrapper<RT> *wrapper
+ = reinterpret_cast<const fun_wrapper<RT>*> (arg);
- /**
- * Join this thread. Is of
- * course a no-op in this of no
- * thread support.
- */
- void join () const {}
+ // copy information from
+ // the stack of the
+ // calling thread
+ boost::function<RT ()> function = wrapper->function;
+
+ boost::shared_ptr<internal::thread_description<RT> >
+ thread_descriptor = wrapper->thread_descriptor;
+
+ // signal the fact that
+ // we have copied all the
+ // information that is
+ // needed
+ {
+ ThreadMutex::ScopedLock lock (wrapper->mutex);
+ wrapper->condition.signal ();
+ }
+
+ // call the
+ // function. since an
+ // exception that is
+ // thrown from one of the
+ // called functions will
+ // not propagate to the
+ // main thread, it will
+ // kill the program if
+ // not treated here
+ // before we return to
+ // the operating system's
+ // thread library
+ internal::register_thread ();
+ try
+ {
+ internal::call (function, thread_descriptor->ret_val);
+ }
+ catch (const std::exception &exc)
+ {
+ internal::handle_std_exception (exc);
+ }
+ catch (...)
+ {
+ internal::handle_unknown_exception ();
+ }
+ internal::deregister_thread ();
+
+ return 0;
+ }
+
+
+ /**
+ * Make the base class a
+ * friend, so that it can
+ * access the thread entry
+ * point function.
+ */
+ template <typename, typename> friend class wrapper_base;
+ };
+ }
- /**
- * Compare for equality of
- * threads. Since thrheads are
- * not supported, there can
- * only be exactly one thread,
- * and the result is
- * <tt>true</tt>. This function
- * doesn't make much sense,
- * though, when threads are not
- * supported.
- */
- bool operator == (const Thread &)
- {
- return true;
- }
-
- private:
- /**
- * Store the return value of
- * the thread function.
- */
- internal::return_value<RT> rv;
- };
-
namespace internal
{
* @internal
* General template declaration
* of a class that is used to
- * forward arguments to
+ * encapsulate arguments to
* global and static member
- * functions.
+ * functions, make sure a new
+ * thread is created and that
+ * function being run on that
+ * thread.
*
* Although this general template
* is not implemented at all, the
* used, even though we need to
* specify it.
*/
- template <typename RT, typename ArgList,
- int length>
- class fun_forwarder;
+ template <typename RT, typename ArgList, int length>
+ class fun_encapsulator;
- /**
- * @internal
- * General template declaration
- * of a class that is used to
- * forward arguments to
- * non-static member functions.
- *
- * Although this general template
- * is not implemented at all, the
- * default template argument
- * makes sure that whenever using
- * the name of this class, the
- * last template argument will be
- * computed correctly from the
- * previous arguments, and the
- * correct specialization for
- * this last template argument be
- * used, even though we need to
- * specify it.
- */
- template <typename RT, typename C, typename ArgList,
- int length>
- class mem_fun_forwarder;
- }
+// ----------- encapsulators for member functions not taking any parameters
- namespace internal
- {
/**
* @internal
- * Forwarder class for member
+ * Encapsulator class for
* functions with no arguments.
*/
- template <typename RT, typename C, typename ArgList>
- class mem_fun_forwarder<RT, C, ArgList, 0>
+ template <typename RT, typename ArgList>
+ class fun_encapsulator<RT, ArgList, 0>
{
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
public:
- inline mem_fun_forwarder (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
+ fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
+ : function (*function)
+ {}
+
+ fun_encapsulator (const boost::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
+ : function (function)
+ {}
inline
Thread<RT>
- operator() () {
- return Thread<RT> (mem_fun_ptr, c,
- ArgList());
- }
+ operator() ()
+ {
+ return fun_wrapper<RT> (function).fire_up ();
+ }
private:
- C &c;
- MemFunPtr mem_fun_ptr;
+ boost::function<typename internal::fun_ptr<RT,ArgList>::type> function;
};
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions
- * with no arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C>
- inline
- internal::mem_fun_forwarder<RT,C,boost::tuple<>,0>
- spawn (C &c, RT (C::*fun_ptr)()) {
- return internal::mem_fun_forwarder<RT, C, boost::tuple<>,0> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function
- * for const member functions with
- * no arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C>
- inline
- internal::mem_fun_forwarder<RT,const C,boost::tuple<>,0>
- spawn (const C &c, RT (C::*fun_ptr)() const) {
- return internal::mem_fun_forwarder<RT, const C, boost::tuple<>,0> (c,fun_ptr);
- }
-
-
-
-
-// ----------- forwarders for unary member functions
-
- namespace internal
- {
/**
* @internal
- * Forwarder class for member
+ * Encapsulator class for
* functions with 1 argument.
*/
- template <typename RT, typename C, typename ArgList>
- class mem_fun_forwarder<RT, C, ArgList, 1>
+ template <typename RT, typename ArgList>
+ class fun_encapsulator<RT, ArgList, 1>
{
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
public:
- inline mem_fun_forwarder (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1) {
- return Thread<RT> (mem_fun_ptr, c,
- boost::tie(arg1));
- }
-
- private:
- C &c;
- MemFunPtr mem_fun_ptr;
- };
-
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions with
- * 1 argument. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C, typename Arg1>
- inline
- internal::mem_fun_forwarder<RT,C,boost::tuple<Arg1>,1>
- spawn (C &c, RT (C::*fun_ptr)(Arg1)) {
- return internal::mem_fun_forwarder<RT, C, boost::tuple<Arg1>,1> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function for
- * const member functions with 1
- * argument. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C, typename Arg1>
- inline
- internal::mem_fun_forwarder<RT,const C,boost::tuple<Arg1>,1>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1) const) {
- return internal::mem_fun_forwarder<RT, const C, boost::tuple<Arg1>,1> (c,fun_ptr);
- }
-
-
-
-
-// ----------- forwarders for binary member functions
-
- namespace internal
- {
- /**
- * @internal
- * Forwarder class for member
- * functions with 2
- * arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_forwarder<RT, C, ArgList, 2>
- {
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
+ fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
+ : function (*function)
+ {}
- public:
- inline mem_fun_forwarder (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
+ fun_encapsulator (const boost::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
+ : function (function)
+ {}
inline
Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2) {
- return Thread<RT> (mem_fun_ptr, c,
- boost::tie(arg1,
- arg2));
- }
+ operator() (typename boost::tuples::element<0,ArgList>::type arg1)
+ {
+ return fun_wrapper<RT> (boost::bind (function,
+ boost::ref(arg1))).fire_up ();
+ }
private:
- C &c;
- MemFunPtr mem_fun_ptr;
+ boost::function<typename internal::fun_ptr<RT,ArgList>::type> function;
};
-
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions
- * with 2 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C, typename Arg1, typename Arg2>
- inline
- internal::mem_fun_forwarder<RT,C,boost::tuple<Arg1, Arg2>,2>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2)) {
- return internal::mem_fun_forwarder<RT, C, boost::tuple<Arg1, Arg2>,2> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function
- * for const member functions with
- * 2 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C, typename Arg1, typename Arg2>
- inline
- internal::mem_fun_forwarder<RT,const C,boost::tuple<Arg1, Arg2>,2>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2) const) {
- return internal::mem_fun_forwarder<RT, const C, boost::tuple<Arg1, Arg2>,2> (c,fun_ptr);
- }
-
-
-// ----------- forwarders for ternary member functions
-
- namespace internal
- {
- /**
+ /**
* @internal
- * Forwarder class for member
- * functions with 3
- * arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_forwarder<RT, C, ArgList, 3>
+ * Encapsulator class for
+ * functions with 2 arguments.
+ */
+ template <typename RT, typename ArgList>
+ class fun_encapsulator<RT, ArgList, 2>
{
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
public:
- inline mem_fun_forwarder (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3) {
- return Thread<RT> (mem_fun_ptr, c,
- boost::tie(arg1,
- arg2,
- arg3));
- }
+ fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
+ : function (*function)
+ {}
+
+ fun_encapsulator (const boost::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
+ : function (function)
+ {}
+
+ inline
+ Thread<RT>
+ operator() (typename boost::tuples::element<0,ArgList>::type arg1,
+ typename boost::tuples::element<1,ArgList>::type arg2)
+ {
+ return fun_wrapper<RT> (boost::bind (function,
+ boost::ref(arg1),
+ boost::ref(arg2))).fire_up ();
+ }
private:
- C &c;
- MemFunPtr mem_fun_ptr;
+ boost::function<typename internal::fun_ptr<RT,ArgList>::type> function;
};
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions
- * with 3 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3>
- inline
- internal::mem_fun_forwarder<RT,C,boost::tuple<Arg1, Arg2, Arg3>,3>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3)) {
- return internal::mem_fun_forwarder<RT, C,
- boost::tuple<Arg1, Arg2, Arg3>,3> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function
- * for const member functions with
- * 3 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3>
- inline
- internal::mem_fun_forwarder<RT,const C,boost::tuple<Arg1, Arg2, Arg3>,3>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3) const) {
- return internal::mem_fun_forwarder<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3>,3> (c,fun_ptr);
- }
-
-
-
-
-// ----------- forwarders for member functions with 4 arguments
-
- namespace internal
- {
- /**
+ /**
* @internal
- * Forwarder class for member
- * functions with 4
- * arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_forwarder<RT, C, ArgList, 4>
+ * Encapsulator class for
+ * functions with 3 arguments.
+ */
+ template <typename RT, typename ArgList>
+ class fun_encapsulator<RT, ArgList, 3>
{
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
public:
- inline mem_fun_forwarder (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4) {
- return Thread<RT> (mem_fun_ptr, c,
- boost::tie(arg1,arg2,
- arg3,arg4));
- }
+ fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
+ : function (*function)
+ {}
+
+ fun_encapsulator (const boost::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
+ : function (function)
+ {}
+
+ inline
+ Thread<RT>
+ operator() (typename boost::tuples::element<0,ArgList>::type arg1,
+ typename boost::tuples::element<1,ArgList>::type arg2,
+ typename boost::tuples::element<2,ArgList>::type arg3)
+ {
+ return fun_wrapper<RT> (boost::bind (function,
+ boost::ref(arg1),
+ boost::ref(arg2),
+ boost::ref(arg3))).fire_up ();
+ }
private:
- C &c;
- MemFunPtr mem_fun_ptr;
+ boost::function<typename internal::fun_ptr<RT,ArgList>::type> function;
};
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions
- * with 4 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3, typename Arg4>
- inline
- internal::mem_fun_forwarder<RT,C,boost::tuple<Arg1, Arg2, Arg3, Arg4>,4>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4)) {
- return internal::mem_fun_forwarder<RT, C,
- boost::tuple<Arg1, Arg2, Arg3, Arg4>,4> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function
- * for const member functions with
- * 4 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3, typename Arg4>
- inline
- internal::mem_fun_forwarder<RT,const C,boost::tuple<Arg1, Arg2, Arg3, Arg4>,4>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4) const) {
- return internal::mem_fun_forwarder<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3, Arg4>,4> (c,fun_ptr);
- }
-
-
-
-
-// ----------- forwarders for member functions with 5 arguments
-
- namespace internal
- {
- /**
+ /**
* @internal
- * Forwarder class for member
- * functions with 5
- * arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_forwarder<RT, C, ArgList, 5>
+ * Encapsulator class for
+ * functions with 4 arguments.
+ */
+ template <typename RT, typename ArgList>
+ class fun_encapsulator<RT, ArgList, 4>
{
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
public:
- inline mem_fun_forwarder (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5) {
- return Thread<RT> (mem_fun_ptr, c,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5));
- }
+ fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
+ : function (*function)
+ {}
+
+ fun_encapsulator (const boost::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
+ : function (function)
+ {}
+
+ inline
+ Thread<RT>
+ operator() (typename boost::tuples::element<0,ArgList>::type arg1,
+ typename boost::tuples::element<1,ArgList>::type arg2,
+ typename boost::tuples::element<2,ArgList>::type arg3,
+ typename boost::tuples::element<3,ArgList>::type arg4)
+ {
+ return fun_wrapper<RT> (boost::bind (function,
+ boost::ref(arg1),
+ boost::ref(arg2),
+ boost::ref(arg3),
+ boost::ref(arg4))).fire_up ();
+ }
private:
- C &c;
- MemFunPtr mem_fun_ptr;
+ boost::function<typename internal::fun_ptr<RT,ArgList>::type> function;
};
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions
- * with 5 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5>
- inline
- internal::mem_fun_forwarder<RT,C,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5>,5>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5)) {
- return internal::mem_fun_forwarder<RT, C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5>,5> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function
- * for const member functions with
- * 5 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5>
- inline
- internal::mem_fun_forwarder<RT,const C,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5>,5>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5) const) {
- return internal::mem_fun_forwarder<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5>,5> (c,fun_ptr);
- }
-
-
-// ----------- forwarders for member functions with 6 arguments
-
- namespace internal
- {
- /**
+ /**
* @internal
- * Forwarder class for member
- * functions with 6
- * arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_forwarder<RT, C, ArgList, 6>
+ * Encapsulator class for
+ * functions with 5 arguments.
+ */
+ template <typename RT, typename ArgList>
+ class fun_encapsulator<RT, ArgList, 5>
{
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
public:
- inline mem_fun_forwarder (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6) {
- return Thread<RT> (mem_fun_ptr, c,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6));
- }
+ fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
+ : function (*function)
+ {}
+
+ fun_encapsulator (const boost::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
+ : function (function)
+ {}
+
+ inline
+ Thread<RT>
+ operator() (typename boost::tuples::element<0,ArgList>::type arg1,
+ typename boost::tuples::element<1,ArgList>::type arg2,
+ typename boost::tuples::element<2,ArgList>::type arg3,
+ typename boost::tuples::element<3,ArgList>::type arg4,
+ typename boost::tuples::element<4,ArgList>::type arg5)
+ {
+ return fun_wrapper<RT> (boost::bind (function,
+ boost::ref(arg1),
+ boost::ref(arg2),
+ boost::ref(arg3),
+ boost::ref(arg4),
+ boost::ref(arg5))).fire_up ();
+ }
- private:
- C &c;
- MemFunPtr mem_fun_ptr;
- };
-
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions
- * with 6 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6>
- inline
- internal::mem_fun_forwarder<RT,C,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>,6>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6)) {
- return internal::mem_fun_forwarder<RT, C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6>,6> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function
- * for const member functions with
- * 6 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6>
- inline
- internal::mem_fun_forwarder<RT,const C,
- boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>,6>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6) const) {
- return internal::mem_fun_forwarder<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6>,6> (c,fun_ptr);
- }
-
-
-// ----------- forwarders for member functions with 7 arguments
-
- namespace internal
- {
- /**
+ private:
+ boost::function<typename internal::fun_ptr<RT,ArgList>::type> function;
+ };
+
+ /**
* @internal
- * Forwarder class for member
- * functions with 7
- * arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_forwarder<RT, C, ArgList, 7>
+ * Encapsulator class for
+ * functions with 6 arguments.
+ */
+ template <typename RT, typename ArgList>
+ class fun_encapsulator<RT, ArgList, 6>
{
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
public:
- inline mem_fun_forwarder (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7) {
- return Thread<RT> (mem_fun_ptr, c,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7));
- }
+ fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
+ : function (*function)
+ {}
+
+ fun_encapsulator (const boost::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
+ : function (function)
+ {}
+
+ inline
+ Thread<RT>
+ operator() (typename boost::tuples::element<0,ArgList>::type arg1,
+ typename boost::tuples::element<1,ArgList>::type arg2,
+ typename boost::tuples::element<2,ArgList>::type arg3,
+ typename boost::tuples::element<3,ArgList>::type arg4,
+ typename boost::tuples::element<4,ArgList>::type arg5,
+ typename boost::tuples::element<5,ArgList>::type arg6)
+ {
+ return fun_wrapper<RT> (boost::bind (function,
+ boost::ref(arg1),
+ boost::ref(arg2),
+ boost::ref(arg3),
+ boost::ref(arg4),
+ boost::ref(arg5),
+ boost::ref(arg6))).fire_up ();
+ }
private:
- C &c;
- MemFunPtr mem_fun_ptr;
+ boost::function<typename internal::fun_ptr<RT,ArgList>::type> function;
};
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions
- * with 7 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7>
- inline
- internal::mem_fun_forwarder<RT,C,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6, Arg7>,7>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7)) {
- return internal::mem_fun_forwarder<RT, C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7>,7> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function
- * for const member functions with
- * 7 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7>
- inline
- internal::mem_fun_forwarder<RT,const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6, Arg7>,7>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7) const) {
- return internal::mem_fun_forwarder<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7>,7> (c,fun_ptr);
- }
-
-
-// ----------- forwarders for member functions with 8 arguments
-
- namespace internal
- {
- /**
+ /**
* @internal
- * Forwarder class for member
- * functions with 8
- * arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_forwarder<RT, C, ArgList, 8>
+ * Encapsulator class for
+ * functions with 7 arguments.
+ */
+ template <typename RT, typename ArgList>
+ class fun_encapsulator<RT, ArgList, 7>
{
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
public:
- inline mem_fun_forwarder (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7,
- typename boost::tuples::element<7,ArgList>::type arg8) {
- return Thread<RT> (mem_fun_ptr, c,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7,arg8));
- }
+ fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
+ : function (*function)
+ {}
+
+ fun_encapsulator (const boost::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
+ : function (function)
+ {}
+
+ inline
+ Thread<RT>
+ operator() (typename boost::tuples::element<0,ArgList>::type arg1,
+ typename boost::tuples::element<1,ArgList>::type arg2,
+ typename boost::tuples::element<2,ArgList>::type arg3,
+ typename boost::tuples::element<3,ArgList>::type arg4,
+ typename boost::tuples::element<4,ArgList>::type arg5,
+ typename boost::tuples::element<5,ArgList>::type arg6,
+ typename boost::tuples::element<6,ArgList>::type arg7)
+ {
+ return fun_wrapper<RT> (boost::bind (function,
+ boost::ref(arg1),
+ boost::ref(arg2),
+ boost::ref(arg3),
+ boost::ref(arg4),
+ boost::ref(arg5),
+ boost::ref(arg6),
+ boost::ref(arg7))).fire_up ();
+ }
private:
- C &c;
- MemFunPtr mem_fun_ptr;
+ boost::function<typename internal::fun_ptr<RT,ArgList>::type> function;
};
-
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions
- * with 8 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8>
- inline
- internal::mem_fun_forwarder<RT,C,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8>,8>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8)) {
- return internal::mem_fun_forwarder<RT, C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8>,8> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function
- * for const member functions with
- * 8 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8>
- inline
- internal::mem_fun_forwarder<RT,const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8>,8>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8) const) {
- return internal::mem_fun_forwarder<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8>,8> (c,fun_ptr);
- }
-
-
-// ----------- forwarders for member functions with 9 arguments
- namespace internal
- {
- /**
+ /**
* @internal
- * Forwarder class for member
- * functions with 9
- * arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_forwarder<RT, C, ArgList, 9>
+ * Encapsulator class for
+ * functions with 8 arguments.
+ */
+ template <typename RT, typename ArgList>
+ class fun_encapsulator<RT, ArgList, 8>
{
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
public:
- inline mem_fun_forwarder (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7,
- typename boost::tuples::element<7,ArgList>::type arg8,
- typename boost::tuples::element<8,ArgList>::type arg9) {
- return Thread<RT> (mem_fun_ptr, c,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7,arg8,
- arg9));
- }
+ fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
+ : function (*function)
+ {}
+
+ fun_encapsulator (const boost::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
+ : function (function)
+ {}
+
+ inline
+ Thread<RT>
+ operator() (typename boost::tuples::element<0,ArgList>::type arg1,
+ typename boost::tuples::element<1,ArgList>::type arg2,
+ typename boost::tuples::element<2,ArgList>::type arg3,
+ typename boost::tuples::element<3,ArgList>::type arg4,
+ typename boost::tuples::element<4,ArgList>::type arg5,
+ typename boost::tuples::element<5,ArgList>::type arg6,
+ typename boost::tuples::element<6,ArgList>::type arg7,
+ typename boost::tuples::element<7,ArgList>::type arg8)
+ {
+ return fun_wrapper<RT> (boost::bind (function,
+ boost::ref(arg1),
+ boost::ref(arg2),
+ boost::ref(arg3),
+ boost::ref(arg4),
+ boost::ref(arg5),
+ boost::ref(arg6),
+ boost::ref(arg7),
+ boost::ref(arg8))).fire_up ();
+ }
private:
- C &c;
- MemFunPtr mem_fun_ptr;
+ boost::function<typename internal::fun_ptr<RT,ArgList>::type> function;
};
- }
-
- /**
- * Overload of the non-const spawn
- * function for member functions
- * with 9 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8, typename Arg9>
- inline
- internal::mem_fun_forwarder<RT,C,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9>,9>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8,Arg9)) {
- return internal::mem_fun_forwarder<RT, C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9>,9> (c,fun_ptr);
- }
-
- /**
- * Overload of the spawn function
- * for const member functions with
- * 9 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8, typename Arg9>
- inline
- internal::mem_fun_forwarder<RT,const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9>,9>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8,Arg9) const) {
- return internal::mem_fun_forwarder<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9>,9> (c,fun_ptr);
- }
-
-
-// ----------- forwarders for member functions with 10 arguments
-
- namespace internal
- {
- /**
+ /**
* @internal
- * Forwarder class for member
- * functions with 10
- * arguments.
- */
- template <typename RT, typename C, typename ArgList>
- class mem_fun_forwarder<RT, C, ArgList, 10>
+ * Encapsulator class for
+ * functions with 9 arguments.
+ */
+ template <typename RT, typename ArgList>
+ class fun_encapsulator<RT, ArgList, 9>
{
- typedef typename internal::mem_fun_ptr<RT,C,ArgList>::type MemFunPtr;
-
public:
- inline mem_fun_forwarder (C &c, MemFunPtr mem_fun_ptr)
- : c (c), mem_fun_ptr(mem_fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7,
- typename boost::tuples::element<7,ArgList>::type arg8,
- typename boost::tuples::element<8,ArgList>::type arg9,
- typename boost::tuples::element<9,ArgList>::type arg10) {
- return Thread<RT> (mem_fun_ptr, c,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7,arg8,
- arg9, arg10));
- }
+ fun_encapsulator (typename internal::fun_ptr<RT,ArgList>::type *function)
+ : function (*function)
+ {}
+
+ fun_encapsulator (const boost::function<typename internal::fun_ptr<RT,ArgList>::type> &function)
+ : function (function)
+ {}
+
+ inline
+ Thread<RT>
+ operator() (typename boost::tuples::element<0,ArgList>::type arg1,
+ typename boost::tuples::element<1,ArgList>::type arg2,
+ typename boost::tuples::element<2,ArgList>::type arg3,
+ typename boost::tuples::element<3,ArgList>::type arg4,
+ typename boost::tuples::element<4,ArgList>::type arg5,
+ typename boost::tuples::element<5,ArgList>::type arg6,
+ typename boost::tuples::element<6,ArgList>::type arg7,
+ typename boost::tuples::element<7,ArgList>::type arg8,
+ typename boost::tuples::element<8,ArgList>::type arg9)
+ {
+ return fun_wrapper<RT> (boost::bind (function,
+ boost::ref(arg1),
+ boost::ref(arg2),
+ boost::ref(arg3),
+ boost::ref(arg4),
+ boost::ref(arg5),
+ boost::ref(arg6),
+ boost::ref(arg7),
+ boost::ref(arg8),
+ boost::ref(arg9))).fire_up ();
+ }
private:
- C &c;
- MemFunPtr mem_fun_ptr;
+ boost::function<typename internal::fun_ptr<RT,ArgList>::type> function;
};
-
}
+
+
+
+// ----------- encapsulators for functions not taking any parameters
+
/**
- * Overload of the non-const spawn
- * function for member functions
- * with 10 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
+ * Overload of the spawn function for
+ * non-member or static member
+ * functions with no arguments.
*/
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8, typename Arg9,
- typename Arg10>
+ template <typename RT>
inline
- internal::mem_fun_forwarder<RT,C,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9, Arg10>,10>
- spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8,Arg9,Arg10)) {
- return internal::mem_fun_forwarder<RT, C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9,
- Arg10>,10> (c,fun_ptr);
+ internal::fun_encapsulator<RT,boost::tuple<>,0>
+ spawn (RT (*fun_ptr)())
+ {
+ return fun_ptr;
}
+
/**
- * Overload of the spawn function
- * for const member functions with
- * 10 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
+ * Overload of the non-const spawn
+ * function for member functions with
+ * no arguments.
*/
- template <typename RT, typename C,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8, typename Arg9,
- typename Arg10>
+ template <typename RT, typename C>
inline
- internal::mem_fun_forwarder<RT,const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9, Arg10>,10>
- spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8,Arg9,Arg10) const) {
- return internal::mem_fun_forwarder<RT, const C,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9,
- Arg10>,10> (c,fun_ptr);
- }
-
-
-
-// ----------- forwarders for functions not taking any parameters
-
- namespace internal
+ internal::fun_encapsulator<RT,boost::tuple<>,0>
+ spawn (C &c, RT (C::*fun_ptr)())
{
- /**
- * @internal
- * Forwarder class for functions
- * with no arguments.
- */
- template <typename RT, typename ArgList>
- class fun_forwarder<RT, ArgList, 0>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_forwarder (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
-
- inline
- Thread<RT>
- operator() () {
- return Thread<RT> (fun_ptr,
- ArgList());
- }
-
- private:
- FunPtr fun_ptr;
- };
-
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<> >::type>
+ (boost::bind(fun_ptr, boost::ref(c)));
}
-
+
/**
- * Overload of the spawn function
- * for non-member or static member
- * functions with no
- * arguments. This version of the
- * function is only visible if *
- * multithreading is not enabled,
- * but * it has the exact same
- * interface as * if multithreading
- * was enabled.
+ * Overload of the spawn function for
+ * const member functions with no
+ * arguments.
*/
- template <typename RT>
+ template <typename RT, typename C>
inline
- internal::fun_forwarder<RT,boost::tuple<>,0>
- spawn (RT (*fun_ptr)()) {
- return internal::fun_forwarder<RT, boost::tuple<>,0> (fun_ptr);
+ internal::fun_encapsulator<RT,boost::tuple<>,0>
+ spawn (const C &c, RT (C::*fun_ptr)() const)
+ {
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<> >::type>
+ (boost::bind(fun_ptr, boost::cref(c)));
}
+
+// ----------- encapsulators for unary functions
-// ----------- forwarders for unary functions
-
- namespace internal
- {
- /**
- * @internal
- * Forwarder class for functions
- * with 1 argument.
- */
- template <typename RT, typename ArgList>
- class fun_forwarder<RT, ArgList, 1>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_forwarder (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1) {
- return Thread<RT> (fun_ptr,
- boost::tie(arg1));
- }
-
- private:
- FunPtr fun_ptr;
- };
-
- }
-
/**
- * Overload of the spawn function
- * for non-member or static member
- * functions with 1 argument. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
+ * Overload of the spawn function for
+ * non-member or static member
+ * functions with 1 argument.
*/
template <typename RT, typename Arg1>
inline
- internal::fun_forwarder<RT,boost::tuple<Arg1>,1>
- spawn (RT (*fun_ptr)(Arg1)) {
- return internal::fun_forwarder<RT, boost::tuple<Arg1>,1> (fun_ptr);
+ internal::fun_encapsulator<RT,boost::tuple<Arg1>,1>
+ spawn (RT (*fun_ptr)(Arg1))
+ {
+ return fun_ptr;
}
+ /**
+ * Overload of the non-const spawn
+ * function for member functions with
+ * 1 argument.
+ */
+ template <typename RT, typename C, typename Arg1>
+ inline
+ internal::fun_encapsulator<RT,boost::tuple<Arg1>,1>
+ spawn (C &c, RT (C::*fun_ptr)(Arg1))
+ {
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1> >::type>
+ (boost::bind(fun_ptr, boost::ref(c), _1));
+ }
-// ----------- forwarders for binary functions
-
- namespace internal
+ /**
+ * Overload of the spawn function for
+ * const member functions with 1
+ * argument.
+ */
+ template <typename RT, typename C, typename Arg1>
+ inline
+ internal::fun_encapsulator<RT,boost::tuple<Arg1>,1>
+ spawn (const C &c, RT (C::*fun_ptr)(Arg1) const)
{
- /**
- * @internal
- * Forwarder class for functions
- * with 2 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_forwarder<RT, ArgList, 2>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1> >::type>
+ (boost::bind(fun_ptr, boost::cref(c), _1));
+ }
- public:
- inline fun_forwarder (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2) {
- return Thread<RT> (fun_ptr,
- boost::tie(arg1,
- arg2));
- }
-
- private:
- FunPtr fun_ptr;
- };
-
- }
+// ----------- encapsulators for binary functions
/**
- * Overload of the spawn function
- * for non-member or static member
- * functions with 2 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
+ * Overload of the spawn function for
+ * non-member or static member
+ * functions with 2 arguments.
*/
template <typename RT, typename Arg1, typename Arg2>
inline
- internal::fun_forwarder<RT,boost::tuple<Arg1, Arg2>,2>
- spawn (RT (*fun_ptr)(Arg1,Arg2)) {
- return internal::fun_forwarder<RT, boost::tuple<Arg1, Arg2>,2> (fun_ptr);
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2>,2>
+ spawn (RT (*fun_ptr)(Arg1,Arg2))
+ {
+ return fun_ptr;
}
-// ----------- forwarders for ternary functions
-
- namespace internal
+ /**
+ * Overload of the non-const spawn
+ * function for member functions with
+ * 2 arguments.
+ */
+ template <typename RT, typename C, typename Arg1, typename Arg2>
+ inline
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2>,2>
+ spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2))
{
- /**
- * @internal
- * Forwarder class for functions
- * with 3 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_forwarder<RT, ArgList, 3>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1,Arg2> >::type>
+ (boost::bind(fun_ptr, boost::ref(c), _1, _2));
+ }
+
+ /**
+ * Overload of the spawn function for
+ * const member functions with 2
+ * arguments.
+ */
+ template <typename RT, typename C, typename Arg1, typename Arg2>
+ inline
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2>,2>
+ spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2) const)
+ {
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1,Arg2> >::type>
+ (boost::bind(fun_ptr, boost::cref(c), _1, _2));
+ }
- public:
- inline fun_forwarder (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3) {
- return Thread<RT> (fun_ptr,
- boost::tie(arg1,
- arg2,
- arg3));
- }
-
- private:
- FunPtr fun_ptr;
- };
-
- }
+// ----------- encapsulators for ternary functions
/**
- * Overload of the spawn function
- * for non-member or static member
- * functions with 3 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
+ * Overload of the spawn function for
+ * non-member or static member
+ * functions with 3 arguments.
*/
template <typename RT,
typename Arg1, typename Arg2, typename Arg3>
inline
- internal::fun_forwarder<RT,boost::tuple<Arg1, Arg2, Arg3>,3>
- spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3)) {
- return internal::fun_forwarder<RT,
- boost::tuple<Arg1, Arg2, Arg3>,3> (fun_ptr);
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3>,3>
+ spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3))
+ {
+ return fun_ptr;
}
+ /**
+ * Overload of the non-const spawn
+ * function for member functions with
+ * 3 arguments.
+ */
+ template <typename RT, typename C,
+ typename Arg1, typename Arg2, typename Arg3>
+ inline
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3>,3>
+ spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3))
+ {
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1,Arg2,Arg3> >::type>
+ (boost::bind(fun_ptr, boost::ref(c), _1, _2, _3));
+ }
-// ----------- forwarders for functions with 4 arguments
-
- namespace internal
+ /**
+ * Overload of the spawn function for
+ * const member functions with 3
+ * arguments.
+ */
+ template <typename RT, typename C,
+ typename Arg1, typename Arg2, typename Arg3>
+ inline
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3>,3>
+ spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3) const)
{
- /**
- * @internal
- * Forwarder class for functions
- * with 4 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_forwarder<RT, ArgList, 4>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1,Arg2,Arg3> >::type>
+ (boost::bind(fun_ptr, boost::cref(c), _1, _2, _3));
+ }
- public:
- inline fun_forwarder (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4) {
- return Thread<RT> (fun_ptr,
- boost::tie(arg1,arg2,
- arg3,arg4));
- }
-
- private:
- FunPtr fun_ptr;
- };
-
- }
+
+// ----------- encapsulators for functions with 4 arguments
/**
- * Overload of the spawn function
- * for non-member or static member
- * functions with 4 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
+ * Overload of the spawn function for
+ * non-member or static member
+ * functions with 4 arguments.
*/
template <typename RT,
typename Arg1, typename Arg2, typename Arg3, typename Arg4>
inline
- internal::fun_forwarder<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4>,4>
- spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4)) {
- return internal::fun_forwarder<RT,
- boost::tuple<Arg1, Arg2, Arg3, Arg4>,4> (fun_ptr);
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4>,4>
+ spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4))
+ {
+ return fun_ptr;
}
+ /**
+ * Overload of the non-const spawn
+ * function for member functions with
+ * 4 arguments.
+ */
+ template <typename RT, typename C,
+ typename Arg1, typename Arg2, typename Arg3, typename Arg4>
+ inline
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4>,4>
+ spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4))
+ {
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4> >::type>
+ (boost::bind(fun_ptr, boost::ref(c), _1, _2, _3, _4));
+ }
-// ----------- forwarders for functions with 5 arguments
-
- namespace internal
+ /**
+ * Overload of the spawn function for
+ * const member functions with 4
+ * arguments.
+ */
+ template <typename RT, typename C,
+ typename Arg1, typename Arg2, typename Arg3, typename Arg4>
+ inline
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4>,4>
+ spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4) const)
{
- /**
- * @internal
- * Forwarder class for functions
- * with 5 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_forwarder<RT, ArgList, 5>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4> >::type>
+ (boost::bind(fun_ptr, boost::cref(c), _1, _2, _3, _4));
+ }
- public:
- inline fun_forwarder (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5) {
- return Thread<RT> (fun_ptr,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5));
- }
-
- private:
- FunPtr fun_ptr;
- };
-
- }
+// ----------- encapsulators for functions with 5 arguments
/**
- * Overload of the spawn function
- * for non-member or static member
- * functions with 5 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
+ * Overload of the spawn function for
+ * non-member or static member
+ * functions with 5 arguments.
*/
template <typename RT,
typename Arg1, typename Arg2, typename Arg3,
typename Arg4, typename Arg5>
inline
- internal::fun_forwarder<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5>,5>
- spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5)) {
- return internal::fun_forwarder<RT,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5>,5> (fun_ptr);
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5>,5>
+ spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5))
+ {
+ return fun_ptr;
}
-// ----------- forwarders for functions with 6 arguments
- namespace internal
+ /**
+ * Overload of the non-const spawn
+ * function for member functions with
+ * 5 arguments.
+ */
+ template <typename RT, typename C,
+ typename Arg1, typename Arg2, typename Arg3,
+ typename Arg4, typename Arg5>
+ inline
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5>,5>
+ spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5))
{
- /**
- * @internal
- * Forwarder class for functions
- * with 6 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_forwarder<RT, ArgList, 6>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_forwarder (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5> >::type>
+ (boost::bind(fun_ptr, boost::ref(c), _1, _2, _3, _4, _5));
+ }
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6) {
- return Thread<RT> (fun_ptr,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6));
- }
-
- private:
- FunPtr fun_ptr;
- };
-
+ /**
+ * Overload of the spawn function for
+ * const member functions with 5
+ * arguments.
+ */
+ template <typename RT, typename C,
+ typename Arg1, typename Arg2, typename Arg3,
+ typename Arg4, typename Arg5>
+ inline
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5>,5>
+ spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5) const)
+ {
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5> >::type>
+ (boost::bind(fun_ptr, boost::cref(c), _1, _2, _3, _4, _5));
}
+
+
+// ----------- encapsulators for functions with 6 arguments
/**
- * Overload of the spawn function
- * for non-member or static member
- * functions with 6 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
+ * Overload of the spawn function for
+ * non-member or static member
+ * functions with 6 arguments.
*/
template <typename RT,
typename Arg1, typename Arg2, typename Arg3,
typename Arg4, typename Arg5, typename Arg6>
inline
- internal::fun_forwarder<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>,6>
- spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6)) {
- return internal::fun_forwarder<RT,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6>,6> (fun_ptr);
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>,6>
+ spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6))
+ {
+ return fun_ptr;
}
-// ----------- forwarders for functions with 7 arguments
- namespace internal
+ /**
+ * Overload of the non-const spawn
+ * function for member functions with
+ * 6 arguments.
+ */
+ template <typename RT, typename C,
+ typename Arg1, typename Arg2, typename Arg3,
+ typename Arg4, typename Arg5, typename Arg6>
+ inline
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>,6>
+ spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6))
{
- /**
- * @internal
- * Forwarder class for functions
- * with 7 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_forwarder<RT, ArgList, 7>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_forwarder (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6> >::type>
+ (boost::bind(fun_ptr, boost::ref(c), _1, _2, _3, _4, _5, _6));
+ }
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7) {
- return Thread<RT> (fun_ptr,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7));
- }
-
- private:
- FunPtr fun_ptr;
- };
-
+ /**
+ * Overload of the spawn function for
+ * const member functions with 6
+ * arguments.
+ */
+ template <typename RT, typename C,
+ typename Arg1, typename Arg2, typename Arg3,
+ typename Arg4, typename Arg5, typename Arg6>
+ inline
+ internal::fun_encapsulator<RT,
+ boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6>,6>
+ spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6) const)
+ {
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6> >::type>
+ (boost::bind(fun_ptr, boost::cref(c), _1, _2, _3, _4, _5, _6));
}
+
+
+// ----------- encapsulators for functions with 7 arguments
/**
- * Overload of the spawn function
- * for non-member or static member
- * functions with 7 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
+ * Overload of the spawn function for
+ * non-member or static member
+ * functions with 7 arguments.
*/
template <typename RT,
typename Arg1, typename Arg2, typename Arg3,
typename Arg4, typename Arg5, typename Arg6,
typename Arg7>
inline
- internal::fun_forwarder<RT,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6, Arg7>,7>
- spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7)) {
- return internal::fun_forwarder<RT,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7>,7> (fun_ptr);
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3,
+ Arg4, Arg5, Arg6, Arg7>,7>
+ spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7))
+ {
+ return fun_ptr;
}
-// ----------- forwarders for functions with 8 arguments
- namespace internal
+ /**
+ * Overload of the non-const spawn
+ * function for member functions with
+ * 7 arguments.
+ */
+ template <typename RT, typename C,
+ typename Arg1, typename Arg2, typename Arg3,
+ typename Arg4, typename Arg5, typename Arg6,
+ typename Arg7>
+ inline
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3,
+ Arg4, Arg5, Arg6, Arg7>,7>
+ spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7))
{
- /**
- * @internal
- * Forwarder class for functions
- * with 8 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_forwarder<RT, ArgList, 8>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_forwarder (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7> >::type>
+ (boost::bind(fun_ptr, boost::ref(c), _1, _2, _3, _4, _5, _6, _7));
+ }
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7,
- typename boost::tuples::element<7,ArgList>::type arg8) {
- return Thread<RT> (fun_ptr,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7,arg8));
- }
-
- private:
- FunPtr fun_ptr;
- };
-
+ /**
+ * Overload of the spawn function for
+ * const member functions with 7
+ * arguments.
+ */
+ template <typename RT, typename C,
+ typename Arg1, typename Arg2, typename Arg3,
+ typename Arg4, typename Arg5, typename Arg6,
+ typename Arg7>
+ inline
+ internal::fun_encapsulator<RT,
+ boost::tuple<Arg1, Arg2, Arg3,
+ Arg4, Arg5, Arg6, Arg7>,7>
+ spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,Arg6,Arg7) const)
+ {
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7> >::type>
+ (boost::bind(fun_ptr, boost::cref(c), _1, _2, _3, _4, _5, _6, _7));
}
+
+
+// ----------- encapsulators for functions with 8 arguments
/**
- * Overload of the spawn function
- * for non-member or static member
- * functions with 8 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
+ * Overload of the spawn function for
+ * non-member or static member
+ * functions with 8 arguments.
*/
template <typename RT,
typename Arg1, typename Arg2, typename Arg3,
typename Arg4, typename Arg5, typename Arg6,
typename Arg7, typename Arg8>
inline
- internal::fun_forwarder<RT,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8>,8>
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3,
+ Arg4, Arg5, Arg6,
+ Arg7, Arg8>,8>
spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8)) {
- return internal::fun_forwarder<RT,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8>,8> (fun_ptr);
+ Arg6,Arg7,Arg8))
+ {
+ return fun_ptr;
}
-// ----------- forwarders for functions with 9 arguments
- namespace internal
+ /**
+ * Overload of the non-const spawn
+ * function for member functions with
+ * 8 arguments.
+ */
+ template <typename RT, typename C,
+ typename Arg1, typename Arg2, typename Arg3,
+ typename Arg4, typename Arg5, typename Arg6,
+ typename Arg7, typename Arg8>
+ inline
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3,
+ Arg4, Arg5, Arg6,
+ Arg7, Arg8>,8>
+ spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
+ Arg6,Arg7,Arg8))
{
- /**
- * @internal
- * Forwarder class for functions
- * with 9 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_forwarder<RT, ArgList, 9>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_forwarder (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8> >::type>
+ (boost::bind(fun_ptr, boost::ref(c), _1, _2, _3, _4, _5, _6, _7, _8));
+ }
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7,
- typename boost::tuples::element<7,ArgList>::type arg8,
- typename boost::tuples::element<8,ArgList>::type arg9) {
- return Thread<RT> (fun_ptr,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7,arg8,
- arg9));
- }
-
- private:
- FunPtr fun_ptr;
- };
-
+ /**
+ * Overload of the spawn function for
+ * const member functions with 8
+ * arguments.
+ */
+ template <typename RT, typename C,
+ typename Arg1, typename Arg2, typename Arg3,
+ typename Arg4, typename Arg5, typename Arg6,
+ typename Arg7, typename Arg8>
+ inline
+ internal::fun_encapsulator<RT,
+ boost::tuple<Arg1, Arg2, Arg3,
+ Arg4, Arg5, Arg6,
+ Arg7, Arg8>,8>
+ spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
+ Arg6,Arg7,Arg8) const)
+ {
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8> >::type>
+ (boost::bind(fun_ptr, boost::cref(c), _1, _2, _3, _4, _5, _6, _7, _8));
}
+
+
+// ----------- encapsulators for functions with 9 arguments
/**
- * Overload of the spawn function
- * for non-member or static member
- * functions with 9 arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
+ * Overload of the spawn function for
+ * non-member or static member
+ * functions with 9 arguments.
*/
template <typename RT,
typename Arg1, typename Arg2, typename Arg3,
typename Arg4, typename Arg5, typename Arg6,
typename Arg7, typename Arg8, typename Arg9>
inline
- internal::fun_forwarder<RT,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9>,9>
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3,
+ Arg4, Arg5, Arg6,
+ Arg7, Arg8, Arg9>,9>
spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8,Arg9)) {
- return internal::fun_forwarder<RT,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9>,9> (fun_ptr);
+ Arg6,Arg7,Arg8,Arg9))
+ {
+ return fun_ptr;
}
-// ----------- forwarders for functions with 10 arguments
- namespace internal
+ /**
+ * Overload of the non-const spawn
+ * function for member functions with
+ * 9 arguments.
+ */
+ template <typename RT, typename C,
+ typename Arg1, typename Arg2, typename Arg3,
+ typename Arg4, typename Arg5, typename Arg6,
+ typename Arg7, typename Arg8, typename Arg9>
+ inline
+ internal::fun_encapsulator<RT,boost::tuple<Arg1, Arg2, Arg3,
+ Arg4, Arg5, Arg6,
+ Arg7, Arg8, Arg9>,9>
+ spawn (C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
+ Arg6,Arg7,Arg8,Arg9))
{
- /**
- * @internal
- * Forwarder class for functions
- * with 10 arguments.
- */
- template <typename RT, typename ArgList>
- class fun_forwarder<RT, ArgList, 10>
- {
- typedef typename internal::fun_ptr<RT,ArgList>::type FunPtr;
-
- public:
- inline fun_forwarder (FunPtr fun_ptr)
- : fun_ptr(fun_ptr) {}
-
- inline
- Thread<RT>
- operator() (typename boost::tuples::element<0,ArgList>::type arg1,
- typename boost::tuples::element<1,ArgList>::type arg2,
- typename boost::tuples::element<2,ArgList>::type arg3,
- typename boost::tuples::element<3,ArgList>::type arg4,
- typename boost::tuples::element<4,ArgList>::type arg5,
- typename boost::tuples::element<5,ArgList>::type arg6,
- typename boost::tuples::element<6,ArgList>::type arg7,
- typename boost::tuples::element<7,ArgList>::type arg8,
- typename boost::tuples::element<8,ArgList>::type arg9,
- typename boost::tuples::element<9,ArgList>::type arg10) {
- return Thread<RT> (fun_ptr,
- boost::tie(arg1,arg2,
- arg3,arg4,
- arg5,arg6,
- arg7,arg8,
- arg9, arg10));
- }
-
- private:
- FunPtr fun_ptr;
- };
-
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9> >::type>
+ (boost::bind(fun_ptr, boost::ref(c), _1, _2, _3, _4, _5, _6, _7, _8, _9));
}
- /**
- * Overload of the spawn function
- * for non-member or static member
- * functions with 10
- * arguments. This version of the
- * function is only visible if
- * multithreading is not enabled, but
- * it has the exact same interface as
- * if multithreading was enabled.
- */
- template <typename RT,
- typename Arg1, typename Arg2, typename Arg3,
- typename Arg4, typename Arg5, typename Arg6,
- typename Arg7, typename Arg8, typename Arg9,
- typename Arg10>
- inline
- internal::fun_forwarder<RT,boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9, Arg10>,10>
- spawn (RT (*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
- Arg6,Arg7,Arg8,Arg9,Arg10)) {
- return internal::fun_forwarder<RT,
- boost::tuple<Arg1, Arg2, Arg3,
- Arg4, Arg5, Arg6,
- Arg7, Arg8, Arg9,
- Arg10>,10> (fun_ptr);
+ /**
+ * Overload of the spawn function for
+ * const member functions with 9
+ * arguments.
+ */
+ template <typename RT, typename C,
+ typename Arg1, typename Arg2, typename Arg3,
+ typename Arg4, typename Arg5, typename Arg6,
+ typename Arg7, typename Arg8, typename Arg9>
+ inline
+ internal::fun_encapsulator<RT,
+ boost::tuple<Arg1, Arg2, Arg3,
+ Arg4, Arg5, Arg6,
+ Arg7, Arg8, Arg9>,9>
+ spawn (const C &c, RT (C::*fun_ptr)(Arg1,Arg2,Arg3,Arg4,Arg5,
+ Arg6,Arg7,Arg8,Arg9) const)
+ {
+ return
+ boost::function<typename internal::fun_ptr<RT,boost::tuple<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, Arg9> >::type>
+ (boost::bind(fun_ptr, boost::cref(c), _1, _2, _3, _4, _5, _6, _7, _8, _9));
}
-
-#endif // #if (DEAL_II_USE_MT == 1)
-
-
/**
* A container for thread
* Add another thread object to
* the collection.
*/
- ThreadGroup & operator += (const Thread<RT> &t) {
- threads.push_back (t);
- return *this;
- }
+ ThreadGroup & operator += (const Thread<RT> &t)
+ {
+ threads.push_back (t);
+ return *this;
+ }
/**
* Wait for all threads in the