From 34c11da50108ba4171fe5090fa96b53941bc54ce Mon Sep 17 00:00:00 2001 From: hehechen Date: Wed, 18 Jan 2023 10:47:51 +0800 Subject: [PATCH] fix compile on mac os Signed-off-by: hehechen --- 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); }