aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbsupport/thread-pool.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2019-10-12 13:06:18 -0600
committerTom Tromey <tom@tromey.com>2019-11-26 14:02:58 -0700
commit4da8c3a8a5d1962d24fb374122c473f930eba386 (patch)
tree80ec079a39c964f8e4c2dd30893f0e413336032b /gdb/gdbsupport/thread-pool.c
parent971db5e21e35e1ad0d124b954ce13d463b887b6c (diff)
downloadgdb-4da8c3a8a5d1962d24fb374122c473f930eba386.zip
gdb-4da8c3a8a5d1962d24fb374122c473f930eba386.tar.gz
gdb-4da8c3a8a5d1962d24fb374122c473f930eba386.tar.bz2
Set names of worker threads
This adds some configury so that gdb can set the names of worker threads. This makes them show up more nicely when debugging gdb itself. 2019-11-26 Tom Tromey <tom@tromey.com> * gdbsupport/thread-pool.c (thread_pool::set_thread_count): Set name of worker thread. * gdbsupport/common.m4 (GDB_AC_COMMON): Check for pthread_setname_np. * configure, config.in: Rebuild. gdb/gdbserver/ChangeLog 2019-11-26 Tom Tromey <tom@tromey.com> * configure, config.in: Rebuild. Change-Id: I60473d65ae9ae14d8c56ddde39684240c16aaf35
Diffstat (limited to 'gdb/gdbsupport/thread-pool.c')
-rw-r--r--gdb/gdbsupport/thread-pool.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/gdb/gdbsupport/thread-pool.c b/gdb/gdbsupport/thread-pool.c
index 8282ea3..d19ae02 100644
--- a/gdb/gdbsupport/thread-pool.c
+++ b/gdb/gdbsupport/thread-pool.c
@@ -26,6 +26,19 @@
#include "gdbsupport/block-signals.h"
#include <algorithm>
+/* On the off chance that we have the pthread library on a Windows
+ host, but std::thread is not using it, avoid calling
+ pthread_setname_np on Windows. */
+#ifndef _WIN32
+#ifdef HAVE_PTHREAD_SETNAME_NP
+#define USE_PTHREAD_SETNAME_NP
+#endif
+#endif
+
+#ifdef USE_PTHREAD_SETNAME_NP
+#include <pthread.h>
+#endif
+
namespace gdb
{
@@ -62,6 +75,9 @@ thread_pool::set_thread_count (size_t num_threads)
for (size_t i = m_thread_count; i < num_threads; ++i)
{
std::thread thread (&thread_pool::thread_function, this);
+#ifdef USE_PTHREAD_SETNAME_NP
+ pthread_setname_np (thread.native_handle (), "gdb worker");
+#endif
thread.detach ();
}
}