From: hartmann Date: Mon, 15 May 2000 07:50:46 +0000 (+0000) Subject: mt for functions with 6 args. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a9fc9471bf27722e14c8409aa302156dcddce0a;p=dealii-svn.git mt for functions with 6 args. git-svn-id: https://svn.dealii.org/trunk@2848 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/thread_management.h b/deal.II/base/include/base/thread_management.h index 7a1ad42aee..b97af5ad5d 100644 --- a/deal.II/base/include/base/thread_management.h +++ b/deal.II/base/include/base/thread_management.h @@ -815,6 +815,121 @@ namespace Threads }; }; + +/** + * Class to store the parameters of a function with 6 arguments. For more + * information on use and internals of this class see the report on + * this subject. + * + * @author Ralf Hartmann, 2000 + */ + template + class FunData6 : public FunDataBase + { + public: + /** + * Typedef a pointer to a global + * function which we will call + * from this class. + */ + typedef RetType (*FunPtr) (Arg1, Arg2, Arg3, Arg4, Arg5, Arg6); + + /** + * Constructor. Store pointer to + * the function and the values of + * the arguments. + */ + FunData6 (FunPtr fun_ptr, + Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6); + + /** + * Copy constructor. + */ + FunData6 (const FunData6 &fun_data6); + + /** + * 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; + + /** + * Values of the arguments of the + * function to be called. + */ + Arg1 arg1; + Arg2 arg2; + Arg3 arg3; + Arg4 arg4; + Arg5 arg5; + Arg6 arg6; + + /** + * 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 FunData6::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 (Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6); + + private: + /** + * Space to temporarily store + * the function pointer. + */ + FunPtr fun_ptr; + }; + }; /** @@ -1496,6 +1611,131 @@ namespace Threads }; }; + + +/** + * Class to store the parameters of a function with 6 arguments. For + * more information on use and internals of this class see the report + * on this subject. + * + * @author Ralf Hartmann, 2000 + */ + template + class MemFunData6 : 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); + + /** + * Constructor. Store pointer to + * the function and the values of + * the arguments. + */ + MemFunData6 (FunPtr fun_ptr, + Class *object, + Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6); + + /** + * Copy constructor. + */ + MemFunData6 (const MemFunData6 &fun_data6); + + /** + * 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; + + /** + * 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 MemFunData6::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); + + private: + /** + * Space to temporarily store + * the function pointer. + */ + FunPtr fun_ptr; + }; + }; + /** * Encapsulate a function pointer @@ -1589,7 +1829,23 @@ namespace Threads */ template typename FunData5::ArgCollector - encapsulate (void (*fun_ptr)(Arg1, Arg2, Arg3, Arg4,Arg5)); + encapsulate (void (*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5)); + + + /** + * Encapsulate a 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 FunData6::ArgCollector + encapsulate (void (*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)); /** @@ -1693,7 +1949,23 @@ namespace Threads encapsulate (void (Class::*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5)); + /** + * 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 MemFunData6::ArgCollector + encapsulate (void (Class::*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)); + /** * Spawn a new thread using the * function and parameters @@ -2337,6 +2609,111 @@ namespace Threads return new FunData5(fun_ptr, arg1, arg2, arg3, arg4, arg5); }; + + + + +/* ---------------------- FunData6 implementation ------------------------ */ + + template + FunData6::FunData6 (FunPtr fun_ptr, + Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6) : + FunDataBase (&FunData6::thread_entry_point), + fun_ptr (fun_ptr), + arg1 (arg1), + arg2 (arg2), + arg3 (arg3), + arg4 (arg4), + arg5 (arg5), + arg6 (arg6) + {}; + + + + template + FunData6::FunData6 (const FunData6 &fun_data) : + FunDataBase (fun_data), + fun_ptr (fun_data.fun_ptr), + arg1 (fun_data.arg1), + arg2 (fun_data.arg2), + arg3 (fun_data.arg3), + arg4 (fun_data.arg4), + arg5 (fun_data.arg5), + arg6 (fun_data.arg6) + {}; + + + + template + FunDataBase * + FunData6::clone () const + { + return new FunData6 (*this); + }; + + + + template + void * + FunData6::thread_entry_point (void *arg) + { + // convenience typedef, since we + // will need that class name + // several times below + typedef FunData6 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; + 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; + + + // copying of parameters is done, + // now we can release the lock on + // #fun_data# + fun_data->lock.release (); + + // call the function + (*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6); + + return 0; + }; + + + + template + FunData6::ArgCollector::ArgCollector (FunPtr fun_ptr) : + fun_ptr (fun_ptr) + {}; + + + + template + FunEncapsulation + FunData6::ArgCollector::collect_args (Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6) + { + return new FunData6(fun_ptr, arg1, arg2, + arg3, arg4, arg5, arg6); + }; @@ -2890,6 +3267,116 @@ namespace Threads + +/* ---------------------- MemFunData6 implementation ------------------------ */ + + template + MemFunData6::MemFunData6 (FunPtr fun_ptr, + Class *object, + Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6) : + FunDataBase (&MemFunData6::thread_entry_point), + fun_ptr (fun_ptr), + object (object), + arg1 (arg1), + arg2 (arg2), + arg3 (arg3), + arg4 (arg4), + arg5 (arg5), + arg6 (arg6) + {}; + + + + template + MemFunData6::MemFunData6 (const MemFunData6 &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) + {}; + + + + template + FunDataBase * + MemFunData6::clone () const + { + return new MemFunData6 (*this); + }; + + + + template + void * + MemFunData6::thread_entry_point (void *arg) + { + // convenience typedef, since we + // will need that class name + // several times below + typedef MemFunData6 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; + + + // copying of parameters is done, + // now we can release the lock on + // #fun_data# + fun_data->lock.release (); + + // call the function + (object->*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6); + + return 0; + }; + + + + template + MemFunData6::ArgCollector::ArgCollector (FunPtr fun_ptr) : + fun_ptr (fun_ptr) + {}; + + + + template + FunEncapsulation + MemFunData6::ArgCollector::collect_args (Class *object, + Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6) + { + return new MemFunData6(fun_ptr, object, + arg1, arg2, arg3, arg4, arg5, arg6); + }; + + + /* ---------------------------------------------------------------- */ @@ -2936,6 +3423,7 @@ namespace Threads return fun_ptr; }; + template FunData5::ArgCollector @@ -2943,7 +3431,17 @@ namespace Threads { return fun_ptr; }; + + + template + FunData6::ArgCollector + encapsulate (void (*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) + { + return fun_ptr; + }; + + template MemFunData0::ArgCollector @@ -2999,6 +3497,15 @@ namespace Threads + template + MemFunData6::ArgCollector + encapsulate (void (Class::*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)) + { + return fun_ptr; + }; + + + template vector > split_range (const ForwardIterator &begin, const ForwardIterator &end,