diff options
author | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-11-18 18:56:29 +0000 |
---|---|---|
committer | redi <redi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-11-18 18:56:29 +0000 |
commit | 31a7dfb055a1838a3eb6a65a16742251daeb789f (patch) | |
tree | 105dd0ced7407acdcfd97c7b0f2b21cee51ddb0c /libstdc++-v3/include/std | |
parent | 12719f102c4f64ddf5e5861ac440bdb670a62e1e (diff) | |
download | gcc-31a7dfb055a1838a3eb6a65a16742251daeb789f.tar.gz |
2010-11-18 Jonathan Wakely <jwakely.gcc@gmail.com>
PR libstdc++/46455
* include/std/mutex: Define destructors for mutex types which use an
init function.
* include/ext/concurrence.h: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@166917 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/std')
-rw-r--r-- | libstdc++-v3/include/std/mutex | 76 |
1 files changed, 61 insertions, 15 deletions
diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex index 6d86cde8c5d..b9b924c4650 100644 --- a/libstdc++-v3/include/std/mutex +++ b/libstdc++-v3/include/std/mutex @@ -75,6 +75,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // XXX EAGAIN, ENOMEM, EPERM, EBUSY(may), EINVAL(may) __GTHREAD_MUTEX_INIT_FUNCTION(&_M_mutex); } + + ~mutex() { __gthread_mutex_destroy(&_M_mutex); } #endif mutex(const mutex&) = delete; @@ -109,6 +111,45 @@ _GLIBCXX_BEGIN_NAMESPACE(std) { return &_M_mutex; } }; +#ifndef __GTHREAD_RECURSIVE_MUTEX_INIT + // FIXME: gthreads doesn't define __gthread_recursive_mutex_destroy + // so we need to obtain a __gthread_mutex_t to destroy + class __destroy_recursive_mutex + { + 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); + } + + public: + // matches a gthr-win32.h recursive mutex + template<typename _Rm> + static typename enable_if<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<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<is_same<_Rm, __gthread_mutex_t>::value, void>::type + _S_destroy(_Rm* __mx) + { __gthread_mutex_destroy(__mx); } + }; +#endif + /// recursive_mutex class recursive_mutex { @@ -118,17 +159,19 @@ _GLIBCXX_BEGIN_NAMESPACE(std) public: typedef __native_type* native_handle_type; +#ifdef __GTHREAD_RECURSIVE_MUTEX_INIT + recursive_mutex() : _M_mutex(__GTHREAD_RECURSIVE_MUTEX_INIT) { } +#else recursive_mutex() { // XXX EAGAIN, ENOMEM, EPERM, EBUSY(may), EINVAL(may) -#ifdef __GTHREAD_RECURSIVE_MUTEX_INIT - __native_type __tmp = __GTHREAD_RECURSIVE_MUTEX_INIT; - _M_mutex = __tmp; -#else __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION(&_M_mutex); -#endif } + ~recursive_mutex() + { __destroy_recursive_mutex::_S_destroy(&_M_mutex); } +#endif + recursive_mutex(const recursive_mutex&) = delete; recursive_mutex& operator=(const recursive_mutex&) = delete; @@ -177,16 +220,17 @@ _GLIBCXX_BEGIN_NAMESPACE(std) public: typedef __native_type* native_handle_type; - timed_mutex() - { #ifdef __GTHREAD_MUTEX_INIT - __native_type __tmp = __GTHREAD_MUTEX_INIT; - _M_mutex = __tmp; + timed_mutex() : _M_mutex(__GTHREAD_MUTEX_INIT) { } #else + timed_mutex() + { __GTHREAD_MUTEX_INIT_FUNCTION(&_M_mutex); -#endif } + ~timed_mutex() { __gthread_mutex_destroy(&_M_mutex); } +#endif + timed_mutex(const timed_mutex&) = delete; timed_mutex& operator=(const timed_mutex&) = delete; @@ -281,17 +325,19 @@ _GLIBCXX_BEGIN_NAMESPACE(std) public: typedef __native_type* native_handle_type; +#ifdef __GTHREAD_RECURSIVE_MUTEX_INIT + recursive_timed_mutex() : _M_mutex(__GTHREAD_RECURSIVE_MUTEX_INIT) { } +#else recursive_timed_mutex() { // XXX EAGAIN, ENOMEM, EPERM, EBUSY(may), EINVAL(may) -#ifdef __GTHREAD_RECURSIVE_MUTEX_INIT - __native_type __tmp = __GTHREAD_RECURSIVE_MUTEX_INIT; - _M_mutex = __tmp; -#else __GTHREAD_RECURSIVE_MUTEX_INIT_FUNCTION(&_M_mutex); -#endif } + ~recursive_timed_mutex() + { __destroy_recursive_mutex::_S_destroy(&_M_mutex); } +#endif + recursive_timed_mutex(const recursive_timed_mutex&) = delete; recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete; |