From patchwork Sun Sep 30 18:41:06 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 188187 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 744172C00C8 for ; Mon, 1 Oct 2012 04:41:19 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1349635280; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:Date:Message-ID:Subject:From:To: Cc:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=VP8iZWB TV7cGN3y/yJHdjlcyGa4=; b=lIOPs5a3pgmRQI+qy9Cgiwv5DyzAyS4CaJe0ey8 pRXGFwhcUIL9jpbjqWwRxpDDGiTVvRAS2YK36ww5bdxo5R6sa50VRkIzQQX9e5/D blZLvzU2xZGzSgTmKXdY/25kf/jjuD9sjhu7/f9RX+bpMruPcIu3lw1b05wCnhS7 609I= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Cc:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=m8lBmsKuuf8CH9StEs+gng31CY6rojk/O/PNNf/BX30Z11AspFaUZ2JsDrnbZC 2jhYKNkZuQS3TgmjFHD56UtAASxzQxuzIJtRQ07toi/gdOg+9OlkBjkpDCpW7FEu /upqzPqPAWZTSH4i5t1e6zDdCteG8K1CFfCCR6KICPo7U=; Received: (qmail 24516 invoked by alias); 30 Sep 2012 18:41:15 -0000 Received: (qmail 24501 invoked by uid 22791); 30 Sep 2012 18:41:12 -0000 X-SWARE-Spam-Status: No, hits=-4.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, TW_BJ X-Spam-Check-By: sourceware.org Received: from mail-ia0-f175.google.com (HELO mail-ia0-f175.google.com) (209.85.210.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 30 Sep 2012 18:41:07 +0000 Received: by iacb35 with SMTP id b35so306911iac.20 for ; Sun, 30 Sep 2012 11:41:07 -0700 (PDT) MIME-Version: 1.0 Received: by 10.50.219.129 with SMTP id po1mr3749461igc.35.1349030466736; Sun, 30 Sep 2012 11:41:06 -0700 (PDT) Received: by 10.42.197.202 with HTTP; Sun, 30 Sep 2012 11:41:06 -0700 (PDT) Date: Sun, 30 Sep 2012 19:41:06 +0100 Message-ID: Subject: PR 53889: Add __gthread_recursive_mutex_destroy From: Jonathan Wakely To: gcc-patches , "libstdc++" Cc: Jakub Jelinek Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org There is no __gthread_recursive_mutex_destroy function in the gthreads API. Trying to use __gthread_mutex_destroy fails to compile on platforms where the mutex types are different. To avoid resource leaks libstdc++ needs to hack around the missing function with overloaded functions and SFINAE tricks to detect how a recursive mutex can be destroyed. This patch extends the gthreads API to include __gthread_recursive_mutex_destroy, defining it for each gthread model, and removing the hacks from libstdc++. libgcc: PR other/53889 * gthr.h (__gthread_recursive_mutex_destroy): Document new required function. * gthr-posix.h (__gthread_recursive_mutex_destroy): Define. * gthr-single.h (__gthread_recursive_mutex_destroy): Likewise. * config/gthr-rtems.h (__gthread_recursive_mutex_destroy): Likewise. * config/gthr-vxworks.h (__gthread_recursive_mutex_destroy): Likewise. * config/i386/gthr-win32.h (__gthread_recursive_mutex_destroy): Likewise. * config/mips/gthr-mipssde.h (__gthread_recursive_mutex_destroy): Likewise. * config/pa/gthr-dce.h (__gthread_recursive_mutex_destroy): Likewise. * config/s390/gthr-tpf.h (__gthread_recursive_mutex_destroy): Likewise. libstdc++-v3: PR other/53889 * include/std/mutex (__recursive_mutex_base::~__recursive_mutex_base): Use __gthread_recursive_mutex_destroy. (__recursive_mutex_base::_S_destroy): Remove. (__recursive_mutex_base::_S_destroy_win32): Likewise. * include/ext/concurrence.h (__recursive_mutex::~__recursive_mutex): Use __gthread_recursive_mutex_destroy. (__recursive_mutex::_S_destroy): Remove. (__recursive_mutex::_S_destroy_win32): Likewise. Tested x86_64-linux. Are the libgcc parts OK for trunk? commit 37d75fef68222e92c4b58870dcfeeb3679e3c718 Author: Jonathan Wakely Date: Sun Sep 30 19:00:51 2012 +0100 libgcc: PR other/53889 * gthr.h (__gthread_recursive_mutex_destroy): Document new required function. * gthr-posix.h (__gthread_recursive_mutex_destroy): Define. * gthr-single.h (__gthread_recursive_mutex_destroy): Likewise. * config/gthr-rtems.h (__gthread_recursive_mutex_destroy): Likewise. * config/gthr-vxworks.h (__gthread_recursive_mutex_destroy): Likewise. * config/i386/gthr-win32.h (__gthread_recursive_mutex_destroy): Likewise. * config/mips/gthr-mipssde.h (__gthread_recursive_mutex_destroy): Likewise. * config/pa/gthr-dce.h (__gthread_recursive_mutex_destroy): Likewise. * config/s390/gthr-tpf.h (__gthread_recursive_mutex_destroy): Likewise. libstdc++-v3: PR other/53889 * include/std/mutex (__recursive_mutex_base::~__recursive_mutex_base): Use __gthread_recursive_mutex_destroy. (__recursive_mutex_base::_S_destroy): Remove. (__recursive_mutex_base::_S_destroy_win32): Likewise. * include/ext/concurrence.h (__recursive_mutex::~__recursive_mutex): Use __gthread_recursive_mutex_destroy. (__recursive_mutex::_S_destroy): Remove. (__recursive_mutex::_S_destroy_win32): Likewise. diff --git a/libgcc/config/gthr-rtems.h b/libgcc/config/gthr-rtems.h index c5bd522..50bdd9f 100644 --- a/libgcc/config/gthr-rtems.h +++ b/libgcc/config/gthr-rtems.h @@ -1,8 +1,7 @@ /* RTEMS threads compatibility routines for libgcc2 and libobjc. by: Rosimildo da Silva( rdasilva@connecttel.com ) */ /* Compile this one with gcc. */ -/* Copyright (C) 1997, 1999, 2000, 2002, 2003, 2005, 2008, 2009 - Free Software Foundation, Inc. +/* Copyright (C) 1997-2012 Free Software Foundation, Inc. This file is part of GCC. @@ -150,6 +149,12 @@ __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) return rtems_gxx_recursive_mutex_unlock( __mutex ); } +static inline int +__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex) +{ + return rtems_gxx_mutex_destroy( __mutex ); +} + #ifdef __cplusplus } #endif diff --git a/libgcc/config/gthr-vxworks.h b/libgcc/config/gthr-vxworks.h index 63116c4..b48c5ac 100644 --- a/libgcc/config/gthr-vxworks.h +++ b/libgcc/config/gthr-vxworks.h @@ -1,7 +1,6 @@ /* Threads compatibility routines for libgcc2 and libobjc for VxWorks. */ /* Compile this one with gcc. */ -/* Copyright (C) 1997, 1999, 2000, 2008, 2009, 2011 - Free Software Foundation, Inc. +/* Copyright (C) 1997-2012 Free Software Foundation, Inc. Contributed by Mike Stump . This file is part of GCC. @@ -111,6 +110,12 @@ __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *mutex) return __gthread_mutex_unlock (mutex); } +static inline int +__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex) +{ + return __gthread_mutex_destroy (__mutex); +} + /* pthread_once is complicated enough that it's implemented out-of-line. See config/vxlib.c. */ diff --git a/libgcc/config/i386/gthr-win32.h b/libgcc/config/i386/gthr-win32.h index 53f8396..cc2cc9b 100644 --- a/libgcc/config/i386/gthr-win32.h +++ b/libgcc/config/i386/gthr-win32.h @@ -1,8 +1,7 @@ /* Threads compatibility routines for libgcc2 and libobjc. */ /* Compile this one with gcc. */ -/* Copyright (C) 1999, 2000, 2002, 2003, 2004, 2005, 2008, 2009 - Free Software Foundation, Inc. +/* Copyright (C) 1999-2012 Free Software Foundation, Inc. Contributed by Mumit Khan . This file is part of GCC. @@ -536,6 +535,14 @@ __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) return 0; } +static inline void +__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *mutex) +{ + __gthread_mutex_t __mutex2; + __mutex2.sema = mutex->sema; + __gthr_win32_mutex_destroy (&__mutex2); +} + #else /* ! __GTHREAD_HIDE_WIN32API */ #include @@ -761,6 +768,12 @@ __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) return 0; } +static inline void +__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *mutex) +{ + CloseHandle ((HANDLE) mutex->sema); +} + #endif /* __GTHREAD_HIDE_WIN32API */ #ifdef __cplusplus diff --git a/libgcc/config/mips/gthr-mipssde.h b/libgcc/config/mips/gthr-mipssde.h index 34f9b6c..7c9f537 100644 --- a/libgcc/config/mips/gthr-mipssde.h +++ b/libgcc/config/mips/gthr-mipssde.h @@ -1,6 +1,6 @@ /* MIPS SDE threads compatibility routines for libgcc2 and libobjc. */ /* Compile this one with gcc. */ -/* Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc. +/* Copyright (C) 2006-2012 Free Software Foundation, Inc. Contributed by Nigel Stephens This file is part of GCC. @@ -223,6 +223,12 @@ __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) return 0; } +static inline int +__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex) +{ + return __gthread_mutex_destroy(__mutex); +} + #ifdef __cplusplus } #endif diff --git a/libgcc/config/pa/gthr-dce.h b/libgcc/config/pa/gthr-dce.h index d32155a..3ba43a1 100644 --- a/libgcc/config/pa/gthr-dce.h +++ b/libgcc/config/pa/gthr-dce.h @@ -1,7 +1,6 @@ /* Threads compatibility routines for libgcc2 and libobjc. */ /* Compile this one with gcc. */ -/* Copyright (C) 1997, 1999, 2000, 2001, 2004, 2005, 2008, 2009 - Free Software Foundation, Inc. +/* Copyright (C) 1997-2012 Free Software Foundation, Inc. This file is part of GCC. @@ -557,6 +556,12 @@ __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) return __gthread_mutex_unlock (__mutex); } +static inline int +__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex) +{ + return __gthread_mutex_destroy (__mutex); +} + #endif /* _LIBOBJC */ #endif diff --git a/libgcc/config/s390/gthr-tpf.h b/libgcc/config/s390/gthr-tpf.h index fb23e91..49bce4c 100644 --- a/libgcc/config/s390/gthr-tpf.h +++ b/libgcc/config/s390/gthr-tpf.h @@ -1,6 +1,6 @@ /* Threads compatibility routines for libgcc2 and libobjc. Compile this one with gcc. - Copyright (C) 2004, 2005, 2008, 2009 Free Software Foundation, Inc. + Copyright (C) 2004-2012 Free Software Foundation, Inc. This file is part of GCC. @@ -225,5 +225,10 @@ __gthread_recursive_mutex_init_function (__gthread_recursive_mutex_t *__mutex) return 0; } +static inline int +__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex) +{ + return __gthread_mutex_destroy (__mutex); +} #endif /* ! GCC_GTHR_TPF_H */ diff --git a/libgcc/gthr-posix.h b/libgcc/gthr-posix.h index cc4e518..1e7ddfe 100644 --- a/libgcc/gthr-posix.h +++ b/libgcc/gthr-posix.h @@ -832,6 +832,12 @@ __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) return __gthread_mutex_unlock (__mutex); } +static inline int +__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex) +{ + return __gthread_mutex_destroy (__mutex); +} + #ifdef _GTHREAD_USE_COND_INIT_FUNC static inline void __gthread_cond_init_function (__gthread_cond_t *__cond) diff --git a/libgcc/gthr-single.h b/libgcc/gthr-single.h index 4e39679..717e6cb 100644 --- a/libgcc/gthr-single.h +++ b/libgcc/gthr-single.h @@ -1,7 +1,6 @@ /* Threads compatibility routines for libgcc2 and libobjc. */ /* Compile this one with gcc. */ -/* Copyright (C) 1997, 1999, 2000, 2004, 2008, 2009 - Free Software Foundation, Inc. +/* Copyright (C) 1997-2012 Free Software Foundation, Inc. This file is part of GCC. @@ -286,6 +285,12 @@ __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex) return __gthread_mutex_unlock (__mutex); } +static inline int +__gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *__mutex) +{ + return __gthread_mutex_destroy (__mutex); +} + #endif /* _LIBOBJC */ #undef UNUSED diff --git a/libgcc/gthr.h b/libgcc/gthr.h index 813abe1..9f2b53d 100644 --- a/libgcc/gthr.h +++ b/libgcc/gthr.h @@ -1,7 +1,6 @@ /* Threads compatibility routines for libgcc2. */ /* Compile this one with gcc. */ -/* Copyright (C) 1997, 1998, 2004, 2008, 2009, 2011 - Free Software Foundation, Inc. +/* Copyright (C) 1997-2012 Free Software Foundation, Inc. This file is part of GCC. @@ -73,6 +72,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see int __gthread_setspecific (__gthread_key_t key, const void *ptr) int __gthread_mutex_destroy (__gthread_mutex_t *mutex); + int __gthread_recursive_mutex_destroy (__gthread_recursive_mutex_t *mutex); int __gthread_mutex_lock (__gthread_mutex_t *mutex); int __gthread_mutex_trylock (__gthread_mutex_t *mutex); diff --git a/libstdc++-v3/include/ext/concurrence.h b/libstdc++-v3/include/ext/concurrence.h index ad02839..68c679c 100644 --- a/libstdc++-v3/include/ext/concurrence.h +++ b/libstdc++-v3/include/ext/concurrence.h @@ -219,7 +219,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ~__recursive_mutex() { if (__gthread_active_p()) - _S_destroy(&_M_mutex); + __gthread_recursive_mutex_destroy(&_M_mutex); } #endif @@ -247,43 +247,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __gthread_recursive_mutex_t* gthread_recursive_mutex(void) { return &_M_mutex; } - -#if __GTHREADS && ! defined __GTHREAD_RECURSIVE_MUTEX_INIT - // FIXME: gthreads doesn't define __gthread_recursive_mutex_destroy - // so we need to obtain a __gthread_mutex_t to destroy - private: - template - static void - _S_destroy_win32(_Mx* __mx, _Rm const* __rmx) - { - __mx->counter = __rmx->counter; - __mx->sema = __rmx->sema; - __gthread_mutex_destroy(__mx); - } - - // matches a gthr-win32.h recursive mutex - template - static typename __enable_if<(bool)sizeof(&_Rm::sema), void>::__type - _S_destroy(_Rm* __mx) - { - __gthread_mutex_t __tmp; - _S_destroy_win32(&__tmp, __mx); - } - - // matches a recursive mutex with a member 'actual' - template - static typename __enable_if<(bool)sizeof(&_Rm::actual), void>::__type - _S_destroy(_Rm* __mx) - { __gthread_mutex_destroy(&__mx->actual); } - - // matches when there's only one mutex type - template - static typename - __enable_if::__value, - void>::__type - _S_destroy(_Rm* __mx) - { __gthread_mutex_destroy(__mx); } -#endif }; /// Scoped lock idiom. diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex index 34d64c5..b28a53e 100644 --- a/libstdc++-v3/include/std/mutex +++ b/libstdc++-v3/include/std/mutex @@ -101,42 +101,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } ~__recursive_mutex_base() - { _S_destroy(&_M_mutex); } - - private: - // FIXME: gthreads doesn't define __gthread_recursive_mutex_destroy - // so we need to obtain a __gthread_mutex_t to destroy - - // matches when there's only one mutex type - template - static - typename enable_if::value, void>::type - _S_destroy(_Rm* __mx) - { __gthread_mutex_destroy(__mx); } - - // matches a recursive mutex with a member 'actual' - template - static typename enable_if<(bool)sizeof(&_Rm::actual), void>::type - _S_destroy(_Rm* __mx) - { __gthread_mutex_destroy(&__mx->actual); } - - // matches a gthr-win32.h recursive mutex - template - static typename enable_if<(bool)sizeof(&_Rm::sema), void>::type - _S_destroy(_Rm* __mx) - { - __gthread_mutex_t __tmp; - _S_destroy_win32(&__tmp, __mx); - } - - template - static void - _S_destroy_win32(_Mx* __mx, _Rm const* __rmx) - { - __mx->counter = __rmx->counter; - __mx->sema = __rmx->sema; - __gthread_mutex_destroy(__mx); - } + { __gthread_recursive_mutex_destroy(&_M_mutex); } #endif };