This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch to gthr-win32.h


 
 
Hello

In current version of the mingw multithread support dll for
C++ exceptions, the key/dtor code is thread dependent.  This can
lead to memory leaks, since only the first dying thread will have its
additional memory for exception handling freed.

Thomas Pfaff has submitted a patch to the mingw runtime that corrects this
problem. The following patch to the gthr-win32.h complements that patch, by
letting __gthread_key_dtor act like the posix version during sjlj chain
unwinding.  

The patch also cleans up some problems with prototypes when included
from libstdc++ stl_threads.h and removes a duplicate include of _mingw.h

Bootstrapped and tested (using modified mingw runtime) under following
configuration:

../gcc/configure --with-gnu-ld --with-gnu-as --host=i586-pc-mingw32
--target=i586-pc-mingw32 --prefix=/mingw --enable-sjlj-exceptions
--enable-threads --disable-nls --enable-languages=c++,f77
--disable-win32-registry 

Please apply to trunk.

Note that in oder to "minimise the diff" and also to retain the ordering
of functions as listed in gthr.h comments, I have put in a forward
declaration for __gthread_set_specific.  Thomas has suggested that the
alternative (reordering the function definitions) might be cleaner. 

2001-11-21 Thomas Pfaff <tpfaff@gmx.net>

	* gthr-win32.h (__gthread_key_dtor): Let it act like the posix
	version in gthr-posix.h
	(__ghthread_key_delete): Call __mingwthr_remove_key_dtor to
	remove the key from the key/dtor list.

2001-11-21 Mumit Khan  <khan@nanotech.wisc.edu>

	* gthr-win32.h: Update copyright statement.
	Wrap prototypes for external mingw runtime functions in
	extern "C" if __cplusplus.
	(_mingw.h) Remove second include.
	


Index: gcc/gcc/gthr-win32.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gthr-win32.h,v
retrieving revision 1.11
diff -u -p -r1.11 gthr-win32.h
--- gthr-win32.h	2001/10/12 13:10:33	1.11
+++ gthr-win32.h	2001/11/19 20:49:38
@@ -1,6 +1,6 @@
 /* Threads compatibility routines for libgcc2 and libobjc.  */
 /* Compile this one with gcc.  */
-/* Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
    Contributed by Mumit Khan <khan@xraylith.wisc.edu>.
 
 This file is part of GCC.
@@ -320,10 +322,6 @@ __gthread_objc_condition_signal(objc_con
 
 #else /* _LIBOBJC */
 
-#ifdef __MINGW32__
-#include <_mingw.h>
-#endif
-
 typedef DWORD __gthread_key_t;
 
 typedef struct {
@@ -339,7 +337,14 @@ typedef HANDLE __gthread_mutex_t;
 #if __MINGW32_MAJOR_VERSION >= 1 || \
   (__MINGW32_MAJOR_VERSION == 0 && __MINGW32_MINOR_VERSION > 2)
 #define MINGW32_SUPPORTS_MT_EH 1
-extern int __mingwthr_key_dtor PARAMS ((DWORD, void (*) (void *)));
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern int __mingwthr_key_dtor (DWORD, void (*) (void *));
+extern int __mingwthr_remove_key_dtor (DWORD);
+#ifdef __cplusplus
+}
+#endif
 /* Mingw runtime >= v0.3 provides a magic variable that is set to non-zero
    if -mthreads option was specified, or 0 otherwise. This is to get
around 
    the lack of weak symbols in PE-COFF.  */
@@ -410,16 +415,26 @@ __gthread_key_create (__gthread_key_t *k
 
 /* Currently, this routine is called only for Mingw runtime, and if
    -mthreads option is chosen to link in the thread support DLL.  */ 
+
 static inline int
-__gthread_key_dtor (__gthread_key_t key, void *ptr)
-{
-  /* Nothing needed.  */
-  return 0;
-}
+__gthread_setspecific (__gthread_key_t key, const void *ptr);
 
 static inline int
+__gthread_key_dtor (__gthread_key_t key, void *ptr)
+  {
+  /* Just reset the key value to zero.  */
+  if (ptr)
+     return  __gthread_setspecific(key, 0);
+  else
+    return 0;  /* Nothing needed.  */
+}
+  
+ static inline int
 __gthread_key_delete (__gthread_key_t key)
 {
+#ifdef MINGW32_SUPPORTS_MT_EH
+  __mingwthr_remove_key_dtor(key);
+#endif
   return (TlsFree (key) != 0) ? 0 : (int) GetLastError ();
 }
 




http://shopping.yahoo.com.au - Yahoo! Shopping
- Get organised for Christmas early this year!


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]