Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ check_cxx_compiler_flag (-Wdeprecated HAVE_NO_DEPRECATED)
check_cxx_compiler_flag (-Wunnamed-type-template-args
HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS)

cmake_push_check_state (RESET)
set (CMAKE_REQUIRED_LIBRARIES Threads::Threads)
check_cxx_symbol_exists (pthread_threadid_np "pthread.h" HAVE_PTHREAD_THREADID_NP)
cmake_pop_check_state ()

# NOTE: Cannot use check_function_exists here since >=vc-14.0 can define
# snprintf as an inline function
check_cxx_symbol_exists (snprintf cstdio HAVE_SNPRINTF)
Expand Down
3 changes: 3 additions & 0 deletions src/config.h.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -222,4 +222,7 @@

#endif

/* Replacement for deprecated syscall(SYS_gettid) on macOS. */
#cmakedefine HAVE_PTHREAD_THREADID_NP ${HAVE_PTHREAD_THREADID_NP}

#endif // GLOG_CONFIG_H
2 changes: 1 addition & 1 deletion src/raw_logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
# include <unistd.h>
#endif

#if defined(HAVE_SYSCALL_H) || defined(HAVE_SYS_SYSCALL_H)
#if (defined(HAVE_SYSCALL_H) || defined(HAVE_SYS_SYSCALL_H)) && (!(defined(OS_MACOSX)))
# define safe_write(fd, s, len) syscall(SYS_write, fd, s, len)
#else
// Not so safe, but what can you do?
Expand Down
6 changes: 6 additions & 0 deletions src/utilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,13 @@ pid_t GetTID() {
#endif
static bool lacks_gettid = false;
if (!lacks_gettid) {
#if (defined(OS_MACOSX) && defined(HAVE_PTHREAD_THREADID_NP))
uint64_t tid64;
const int error = pthread_threadid_np(NULL, &tid64);
pid_t tid = error ? -1 : (pid_t)tid64;
#else
pid_t tid = syscall(__NR_gettid);
#endif
if (tid != -1) {
return tid;
}
Expand Down