As documented in the libstdc++ manual, the shared pointer operations in
libstdc++ headers can be instrumented by defining the macros
_GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE()/AFTER() and libstdc++ has to be
rebuilt in order to instrument the remaining shared pointer operations.
However, rebuilding libstdc++ is inconvenient. So let's move the thread
wrapper code from thread.cc into .
See also:
* http://gcc.gnu.org/onlinedocs/libstdc++/manual/debug.html.
* http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51504.
Signed-off-by: Bart Van Assche
Index: libstdc++-v3/src/thread.cc
===
--- libstdc++-v3/src/thread.cc (revision 182271)
+++ libstdc++-v3/src/thread.cc (working copy)
@@ -59,28 +59,6 @@ static inline int get_nprocs()
namespace std _GLIBCXX_VISIBILITY(default)
{
- namespace
- {
-extern "C" void*
-execute_native_thread_routine(void* __p)
-{
- thread::_Impl_base* __t = static_cast(__p);
- thread::__shared_base_type __local;
- __local.swap(__t->_M_this_ptr);
-
- __try
- {
- __t->_M_run();
- }
- __catch(...)
- {
- std::terminate();
- }
-
- return 0;
-}
- }
-
_GLIBCXX_BEGIN_NAMESPACE_VERSION
void
@@ -114,12 +92,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
void
thread::_M_start_thread(__shared_base_type __b)
{
+ _M_start_thread(__b, &_M_entry);
+ }
+
+ void
+ thread::_M_start_thread(__shared_base_type __b, void* (*__pf)(void*))
+ {
if (!__gthread_active_p())
__throw_system_error(int(errc::operation_not_permitted));
__b->_M_this_ptr = __b;
-int __e = __gthread_create(&_M_id._M_thread,
- &execute_native_thread_routine, __b.get());
+int __e = __gthread_create(&_M_id._M_thread, __pf, __b.get());
if (__e)
{
__b->_M_this_ptr.reset();
Index: libstdc++-v3/include/std/thread
===
--- libstdc++-v3/include/std/thread (revision 182271)
+++ libstdc++-v3/include/std/thread (working copy)
@@ -132,7 +132,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
_M_start_thread(_M_make_routine(std::__bind_simple(
std::forward<_Callable>(__f),
-std::forward<_Args>(__args)...)));
+std::forward<_Args>(__args)...)),
+&thread::_M_entry);
}
~thread()
@@ -180,9 +181,30 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
hardware_concurrency() noexcept;
private:
+static void* _M_entry(void* __p)
+{
+ thread::_Impl_base* __t = static_cast(__p);
+ thread::__shared_base_type __local;
+ __local.swap(__t->_M_this_ptr);
+
+ __try
+{
+ __t->_M_run();
+}
+ __catch(...)
+{
+ std::terminate();
+}
+
+ return 0;
+}
+
void
_M_start_thread(__shared_base_type);
+void
+_M_start_thread(__shared_base_type, void* (*)(void*));
+
template
shared_ptr<_Impl<_Callable>>
_M_make_routine(_Callable&& __f)
Index: libstdc++-v3/config/abi/post/s390-linux-gnu/baseline_symbols.txt
===
--- libstdc++-v3/config/abi/post/s390-linux-gnu/baseline_symbols.txt
(revision 182271)
+++ libstdc++-v3/config/abi/post/s390-linux-gnu/baseline_symbols.txt
(working copy)
@@ -2145,6 +2145,7 @@ FUNC:_ZNSt6localeD1Ev@@GLIBCXX_3.4
FUNC:_ZNSt6localeD2Ev@@GLIBCXX_3.4
FUNC:_ZNSt6localeaSERKS_@@GLIBCXX_3.4
FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE@@GLIBCXX_3.4.11
+FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFPvS3_E@@GLIBCXX_3.4.17
FUNC:_ZNSt6thread4joinEv@@GLIBCXX_3.4.11
FUNC:_ZNSt6thread6detachEv@@GLIBCXX_3.4.11
FUNC:_ZNSt7codecvtIcc11__mbstate_tEC1EP15__locale_structm@@GLIBCXX_3.4
Index: libstdc++-v3/config/abi/post/x86_64-linux-gnu/baseline_symbols.txt
===
--- libstdc++-v3/config/abi/post/x86_64-linux-gnu/baseline_symbols.txt
(revision 182271)
+++ libstdc++-v3/config/abi/post/x86_64-linux-gnu/baseline_symbols.txt
(working copy)
@@ -1955,6 +1955,7 @@ FUNC:_ZNSt6localeD1Ev@@GLIBCXX_3.4
FUNC:_ZNSt6localeD2Ev@@GLIBCXX_3.4
FUNC:_ZNSt6localeaSERKS_@@GLIBCXX_3.4
FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEE@@GLIBCXX_3.4.11
+FUNC:_ZNSt6thread15_M_start_threadESt10shared_ptrINS_10_Impl_baseEEPFPvS3_E@@GLIBCXX_3.4.17
FUNC:_ZNSt6thread4joinEv@@GLIBCXX_3.4.11
FUNC:_ZNSt6thread6detachEv@@GLIBCXX_3.4.11
FUNC:_ZNSt7codecvtIcc11__mbstate_tEC1EP15__locale_structm@@GLIBCXX_3.4
Index: libstdc++-v3/config/abi/post/ia64-linux-gnu/baseline_symbols.txt
===
--- libstdc++-v3/config/abi/post/ia64-linux-gnu