From 852301b8f4aa32ce6f8adda2eb913fbd8017c8c9 Mon Sep 17 00:00:00 2001 From: wolf Date: Thu, 16 Aug 2001 14:58:13 +0000 Subject: [PATCH] spawn wrappers for member functions with 7 args. git-svn-id: https://svn.dealii.org/trunk@4895 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/thread_management.h | 321 +++++++++++++++++- 1 file changed, 319 insertions(+), 2 deletions(-) diff --git a/deal.II/base/include/base/thread_management.h b/deal.II/base/include/base/thread_management.h index f2af12e6c0..dacd9ac5f7 100644 --- a/deal.II/base/include/base/thread_management.h +++ b/deal.II/base/include/base/thread_management.h @@ -2713,6 +2713,165 @@ namespace Threads encapsulate (void (Class_::*fun_ptr)(Arg1_, Arg2_, Arg3_, Arg4_, Arg5_, Arg6_)); }; + + + +/** + * Class to store the parameters of a function with 7 arguments. For + * more information on use and internals of this class see the report + * on this subject. + * + * @author Wolfgang Bangerth, Ralf Hartmann, 2001 + */ + template + class MemFunData7 : public FunDataBase + { + public: + /** + * Typedef a pointer to a global + * function which we will call + * from this class. + */ + typedef RetType (Class::*FunPtr) (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7); + + /** + * Constructor. Store pointer to + * the function and the values of + * the arguments. + */ + MemFunData7 (FunPtr fun_ptr, + Class *object, + Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6, + Arg7 arg7); + + /** + * Copy constructor. + */ + MemFunData7 (const MemFunData7 &fun_data7); + + /** + * Virtual constructor. + */ + virtual FunDataBase * clone () const; + + private: + + /** + * Pointer to the function to be + * called and values of the + * arguments to be passed. + */ + FunPtr fun_ptr; + + /** + * Pointer to the object which + * we shall work on. + */ + Class *object; + + /** + * Values of the arguments of the + * function to be called. + */ + Arg1 arg1; + Arg2 arg2; + Arg3 arg3; + Arg4 arg4; + Arg5 arg5; + Arg6 arg6; + Arg7 arg7; + + /** + * Static function used as entry + * point for the new thread. + */ + static void * thread_entry_point (void *arg); + + /** + * Helper class, used to collect + * the values of the parameters + * which we will pass to the + * function, once we know its + * type. + */ + class ArgCollector + { + public: + /** + * Typedef the function + * pointer type of the + * underlying class to a + * local type. + */ + typedef typename MemFunData7::FunPtr FunPtr; + + /** + * Constructor. Take and store a + * pointer to the function which + * is to be called. + */ + ArgCollector (FunPtr fun_ptr); + + /** + * Take the arguments with + * which we want to call the + * function and produce and + * object of the desired type + * from that. + */ + FunEncapsulation collect_args (Class *object, + Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6, + Arg7 arg7); + + /** + * Same as above, but take + * a reference instead of a + * pointer. This allows us + * to be a little + * convenient, as we can + * use @p{object} or + * @p{this}, without taking + * care that one is a + * reference and the other + * a pointer. + */ + FunEncapsulation collect_args (Class &object, + Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6, + Arg7 arg7); + private: + /** + * Space to temporarily store + * the function pointer. + */ + FunPtr fun_ptr; + }; + + /** + * Declare a function that uses + * the @ref{ArgCollector} as + * friend. + */ + template + friend + typename MemFunData7::ArgCollector + encapsulate (void (Class_::*fun_ptr)(Arg1_, Arg2_, Arg3_, + Arg4_, Arg5_, Arg6_, Arg7_)); + }; /** @@ -3007,6 +3166,22 @@ namespace Threads typename MemFunData6::ArgCollector encapsulate (void (Class::*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)); + /** + * Encapsulate a member function + * pointer into an object with + * which a new thread can later be + * spawned. For more information + * on use and internals of this + * class see the report on this + * subject. + * + * This function exists once for + * each number of parameters. + */ + template + typename MemFunData7::ArgCollector + encapsulate (void (Class::*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)); + /** * Spawn a new thread using the @@ -4985,6 +5160,139 @@ namespace Threads { return collect_args (&object, arg1, arg2, arg3, arg4, arg5, arg6); }; + + + + + +/* ---------------------- MemFunData7 implementation ------------------------ */ + + template + MemFunData7::MemFunData7 (FunPtr fun_ptr, + Class *object, + Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6, + Arg7 arg7) : + FunDataBase (&MemFunData7::thread_entry_point), + fun_ptr (fun_ptr), + object (object), + arg1 (arg1), + arg2 (arg2), + arg3 (arg3), + arg4 (arg4), + arg5 (arg5), + arg6 (arg6), + arg7 (arg7) + {}; + + + + template + MemFunData7::MemFunData7 (const MemFunData7 &fun_data) : + FunDataBase (fun_data), + fun_ptr (fun_data.fun_ptr), + object (fun_data.object), + arg1 (fun_data.arg1), + arg2 (fun_data.arg2), + arg3 (fun_data.arg3), + arg4 (fun_data.arg4), + arg5 (fun_data.arg5), + arg6 (fun_data.arg6), + arg7 (fun_data.arg7) + {}; + + + + template + FunDataBase * + MemFunData7::clone () const + { + return new MemFunData7 (*this); + }; + + + + template + void * + MemFunData7::thread_entry_point (void *arg) + { + // convenience typedef, since we + // will need that class name + // several times below + typedef MemFunData7 ThisClass; + + FunEncapsulation *fun_encapsulation + = reinterpret_cast(arg); + const ThisClass *fun_data + = dynamic_cast (fun_encapsulation->fun_data_base); + + // copy the parameters + ThisClass::FunPtr fun_ptr = fun_data->fun_ptr; + Class *object = fun_data->object; + Arg1 arg1 = fun_data->arg1; + Arg2 arg2 = fun_data->arg2; + Arg3 arg3 = fun_data->arg3; + Arg4 arg4 = fun_data->arg4; + Arg5 arg5 = fun_data->arg5; + Arg6 arg6 = fun_data->arg6; + Arg7 arg7 = fun_data->arg7; + + + // copying of parameters is done, + // now we can release the lock on + // @p{fun_data} + fun_data->lock.release (); + + // call the function + (object->*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6, arg7); + + return 0; + }; + + + + template + MemFunData7::ArgCollector::ArgCollector (FunPtr fun_ptr) : + fun_ptr (fun_ptr) + {}; + + + + template + FunEncapsulation + MemFunData7::ArgCollector::collect_args (Class *object, + Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6, + Arg7 arg7) + { + return new MemFunData7(fun_ptr, object, + arg1, arg2, arg3, arg4, arg5, arg6, arg7); + }; + + + + template + inline + FunEncapsulation + MemFunData7::ArgCollector::collect_args (Class &object, + Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6, + Arg7 arg7) + { + return collect_args (&object, arg1, arg2, arg3, arg4, arg5, arg6, arg7); + }; /* ---------------------------------------------------------------- */ @@ -5153,6 +5461,15 @@ namespace Threads + template + typename MemFunData7::ArgCollector + encapsulate (void (Class::*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)) + { + return fun_ptr; + }; + + + template typename std::vector > split_range (const ForwardIterator &begin, @@ -5194,8 +5511,8 @@ namespace Threads // template type, which // here is unsigned if no // cast is performed) - advance (return_values[i].second, - static_cast(n_elements_per_interval)); + std::advance (return_values[i].second, + static_cast(n_elements_per_interval)); // distribute residual in // division equally among // the first few -- 2.39.5