Merge pull request #685 from z-aki/master
Fix syscall deprecation warning on macOS >= 10.12
This commit is contained in:
commit
eca3ddef81
@ -140,6 +140,11 @@ check_cxx_compiler_flag (-Wdeprecated HAVE_NO_DEPRECATED)
|
|||||||
check_cxx_compiler_flag (-Wunnamed-type-template-args
|
check_cxx_compiler_flag (-Wunnamed-type-template-args
|
||||||
HAVE_NO_UNNAMED_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
|
# NOTE: Cannot use check_function_exists here since >=vc-14.0 can define
|
||||||
# snprintf as an inline function
|
# snprintf as an inline function
|
||||||
check_cxx_symbol_exists (snprintf cstdio HAVE_SNPRINTF)
|
check_cxx_symbol_exists (snprintf cstdio HAVE_SNPRINTF)
|
||||||
|
|||||||
@ -222,4 +222,7 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Replacement for deprecated syscall(SYS_gettid) on macOS. */
|
||||||
|
#cmakedefine HAVE_PTHREAD_THREADID_NP ${HAVE_PTHREAD_THREADID_NP}
|
||||||
|
|
||||||
#endif // GLOG_CONFIG_H
|
#endif // GLOG_CONFIG_H
|
||||||
|
|||||||
@ -59,7 +59,7 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
#endif
|
#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)
|
# define safe_write(fd, s, len) syscall(SYS_write, fd, s, len)
|
||||||
#else
|
#else
|
||||||
// Not so safe, but what can you do?
|
// Not so safe, but what can you do?
|
||||||
|
|||||||
@ -248,7 +248,13 @@ pid_t GetTID() {
|
|||||||
#endif
|
#endif
|
||||||
static bool lacks_gettid = false;
|
static bool lacks_gettid = false;
|
||||||
if (!lacks_gettid) {
|
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);
|
pid_t tid = syscall(__NR_gettid);
|
||||||
|
#endif
|
||||||
if (tid != -1) {
|
if (tid != -1) {
|
||||||
return tid;
|
return tid;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user