Skip to content

Commit

Permalink
fix compile on mac os (#6652)
Browse files Browse the repository at this point in the history
close #6651
  • Loading branch information
hehechen authored Jan 18, 2023
1 parent a17c0bb commit 2dd8483
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion dbms/src/Common/setThreadName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 2dd8483

Please sign in to comment.