From: wolf Date: Thu, 26 Oct 2000 14:25:06 +0000 (+0000) Subject: Implement FunData for 7 and 8 arguments. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fdbaf41f5d994e83add339596b86b70c8d98f6ce;p=dealii-svn.git Implement FunData for 7 and 8 arguments. git-svn-id: https://svn.dealii.org/trunk@3459 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 d5ef6ab2aa..2a3293cf0f 100644 --- a/deal.II/base/include/base/thread_management.h +++ b/deal.II/base/include/base/thread_management.h @@ -929,7 +929,7 @@ namespace Threads * information on use and internals of this class see the report on * multithreading. * - * @author Wolfgang Bangerth, Ralf Hartmann, 2000 + * @author Wolfgang Bangerth, 2000 */ template class FunData6 : public FunDataBase @@ -1040,6 +1040,247 @@ namespace Threads }; +/** + * 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 + * multithreading. + * + * @author Wolfgang Bangerth, 2000 + */ + template + class FunData7 : 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, Arg7); + + /** + * Constructor. Store pointer to + * the function and the values of + * the arguments. + */ + FunData7 (FunPtr fun_ptr, + Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6, + Arg7 arg7); + + /** + * Copy constructor. + */ + FunData7 (const FunData7 &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; + + /** + * 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 FunData7::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, + Arg7 arg7); + + private: + /** + * Space to temporarily store + * the function pointer. + */ + FunPtr fun_ptr; + }; + }; + + +/** + * Class to store the parameters of a function with 8 arguments. For more + * information on use and internals of this class see the report on + * multithreading. + * + * @author Wolfgang Bangerth, 2000 + */ + template + class FunData8 : 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, Arg7, Arg8); + + /** + * Constructor. Store pointer to + * the function and the values of + * the arguments. + */ + FunData8 (FunPtr fun_ptr, + Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6, + Arg7 arg7, + Arg8 arg8); + + /** + * Copy constructor. + */ + FunData8 (const FunData8 &fun_data8); + + /** + * 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; + Arg7 arg7; + Arg8 arg8; + + /** + * 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 FunData8::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, + Arg7 arg7, + Arg8 arg8); + + private: + /** + * Space to temporarily store + * the function pointer. + */ + FunPtr fun_ptr; + }; + }; + + /** * Class to store the parameters of a void function. For more * information on use and internals of this class see the report on @@ -2072,6 +2313,38 @@ namespace Threads encapsulate (void (*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6)); + /** + * 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 multithreading. + * + * This function exists once for + * each number of parameters. + */ + template + typename FunData7::ArgCollector + encapsulate (void (*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7)); + + + /** + * 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 multithreading. + * + * This function exists once for + * each number of parameters. + */ + template + typename FunData8::ArgCollector + encapsulate (void (*fun_ptr)(Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8)); + + /** * Encapsulate a member function * pointer into an object with @@ -2943,6 +3216,234 @@ namespace Threads +/* ---------------------- FunData7 implementation ------------------------ */ + + template + FunData7::FunData7 (FunPtr fun_ptr, + Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6, + Arg7 arg7) : + FunDataBase (&FunData7::thread_entry_point), + fun_ptr (fun_ptr), + arg1 (arg1), + arg2 (arg2), + arg3 (arg3), + arg4 (arg4), + arg5 (arg5), + arg6 (arg6), + arg7 (arg7) + {}; + + + + template + FunData7::FunData7 (const FunData7 &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), + arg7 (fun_data.arg7) + {}; + + + + template + FunDataBase * + FunData7::clone () const + { + return new FunData7 (*this); + }; + + + + template + void * + FunData7::thread_entry_point (void *arg) + { + // convenience typedef, since we + // will need that class name + // several times below + typedef FunData7 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; + 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 + (*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6, arg7); + + return 0; + }; + + + + template + FunData7::ArgCollector::ArgCollector (FunPtr fun_ptr) : + fun_ptr (fun_ptr) + {}; + + + + template + FunEncapsulation + FunData7::ArgCollector::collect_args (Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6, + Arg7 arg7) + { + return new FunData7(fun_ptr, arg1, arg2, + arg3, arg4, arg5, arg6, arg7); + }; + + + + + +/* ---------------------- FunData8 implementation ------------------------ */ + + template + FunData8::FunData8 (FunPtr fun_ptr, + Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6, + Arg7 arg7, + Arg8 arg8) : + FunDataBase (&FunData8::thread_entry_point), + fun_ptr (fun_ptr), + arg1 (arg1), + arg2 (arg2), + arg3 (arg3), + arg4 (arg4), + arg5 (arg5), + arg6 (arg6), + arg7 (arg7), + arg8 (arg8) + {}; + + + + template + FunData8::FunData8 (const FunData8 &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), + arg7 (fun_data.arg7), + arg8 (fun_data.arg8) + {}; + + + + template + FunDataBase * + FunData8::clone () const + { + return new FunData8 (*this); + }; + + + + template + void * + FunData8::thread_entry_point (void *arg) + { + // convenience typedef, since we + // will need that class name + // several times below + typedef FunData8 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; + Arg7 arg7 = fun_data->arg7; + Arg8 arg8 = fun_data->arg8; + + + // copying of parameters is done, + // now we can release the lock on + // @p{fun_data} + fun_data->lock.release (); + + // call the function + (*fun_ptr)(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); + + return 0; + }; + + + + template + FunData8::ArgCollector::ArgCollector (FunPtr fun_ptr) : + fun_ptr (fun_ptr) + {}; + + + + template + FunEncapsulation + FunData8::ArgCollector::collect_args (Arg1 arg1, + Arg2 arg2, + Arg3 arg3, + Arg4 arg4, + Arg5 arg5, + Arg6 arg6, + Arg7 arg7, + Arg8 arg8) + { + return new FunData8(fun_ptr, arg1, arg2, + arg3, arg4, arg5, arg6, + arg7, arg8); + }; + + + + + /* ---------------------- MemFunData0 implementation ------------------------ */ template