From 2dd8483b7ce9656554cd2ba3901f448c2ec0a042 Mon Sep 17 00:00:00 2001 From: hehechen Date: Wed, 18 Jan 2023 14:49:52 +0800 Subject: [PATCH] fix compile on mac os (#6652) close pingcap/tiflash#6651 --- dbms/src/Common/setThreadName.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dbms/src/Common/setThreadName.cpp b/dbms/src/Common/setThreadName.cpp index 4d0aadd26ba..4b9739b8416 100644 --- a/dbms/src/Common/setThreadName.cpp +++ b/dbms/src/Common/setThreadName.cpp @@ -77,5 +77,15 @@ std::string getThreadName() std::string getThreadNameAndID() { - return getThreadName() + "_" + DB::toString(pthread_self()); + uint64_t thread_id; +#if defined(__APPLE__) + int err = pthread_threadid_np(pthread_self(), &thread_id); + if (err) + DB::throwFromErrno("Cannot get thread id with pthread_threadid_np()", DB::ErrorCodes::PTHREAD_ERROR, err); +#elif defined(__FreeBSD__) + thread_id = pthread_getthreadid_np(); +#else + thread_id = pthread_self(); +#endif + return getThreadName() + "_" + DB::toString(thread_id); }