Skip to content

Commit

Permalink
os-inl.h: fix for missing pthread_threadid_np
Browse files Browse the repository at this point in the history
  • Loading branch information
barracuda156 committed Apr 22, 2023
1 parent 0ca574a commit 4ee132d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion include/spdlog/details/os-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@

#endif // unix

#if defined __APPLE__
# include <AvailabilityMacros.h>
#endif

#ifndef __has_feature // Clang - feature checking macros.
# define __has_feature(x) 0 // Compatibility with non-clang compilers.
#endif
Expand Down Expand Up @@ -355,7 +359,17 @@ SPDLOG_INLINE size_t _thread_id() SPDLOG_NOEXCEPT
return static_cast<size_t>(::thr_self());
#elif __APPLE__
uint64_t tid;
pthread_threadid_np(nullptr, &tid);
# if (MAC_OS_X_VERSION_MAX_ALLOWED < 1060) || defined(__POWERPC__)
tid = pthread_mach_thread_np(pthread_self());
# elif MAC_OS_X_VERSION_MIN_REQUIRED < 1060
if (&pthread_threadid_np) {
pthread_threadid_np(nullptr, &tid);
} else {
tid = pthread_mach_thread_np(pthread_self());
}
# else
pthread_threadid_np(nullptr, &tid);
# endif
return static_cast<size_t>(tid);
#else // Default to standard C++11 (other Unix)
return static_cast<size_t>(std::hash<std::thread::id>()(std::this_thread::get_id()));
Expand Down

0 comments on commit 4ee132d

Please sign in to comment.