From 0550bfbc8309d64160ddce58025464615afabdbd Mon Sep 17 00:00:00 2001 From: wolf Date: Fri, 11 Apr 2003 00:16:54 +0000 Subject: [PATCH] Work around a problem in gcc3.4, and by this also improve performance a little since a call can be inlined: rather than passing down a pointer to the entry_point function to the base class, pass down the type of its enclosing class as a template argument. The base class can then take the address of the starter function itself. git-svn-id: https://svn.dealii.org/trunk@7385 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/thread_management.h | 87 ++++++++++--------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/deal.II/base/include/base/thread_management.h b/deal.II/base/include/base/thread_management.h index c30f9176c7..cb5235dd63 100644 --- a/deal.II/base/include/base/thread_management.h +++ b/deal.II/base/include/base/thread_management.h @@ -2830,7 +2830,7 @@ namespace Threads }; // forward declare another class - template struct wrapper_base; + template struct wrapper_base; } @@ -2971,11 +2971,24 @@ namespace Threads * Base class for the classes * wrapping function pointers and * arguments for non-member and - * member functions. + * 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 @p{entry_point}, + * 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 + template struct wrapper_base { @@ -2991,20 +3004,14 @@ namespace Threads DescriptionPointer(new internal::thread_description()); ThreadMutex::ScopedLock lock (mutex); - thread_descriptor->create (entry_point, (void *)this); + thread_descriptor->create (&EntryPointClass::entry_point, + (void *)this); condition.wait (mutex); return thread_descriptor; } protected: - /** - * Typedef for the type of a - * thread entry point, as - * required by POSIX. - */ - typedef void * (*EntryPoint) (void *); - /** * Typedef for shared * pointers to the objects @@ -3015,14 +3022,6 @@ namespace Threads boost::shared_ptr > DescriptionPointer; - /** - * Constructor. Take the - * address of a thread entry - * point and store it. - */ - wrapper_base (const EntryPoint ep) - : entry_point (ep) {}; - /** * Shared pointer to the * unique object describing a @@ -3038,16 +3037,6 @@ namespace Threads */ mutable ThreadMutex mutex; mutable ThreadCondition condition; - - private: - /** - * Address of the thread - * entry point. Is set in the - * constructor, and is the - * address of a function in - * derived classes. - */ - const EntryPoint entry_point; }; @@ -3062,7 +3051,7 @@ namespace Threads * @author Wolfgang Bangerth, 2003 */ template - struct fun_wrapper : public wrapper_base + struct fun_wrapper : public wrapper_base > { /** * Typedef for the type of @@ -3097,8 +3086,7 @@ namespace Threads */ fun_wrapper (FunPtr fun_ptr, const ArgReferences &args) - : wrapper_base (&entry_point), - fun_ptr (fun_ptr), + : fun_ptr (fun_ptr), args (args) {}; private: /** @@ -3138,8 +3126,8 @@ namespace Threads */ static void * entry_point (void *arg) { - const wrapper_base *w - = reinterpret_cast*> (arg); + const wrapper_base *w + = reinterpret_cast*> (arg); const fun_wrapper *wrapper = static_cast (w); @@ -3191,6 +3179,15 @@ namespace Threads return 0; }; + + + /** + * Make the base class a + * friend, so that it can + * access the thread entry + * point function. + */ + template friend class wrapper_base; }; @@ -3205,7 +3202,7 @@ namespace Threads * @author Wolfgang Bangerth, 2003 */ template - struct mem_fun_wrapper : public wrapper_base + struct mem_fun_wrapper : public wrapper_base > { /** * Typedef for the type of @@ -3241,10 +3238,10 @@ namespace Threads mem_fun_wrapper (MemFunPtr mem_fun_ptr, C &c, const ArgReferences &args) - : wrapper_base (&entry_point), - c (c), - mem_fun_ptr (mem_fun_ptr), - args (args) {}; + : + c (c), + mem_fun_ptr (mem_fun_ptr), + args (args) {}; private: /** * Default constructor. Made @@ -3285,8 +3282,8 @@ namespace Threads */ static void * entry_point (void *arg) { - const wrapper_base *w - = reinterpret_cast*> (arg); + const wrapper_base *w + = reinterpret_cast*> (arg); const mem_fun_wrapper *wrapper = static_cast (w); @@ -3339,6 +3336,14 @@ namespace Threads return 0; }; + + /** + * Make the base class a + * friend, so that it can + * access the thread entry + * point function. + */ + template friend class wrapper_base; }; } -- 2.39.5