Merge pull request #685 from z-aki/master

Fix syscall deprecation warning on macOS >= 10.12
This commit is contained in:
Sergiu Deitsch 2021-07-14 17:49:43 +02:00 committed by GitHub
commit eca3ddef81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 1 deletions

View File

@ -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)

View File

@ -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

View File

@ -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?

View File

@ -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;
}