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] PR35063 __gthread_mutex_destroy


Hello,

the attached patch adds __gthread_mutex_destroy as a function that all
thread implementations must provide. For posix, posix95, dce and tpf it
calls pthread_mutex_destroy, for win32 it calls CloseHandle, and for the
rest there is a null implementation that always returns success.

The origin of the patch was a gfortran bugreport where libgfortran
exhausted the available handles on windows due to not destroying the
mutex. As 4.3 was really close, it was decided to do a minimally
instrusive patch that only fixed the issue on windows where it was
reported (see http://gcc.gnu.org/ml/fortran/2008-02/msg00072.html). This
is the "proper" fix, and also fixes libgfortran to use
__gthread_mutex_destroy rather than the macro kludge the 4.3 patch did.

For the patch, I have merely guessed that the posix95, dce and tpf
implementations provide pthread_mutex_destroy, as I have no way of
testing these.

Ok for trunk?

-- 
Janne Blomqvist
gcc:

2008-02-25  Janne Blomqvist  <jb@gcc.gnu.org>

	PR gcc/35063
	* gthr.h: Add __gthread_mutex_destroy as a function that must be
	implemented.
	* gthr-vxworks.h (__gthread_mutex_destroy): Null implementation.
	* gthr-single.h (__gthread_mutex_destroy): Likewise.
	* gthr-rtems.h (__gthread_mutex_destroy): Likewise.
	* gthr-mipssde.h (__gthread_mutex_destroy): Likewise.
	* gthr-nks.h (__gthread_mutex_destroy): Likewise.
	* gthr-solaris.h (__gthread_mutex_destroy): Likewise.
	* gthr-win32.h (__GTHREAD_MUTEX_DESTROY_FUNCTION): Remove.
	(__gthread_mutex_destroy_function): Rename to
	__gthread_mutex_destroy.
	* gthr-dce.h (__gthread_mutex_destroy): Call
	pthread_mutex_destroy.
	* gthr-tpf.h (__gthread_mutex_destroy): Likewise.
	* gthr-posix.h (__gthread_mutex_destroy): Likewise.
	* gthr-posix95.h (__gthread_mutex_destroy): Likewise.


libgfortran:

2008-02-25  Janne Blomqvist  <jb@gcc.gnu.org>

	PR libfortran/35063
	* io/unit.c (destroy_unit_mutex): Call __gthread_mutex_destroy
	instead of macro kludge.
	
Index: gcc/gthr-vxworks.h
===================================================================
--- gcc/gthr-vxworks.h	(revision 132636)
+++ gcc/gthr-vxworks.h	(working copy)
@@ -61,6 +61,12 @@ __gthread_mutex_init_function (__gthread
 }
 
 static inline int
+__gthread_mutex_destroy (__gthread_mutex_t * UNUSED(mutex))
+{
+  return 0;
+}
+
+static inline int
 __gthread_mutex_lock (__gthread_mutex_t *mutex)
 {
   return semTake (*mutex, WAIT_FOREVER);
Index: gcc/gthr-win32.h
===================================================================
--- gcc/gthr-win32.h	(revision 132636)
+++ gcc/gthr-win32.h	(working copy)
@@ -359,9 +359,6 @@ typedef struct {
   __gthread_recursive_mutex_init_function
 #define __GTHREAD_RECURSIVE_MUTEX_INIT_DEFAULT {-1, 0, 0, 0}
 
-#define __GTHREAD_MUTEX_DESTROY_FUNCTION \
-  __gthread_mutex_destroy_function
-
 #if __MINGW32_MAJOR_VERSION >= 1 || \
   (__MINGW32_MAJOR_VERSION == 0 && __MINGW32_MINOR_VERSION > 2)
 #define MINGW32_SUPPORTS_MT_EH 1
@@ -619,7 +616,7 @@ __gthread_mutex_init_function (__gthread
 }
 
 static inline void
-__gthread_mutex_destroy_function (__gthread_mutex_t *mutex)
+__gthread_mutex_destroy (__gthread_mutex_t *mutex)
 {
   CloseHandle ((HANDLE) mutex->sema);
 }
Index: gcc/gthr-single.h
===================================================================
--- gcc/gthr-single.h	(revision 132636)
+++ gcc/gthr-single.h	(working copy)
@@ -216,6 +216,12 @@ __gthread_active_p (void)
 }
 
 static inline int
+__gthread_mutex_destroy (__gthread_mutex_t * UNUSED(mutex))
+{
+  return 0;
+}
+
+static inline int
 __gthread_mutex_lock (__gthread_mutex_t * UNUSED(mutex))
 {
   return 0;
Index: gcc/gthr-rtems.h
===================================================================
--- gcc/gthr-rtems.h	(revision 132636)
+++ gcc/gthr-rtems.h	(working copy)
@@ -111,6 +111,12 @@ __gthread_setspecific (__gthread_key_t k
 }
 
 static inline int
+__gthread_mutex_destroy (__gthread_mutex_t * UNUSED(mutex))
+{
+  return 0;
+}
+
+static inline int
 __gthread_mutex_lock (__gthread_mutex_t *mutex)
 {
     return rtems_gxx_mutex_lock (mutex);
Index: gcc/gthr-mipssde.h
===================================================================
--- gcc/gthr-mipssde.h	(revision 132636)
+++ gcc/gthr-mipssde.h	(working copy)
@@ -135,6 +135,12 @@ __gthread_setspecific (__gthread_key_t k
 }
 
 static inline int
+__gthread_mutex_destroy (__gthread_mutex_t * UNUSED(mutex))
+{
+  return 0;
+}
+
+static inline int
 __gthread_mutex_lock (__gthread_mutex_t *mutex)
 {
   if (__gthread_active_p ())
Index: gcc/gthr-nks.h
===================================================================
--- gcc/gthr-nks.h	(revision 132636)
+++ gcc/gthr-nks.h	(working copy)
@@ -342,6 +342,12 @@ __gthread_mutex_init_function (__gthread
 }
 
 static inline int
+__gthread_mutex_destroy (__gthread_mutex_t * UNUSED(mutex))
+{
+  return 0;
+}
+
+static inline int
 __gthread_mutex_lock (__gthread_mutex_t *mutex)
 {
   return NXLock (*mutex);
Index: gcc/gthr.h
===================================================================
--- gcc/gthr.h	(revision 132636)
+++ gcc/gthr.h	(working copy)
@@ -73,6 +73,8 @@ Software Foundation, 51 Franklin Street,
      void *__gthread_getspecific (__gthread_key_t key)
      int __gthread_setspecific (__gthread_key_t key, const void *ptr)
 
+     int __gthread_mutex_destroy (__gthread_mutex_t *mutex);
+
      int __gthread_mutex_lock (__gthread_mutex_t *mutex);
      int __gthread_mutex_trylock (__gthread_mutex_t *mutex);
      int __gthread_mutex_unlock (__gthread_mutex_t *mutex);
Index: gcc/gthr-dce.h
===================================================================
--- gcc/gthr-dce.h	(revision 132636)
+++ gcc/gthr-dce.h	(working copy)
@@ -71,6 +71,7 @@ __gthrw(pthread_getspecific)
 __gthrw(pthread_setspecific)
 __gthrw(pthread_create)
 __gthrw(pthread_mutex_init)
+__gthrw(pthread_mutex_destroy)
 __gthrw(pthread_mutex_lock)
 __gthrw(pthread_mutex_trylock)
 __gthrw(pthread_mutex_unlock)
@@ -475,6 +476,12 @@ __gthread_mutex_init_function (__gthread
 }
 
 static inline int
+__gthread_mutx_destroy (__gthread_mutex_t *mutex)
+{
+  return __gthrw_(pthread_mutex_destroy) (mutex);
+}
+
+static inline int
 __gthread_mutex_lock (__gthread_mutex_t *mutex)
 {
   if (__gthread_active_p ())
Index: gcc/gthr-tpf.h
===================================================================
--- gcc/gthr-tpf.h	(revision 132636)
+++ gcc/gthr-tpf.h	(working copy)
@@ -92,6 +92,7 @@ __gthrw(pthread_mutexattr_init)
 __gthrw(pthread_mutexattr_settype)
 __gthrw(pthread_mutexattr_destroy)
 __gthrw(pthread_mutex_init)
+__gthrw(pthread_mutex_destroy)
 
 static inline int
 __gthread_active_p (void)
@@ -145,6 +146,12 @@ __gthread_setspecific (__gthread_key_t k
 }
 
 static inline int
+__gthread_mutex_destroy (__gthread_mutex_t *mutex)
+{
+    return __gthrw_(pthread_mutex_destroy) (mutex);
+}
+
+static inline int
 __gthread_mutex_lock (__gthread_mutex_t *mutex)
 {
   if (__tpf_pthread_active ())
Index: gcc/gthr-solaris.h
===================================================================
--- gcc/gthr-solaris.h	(revision 132636)
+++ gcc/gthr-solaris.h	(working copy)
@@ -462,6 +462,12 @@ __gthread_setspecific (__gthread_key_t k
 }
 
 static inline int
+__gthread_mutex_destroy (__gthread_mutex_t * UNUSED(mutex))
+{
+  return 0;
+}
+
+static inline int
 __gthread_mutex_lock (__gthread_mutex_t *mutex)
 {
   if (__gthread_active_p ())
Index: gcc/gthr-posix.h
===================================================================
--- gcc/gthr-posix.h	(revision 132636)
+++ gcc/gthr-posix.h	(working copy)
@@ -94,6 +94,7 @@ __gthrw3(pthread_mutex_lock)
 __gthrw3(pthread_mutex_trylock)
 __gthrw3(pthread_mutex_unlock)
 __gthrw3(pthread_mutex_init)
+__gthrw3(pthread_mutex_destroy)
 __gthrw3(pthread_cond_broadcast)
 __gthrw3(pthread_cond_wait)
 #else
@@ -106,6 +107,7 @@ __gthrw(pthread_mutex_lock)
 __gthrw(pthread_mutex_trylock)
 __gthrw(pthread_mutex_unlock)
 __gthrw(pthread_mutex_init)
+__gthrw(pthread_mutex_destroy)
 __gthrw(pthread_cond_broadcast)
 __gthrw(pthread_cond_wait)
 #endif
@@ -677,6 +679,12 @@ __gthread_setspecific (__gthread_key_t k
 }
 
 static inline int
+__gthread_mutex_destroy (__gthread_mutex_t *mutex)
+{
+    return __gthrw_(pthread_mutex_destroy) (mutex);
+}
+
+static inline int
 __gthread_mutex_lock (__gthread_mutex_t *mutex)
 {
   if (__gthread_active_p ())
Index: gcc/gthr-posix95.h
===================================================================
--- gcc/gthr-posix95.h	(revision 132636)
+++ gcc/gthr-posix95.h	(working copy)
@@ -80,6 +80,7 @@ __gthrw(pthread_create)
 __gthrw(pthread_cancel)
 __gthrw(pthread_self)
 
+__gthrw(pthread_mutex_destroy)
 __gthrw(pthread_mutex_lock)
 __gthrw(pthread_mutex_trylock)
 __gthrw(pthread_mutex_unlock)
@@ -640,6 +641,12 @@ __gthread_setspecific (__gthread_key_t k
 }
 
 static inline int
+__gthread_mutex_destroy (__gthread_mutex_t *mutex)
+{
+  return __gthrw_(pthread_mutex_destroy) (mutex);
+}
+
+static inline int
 __gthread_mutex_lock (__gthread_mutex_t *mutex)
 {
   if (__gthread_active_p ())
Index: libgfortran/io/unit.c
===================================================================
--- libgfortran/io/unit.c	(revision 132632)
+++ libgfortran/io/unit.c	(working copy)
@@ -209,13 +209,7 @@ insert_unit (int n)
 static void
 destroy_unit_mutex (gfc_unit * u)
 {
-#ifdef __GTHREAD_MUTEX_DESTROY_FUNCTION
-  __GTHREAD_MUTEX_DESTROY_FUNCTION (&u->lock);
-#else
-#ifdef __CYGWIN__
-  pthread_mutex_destroy (&u->lock);
-#endif
-#endif
+  __gthread_mutex_destroy (&u->lock);
   free_mem (u);
 }
 

Attachment: signature.asc
Description: OpenPGP digital signature


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