From 66d4926e41ad61ba034d1d752d2514ae0241d692 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Fri, 29 Dec 2017 14:35:20 -0800 Subject: [PATCH] Remove and set thread name on BSD & __APPLE__ --- src/platform_posix.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/platform_posix.cc b/src/platform_posix.cc index fe6b1e5f..42ee5559 100644 --- a/src/platform_posix.cc +++ b/src/platform_posix.cc @@ -37,7 +37,6 @@ #include // sysctl #elif defined(__linux__) #include -#include #endif namespace { @@ -266,8 +265,12 @@ bool TryMakeDirectory(const std::string& absolute_path) { void SetCurrentThreadName(const std::string& thread_name) { loguru::set_thread_name(thread_name.c_str()); -#ifdef __linux__ - prctl(PR_SET_NAME, thread_name.c_str(), 0, 0, 0); +#if defined(__APPLE__) + pthread_setname_np(thread_name.c_str()); +#elif defined(__FreeBSD__) || defined(__OpenBSD__) + pthread_set_name_np(pthread_self(), thread_name.c_str()); +#elif defined(__linux__) + pthread_setname_np(pthread_self(), thread_name.c_str()); #endif }