[macos] Fix warnings around syscall deprecation on OS X 10.12 and up
Change-Id: I16333fc65f2539f6cc6f0116b2b0478cd9966636
diff --git a/src/raw_logging.cc b/src/raw_logging.cc
index 7a7409b..5224f19 100644
--- a/src/raw_logging.cc
+++ b/src/raw_logging.cc
@@ -59,7 +59,8 @@
# include <unistd.h>
#endif
-#if defined(HAVE_SYSCALL_H) || defined(HAVE_SYS_SYSCALL_H)
+#if (defined(HAVE_SYSCALL_H) || defined(HAVE_SYS_SYSCALL_H)) && \
+ MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
# define safe_write(fd, s, len) syscall(SYS_write, fd, s, len)
#else
// Not so safe, but what can you do?
diff --git a/src/utilities.cc b/src/utilities.cc
index 5c88e58..09b96b2 100644
--- a/src/utilities.cc
+++ b/src/utilities.cc
@@ -238,8 +238,15 @@
}
pid_t GetTID() {
- // On Linux and MacOSX, we try to use gettid().
+ // On Linux, and MacOSX prior to 10.12, we try to use gettid(). On
+ // MacOSX 10.12 and later, we use pthread_threadid_np instead, as
+ // syscall is deprecated.
#if defined OS_LINUX || defined OS_MACOSX
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
+ uint64_t tid;
+ pthread_threadid_np(nullptr, &tid);
+ return static_cast<pid_t>(tid);
+#else
#ifndef __NR_gettid
#ifdef OS_MACOSX
#define __NR_gettid SYS_gettid
@@ -261,6 +268,7 @@
// the value change to "true".
lacks_gettid = true;
}
+#endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
#endif // OS_LINUX || OS_MACOSX
// If gettid() could not be used, we use one of the following.