PATCH: Use __gthread_mutex_t in profile/impl/profiler_trace.h

Rainer Orth ro@CeBiTec.Uni-Bielefeld.DE
Wed Feb 24 14:38:00 GMT 2010


The last remaining libstdc++ testsuite failure on Solaris 11/x86 is

FAIL: ext/profile/all.cc (test for excess errors)

The error is:

Excess errors:
In file included from /vol/gcc/obj/gcc-4.5.0-20100208/11-gcc/i386-pc-solaris2.11/libstdc++-v3/include/profile/impl/profiler_hash_func.h:51:0,
                 from /vol/gcc/obj/gcc-4.5.0-20100208/11-gcc/i386-pc-solaris2.11/libstdc++-v3/include/profile/impl/profiler.h:400,
                 from /vol/gcc/obj/gcc-4.5.0-20100208/11-gcc/i386-pc-solaris2.11/libstdc++-v3/include/profile/base.h:44,
                 from /vol/gcc/obj/gcc-4.5.0-20100208/11-gcc/i386-pc-solaris2.11/libstdc++-v3/include/profile/map.h:38,
                 from /vol/gcc/obj/gcc-4.5.0-20100208/11-gcc/i386-pc-solaris2.11/libstdc++-v3/include/profile/map:38,
                 from /vol/gcc/obj/gcc-4.5.0-20100208/11-gcc/i386-pc-solaris2.11/libstdc++-v3/include/map:69,
                 from /vol/gcc/src/hg/trunk/solaris/libstdc++-v3/testsuite/ext/profile/all.cc:24:
/vol/gcc/obj/gcc-4.5.0-20100208/11-gcc/i386-pc-solaris2.11/libstdc++-v3/include/profile/impl/profiler_trace.h:81:1: error: no matching function for call to '_pthread_mutex::_pthread_mutex(<brace-enclosed initializer list>)'
/usr/include/sys/types.h:404:31: note: candidates are: _pthread_mutex::_pthread_mutex()
/usr/include/sys/types.h:404:31: note:                 _pthread_mutex::_pthread_mutex(const _pthread_mutex&)

and much more.  Knowing close to no C++, this is mostly gibberish to me,
but from inspection, it seems that part of the problem is that this
header doesn't use gthreads, but instead tries to provide something
similar itself, which seems wasteful.  The following patch tries to
implement this idea, but didn't get the testcase to compile either ;-(
Someone who knows C++ and this code can probably easily turn this into
something that works.

The error now is

/vol/gcc/obj/gcc-4.5.0-20100208/11-gcc/i386-pc-solaris2.11/libstdc++-v3/include/profile/impl/profiler_trace.h: In constructor '__gnu_profile::__trace_base<__object_info, __stack_info>::__trace_base() [with __object_info = __gnu_profile::__hashfunc_info, __stack_info = __gnu_profile::__hashfunc_stack_info]':
/vol/gcc/obj/gcc-4.5.0-20100208/11-gcc/i386-pc-solaris2.11/libstdc++-v3/include/profile/impl/profiler_hash_func.h:125:60:   instantiated from here
/vol/gcc/obj/gcc-4.5.0-20100208/11-gcc/i386-pc-solaris2.11/libstdc++-v3/include/profile/impl/profiler_trace.h:307:3: error: no match for 'operator=' in '((__gnu_profile::__trace_base<__gnu_profile::__hashfunc_info, __gnu_profile::__hashfunc_stack_info>*)this)->__gnu_profile::__trace_base<__gnu_profile::__hashfunc_info, __gnu_profile::__hashfunc_stack_info>::__stack_table_lock = {{0, 0, 0, 0, 19800}, {{{0}}}, 0}'
/usr/include/sys/types.h:404:31: note: candidate is: _pthread_mutex& _pthread_mutex::operator=(const _pthread_mutex&)

Suggestions?

	Rainer

-- 
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University


2010-02-19  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* include/profile/impl/profiler_trace.h: Include <bits/gthr.h>
	instead <pthread.h>
	(__gnu_profile::__get___global_lock):  Expand from
	_GLIBCXX_PROFILE_DEFINE_DATA.
	Change to __gthread_mutex_t.
	(__gnu_profile::__trace_base::__object_table_lock): Likewise.
	(__gnu_profile::__trace_base::__stack_table_lock): Likewise.
	(__gnu_profile::__trace_base::__lock_object_table): Use
	__gthread_mutex_lock.
	(__gnu_profile::__trace_base::__lock_stack_table): Likewise.
	(__gnu_profile::__trace_base::__unlock_object_table): Use
	__gthread_mutex_unlock.
	(__gnu_profile::__trace_base::__unlock_stack_table): Likewise.
	(__gnu_profile::__trace_base::__trace_base): Initialize
	__object_table_lock, __stack_table_lock.
	(__gnu_profile::__report): Use __gthread_mutex_lock,
	__gthread_mutex_unlock.
	(__gnu_profile::profcxx_init_unconditional): Likewise.

diff -r 72b534606d20 -r 725b27510017 libstdc++-v3/include/profile/impl/profiler_trace.h
--- a/libstdc++-v3/include/profile/impl/profiler_trace.h	Fri Feb 19 08:46:46 2010 +0100
+++ b/libstdc++-v3/include/profile/impl/profiler_trace.h	Fri Feb 19 10:00:04 2010 +0100
@@ -65,7 +65,7 @@
 #endif
 
 #if defined _GLIBCXX_PROFILE_THREADS && defined _GLIBCXX_HAVE_TLS
-#include <pthread.h>
+#include <bits/gthr.h>
 #endif
 
 #include "profile/impl/profiler_state.h"
@@ -73,24 +73,24 @@
 
 namespace __gnu_profile
 {
+// Cannot use _GLIBCXX_PROFILE_DEFINE_DATA directly due to special
+// initialization requirements of __gthread_mutex_t.
+inline __gthread_mutex_t& __get___global_lock() {
+  static __gthread_mutex_t __global_lock;
 
-#if defined _GLIBCXX_PROFILE_THREADS && defined _GLIBCXX_HAVE_TLS
-#define _GLIBCXX_IMPL_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
-typedef pthread_mutex_t __mutex_t;
-/** @brief Pthread mutex wrapper.  */
-_GLIBCXX_PROFILE_DEFINE_DATA(__mutex_t, __global_lock, 
-                             PTHREAD_MUTEX_INITIALIZER);
-inline void __lock(__mutex_t& __m) { pthread_mutex_lock(&__m); }
-inline void __unlock(__mutex_t& __m) { pthread_mutex_unlock(&__m); }
+// FIXME: Probably doesn't work: __global_lock must not be reinitialized
+// at every access.
+#ifdef __GTHREAD_MUTEX_INIT
+  __global_lock = __GTHREAD_MUTEX_INIT;
 #else
-typedef int __mutex_t;
-/** @brief Mock mutex interface.  */
-#define _GLIBCXX_IMPL_MUTEX_INITIALIZER 0
-_GLIBCXX_PROFILE_DEFINE_DATA(__mutex_t, __global_lock, 0);
-inline void __lock(__mutex_t& __m) {}
-inline void __unlock(__mutex_t& __m) {}
+  __GTHREAD_MUTEX_INIT_FUNCTION (&__global_lock);
+#error__GTHREAD_MUTEX_INIT or __GTHREAD_MUTEX_INIT_FUNCTION should be defined by gthr.h abstraction layer, report problem to libstdc++@gcc.gnu.org.
 #endif
 
+  return __global_lock;
+}
+
+
 /** @brief Representation of a warning.  */
 struct __warning_data
 {
@@ -243,8 +243,8 @@
   void __unlock_stack_table();
 
  private:
-  __mutex_t __object_table_lock;
-  __mutex_t __stack_table_lock;
+  __gthread_mutex_t __object_table_lock;
+  __gthread_mutex_t __stack_table_lock;
   typedef _GLIBCXX_IMPL_UNORDERED_MAP<__object_t, 
                                       __object_info> __object_table_t;
   typedef _GLIBCXX_IMPL_UNORDERED_MAP<__stack_t, __stack_info, __stack_hash, 
@@ -274,25 +274,25 @@
 template <typename __object_info, typename __stack_info>
 void __trace_base<__object_info, __stack_info>::__lock_object_table()
 {
-  __lock(this->__object_table_lock);
+  __gthread_mutex_lock(&this->__object_table_lock);
 }
 
 template <typename __object_info, typename __stack_info>
 void __trace_base<__object_info, __stack_info>::__lock_stack_table()
 {
-  __lock(this->__stack_table_lock);
+  __gthread_mutex_lock(&this->__stack_table_lock);
 }
 
 template <typename __object_info, typename __stack_info>
 void __trace_base<__object_info, __stack_info>::__unlock_object_table()
 {
-  __unlock(this->__object_table_lock);
+  __gthread_mutex_unlock(&this->__object_table_lock);
 }
 
 template <typename __object_info, typename __stack_info>
 void __trace_base<__object_info, __stack_info>::__unlock_stack_table()
 {
-  __unlock(this->__stack_table_lock);
+  __gthread_mutex_unlock(&this->__stack_table_lock);
 }
 
 template <typename __object_info, typename __stack_info>
@@ -304,7 +304,14 @@
   __stack_table.rehash(10000);
   __stack_table_byte_size = 0;
   __id = NULL;
-  __object_table_lock = __stack_table_lock = _GLIBCXX_IMPL_MUTEX_INITIALIZER;
+#ifdef __GTHREAD_MUTEX_INIT
+  __object_table_lock = __GTHREAD_MUTEX_INIT;
+  __stack_table_lock = __GTHREAD_MUTEX_INIT;
+#else
+  __GTHREAD_MUTEX_INIT_FUNCTION (&__object_table_lock);
+  __GTHREAD_MUTEX_INIT_FUNCTION (&__stack_table_lock);
+#error__GTHREAD_MUTEX_INIT or __GTHREAD_MUTEX_INIT_FUNCTION should be defined by gthr.h abstraction layer, report problem to libstdc++@gcc.gnu.org.
+#endif
 }
 
 template <typename __object_info, typename __stack_info>
@@ -477,7 +484,7 @@
  */
 inline void __report(void)
 {
-  __lock(_GLIBCXX_PROFILE_DATA(__global_lock));
+  __gthread_mutex_lock(_GLIBCXX_PROFILE_DATA(__global_lock));
 
   __warning_vector_t __warnings;
 
@@ -504,7 +511,7 @@
   std::for_each(__warnings.begin(), __warnings.end(), __warn(__warn_file));
   fclose(__warn_file);
 
-  __unlock(_GLIBCXX_PROFILE_DATA(__global_lock));
+  __gthread_mutex_unlock(_GLIBCXX_PROFILE_DATA(__global_lock));
 }
 
 inline void __set_trace_path()
@@ -628,7 +635,7 @@
 
 inline void __profcxx_init_unconditional()
 {
-  __lock(_GLIBCXX_PROFILE_DATA(__global_lock));
+  __gthread_mutex_lock(_GLIBCXX_PROFILE_DATA(__global_lock));
 
   if (__is_invalid()) {
 
@@ -662,7 +669,7 @@
     }
   }
 
-  __unlock(_GLIBCXX_PROFILE_DATA(__global_lock));
+  __gthread_mutex_unlock(_GLIBCXX_PROFILE_DATA(__global_lock));
 }
 
 /** @brief This function must be called by each instrumentation point.



More information about the Libstdc++ mailing list