Bug 53889 - Gthreads doesn't support destroying recursive mutexes
Summary: Gthreads doesn't support destroying recursive mutexes
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: other (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.8.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-07-07 18:48 UTC by Jonathan Wakely
Modified: 2012-10-05 07:35 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Add __gthread_recursive_mutex_destroy. (2.41 KB, patch)
2012-07-07 18:50 UTC, Jonathan Wakely
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2012-07-07 18:48:53 UTC
There is no __gthread_recursive_mutex_destroy function in the gthreads API.

Using __gthread_mutex_destroy fails to compile on platforms where the mutex types are different. This means to avoid resource leaks libstdc++ needs to hack around it with:

    // FIXME: gthreads doesn't define __gthread_recursive_mutex_destroy
    // so we need to obtain a __gthread_mutex_t to destroy
  private:
    template<typename _Mx, typename _Rm>
      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<typename _Rm>
      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<typename _Rm>
      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<typename _Rm>
      static typename
      __enable_if<std::__are_same<_Rm, __gthread_mutex_t>::__value,
        void>::__type
      _S_destroy(_Rm* __mx)
      { __gthread_mutex_destroy(__mx); }


Gthreads should define __gthread_recursive_mutex_destroy
Comment 1 Jonathan Wakely 2012-07-07 18:50:29 UTC
Created attachment 27760 [details]
Add __gthread_recursive_mutex_destroy.

Untested.
Comment 2 Jonathan Wakely 2012-10-02 20:22:40 UTC
Author: redi
Date: Tue Oct  2 20:22:32 2012
New Revision: 192002

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192002
Log:
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.

Modified:
    trunk/libgcc/ChangeLog
    trunk/libgcc/config/gthr-rtems.h
    trunk/libgcc/config/gthr-vxworks.h
    trunk/libgcc/config/i386/gthr-win32.c
    trunk/libgcc/config/i386/gthr-win32.h
    trunk/libgcc/config/mips/gthr-mipssde.h
    trunk/libgcc/config/pa/gthr-dce.h
    trunk/libgcc/config/s390/gthr-tpf.h
    trunk/libgcc/gthr-posix.h
    trunk/libgcc/gthr-single.h
    trunk/libgcc/gthr.h
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/ext/concurrence.h
    trunk/libstdc++-v3/include/std/mutex
Comment 3 Jonathan Wakely 2012-10-02 20:24:41 UTC
libgcc changes approved by Ian: http://gcc.gnu.org/ml/gcc-patches/2012-10/msg00123.html

This is fixed for 4.8
Comment 4 Jonathan Wakely 2012-10-05 07:35:17 UTC
Author: redi
Date: Fri Oct  5 07:35:12 2012
New Revision: 192114

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192114
Log:
	PR other/53889
	* config/i386/gthr-win32.h (__gthread_recursive_mutex_destroy):
	Fix parameter names.

Modified:
    trunk/libgcc/ChangeLog
    trunk/libgcc/config/i386/gthr-win32.h