+2019-12-11 Tom Tromey <tromey@adacore.com>
+
+ PR build/25268:
+ * gdbsupport/thread-pool.c (set_thread_name): New function.
+ (thread_pool::set_thread_count): Don't call pthread_setname_np.
+ (thread_pool::thread_function): Call set_thread_name.
+
2019-12-11 Tom Tromey <tromey@adacore.com>
* fbsd-tdep.c (fbsd_core_info_proc_status): Cast result of
#include "gdbsupport/alt-stack.h"
#include "gdbsupport/block-signals.h"
#include <algorithm>
+#include "diagnostics.h"
/* On the off chance that we have the pthread library on a Windows
host, but std::thread is not using it, avoid calling
#endif
#ifdef USE_PTHREAD_SETNAME_NP
+
#include <pthread.h>
-#endif
+
+DIAGNOSTIC_PUSH
+DIAGNOSTIC_IGNORE_UNUSED_FUNCTION
+
+/* Handle platform discrepancies in pthread_setname_np: macOS uses a
+ single-argument form, while Linux uses a two-argument form. This
+ wrapper handles the difference. */
+
+static void
+set_thread_name (int (*set_name) (pthread_t, const char *), const char *name)
+{
+ set_name (pthread_self (), name);
+}
+
+static void
+set_thread_name (void (*set_name) (const char *), const char *name)
+{
+ set_name (name);
+}
+
+DIAGNOSTIC_POP
+
+#endif /* USE_PTHREAD_SETNAME_NP */
namespace gdb
{
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 ();
}
}
void
thread_pool::thread_function ()
{
+#ifdef USE_PTHREAD_SETNAME_NP
+ /* This must be done here, because on macOS one can only set the
+ name of the current thread. */
+ set_thread_name (pthread_setname_np, "gdb worker");
+#endif
+
/* Ensure that SIGSEGV is delivered to an alternate signal
stack. */
gdb::alternate_signal_stack signal_stack;