From 14bc8b53cdc07f92d1f1f6198bbc59b37771f87e Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Tue, 14 Jul 2020 14:30:29 -0700 Subject: [PATCH 1/3] android: fix pthread compiler conditionals Signed-off-by: Michael Rebello --- include/envoy/common/platform.h | 21 +++++++-------------- source/common/common/posix/thread_impl.cc | 4 ++-- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/include/envoy/common/platform.h b/include/envoy/common/platform.h index c3398829f8abf..aaa35873ce30f 100644 --- a/include/envoy/common/platform.h +++ b/include/envoy/common/platform.h @@ -248,19 +248,12 @@ struct mmsghdr { #endif // __ANDROID_API__ < 24 #endif // ifdef __ANDROID_API__ -#ifdef __linux__ -#define SUPPORTS_PTHREAD_GETNAME_NP 1 -#endif - // https://android.googlesource.com/platform/bionic/+/master/docs/status.md // ``pthread_getname_np`` is introduced in API 26 -#ifdef __ANDROID_API__ -#if __ANDROID_API__ > 26 -#define SUPPORTS_PTHREAD_GETNAME_NP 1 -#endif // __ANDROID_API__ > 26 -#endif // ifdef __ANDROID_API__ - -// Ensure `SUPPORTS_PTHREAD_GETNAME_NP` is set -#ifndef SUPPORTS_PTHREAD_GETNAME_NP -#define SUPPORTS_PTHREAD_GETNAME_NP 0 -#endif +#if defined(__ANDROID_API__) +#if __ANDROID_API__ >= 26 +#define SUPPORTS_PTHREAD_GETNAME_NP +#endif // __ANDROID_API__ >= 26 +#elif defined(__linux__) +#define SUPPORTS_PTHREAD_GETNAME_NP +#endif // defined(__ANDROID_API__) diff --git a/source/common/common/posix/thread_impl.cc b/source/common/common/posix/thread_impl.cc index c85bbfce57ec0..c063d97d53d8e 100644 --- a/source/common/common/posix/thread_impl.cc +++ b/source/common/common/posix/thread_impl.cc @@ -52,7 +52,7 @@ class ThreadImplPosix : public Thread { this); RELEASE_ASSERT(rc == 0, ""); -#if SUPPORTS_PTHREAD_GETNAME_NP +#ifdef SUPPORTS_PTHREAD_GETNAME_NP // If the name was not specified, get it from the OS. If the name was // specified, write it into the thread, and assert that the OS sees it the // same way. @@ -93,7 +93,7 @@ class ThreadImplPosix : public Thread { } private: -#if SUPPORTS_PTHREAD_GETNAME_NP +#ifdef SUPPORTS_PTHREAD_GETNAME_NP // Attempts to get the name from the operating system, returning true and // updating 'name' if successful. Note that during normal operation this // may fail, if the thread exits prior to the system call. From 32b79c13c07b5c64f11de7776ca3b91e03a2670b Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Tue, 14 Jul 2020 15:15:45 -0700 Subject: [PATCH 2/3] CR Signed-off-by: Michael Rebello --- include/envoy/common/platform.h | 7 +++++-- source/common/common/posix/thread_impl.cc | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/envoy/common/platform.h b/include/envoy/common/platform.h index aaa35873ce30f..a0a1fac6bb3ae 100644 --- a/include/envoy/common/platform.h +++ b/include/envoy/common/platform.h @@ -250,10 +250,13 @@ struct mmsghdr { // https://android.googlesource.com/platform/bionic/+/master/docs/status.md // ``pthread_getname_np`` is introduced in API 26 +#define SUPPORTS_PTHREAD_GETNAME_NP 0 #if defined(__ANDROID_API__) #if __ANDROID_API__ >= 26 -#define SUPPORTS_PTHREAD_GETNAME_NP +#undef SUPPORTS_PTHREAD_GETNAME_NP +#define SUPPORTS_PTHREAD_GETNAME_NP 1 #endif // __ANDROID_API__ >= 26 #elif defined(__linux__) -#define SUPPORTS_PTHREAD_GETNAME_NP +#undef SUPPORTS_PTHREAD_GETNAME_NP +#define SUPPORTS_PTHREAD_GETNAME_NP 1 #endif // defined(__ANDROID_API__) diff --git a/source/common/common/posix/thread_impl.cc b/source/common/common/posix/thread_impl.cc index c063d97d53d8e..c85bbfce57ec0 100644 --- a/source/common/common/posix/thread_impl.cc +++ b/source/common/common/posix/thread_impl.cc @@ -52,7 +52,7 @@ class ThreadImplPosix : public Thread { this); RELEASE_ASSERT(rc == 0, ""); -#ifdef SUPPORTS_PTHREAD_GETNAME_NP +#if SUPPORTS_PTHREAD_GETNAME_NP // If the name was not specified, get it from the OS. If the name was // specified, write it into the thread, and assert that the OS sees it the // same way. @@ -93,7 +93,7 @@ class ThreadImplPosix : public Thread { } private: -#ifdef SUPPORTS_PTHREAD_GETNAME_NP +#if SUPPORTS_PTHREAD_GETNAME_NP // Attempts to get the name from the operating system, returning true and // updating 'name' if successful. Note that during normal operation this // may fail, if the thread exits prior to the system call. From 021563741b3945d8b2dfd3c4ab0af8de7fdb02cb Mon Sep 17 00:00:00 2001 From: Michael Rebello Date: Tue, 14 Jul 2020 15:38:15 -0700 Subject: [PATCH 3/3] address naming nits Signed-off-by: Michael Rebello --- include/envoy/common/platform.h | 10 +++++----- source/common/common/posix/thread_impl.cc | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/envoy/common/platform.h b/include/envoy/common/platform.h index a0a1fac6bb3ae..d5606ca32ee48 100644 --- a/include/envoy/common/platform.h +++ b/include/envoy/common/platform.h @@ -250,13 +250,13 @@ struct mmsghdr { // https://android.googlesource.com/platform/bionic/+/master/docs/status.md // ``pthread_getname_np`` is introduced in API 26 -#define SUPPORTS_PTHREAD_GETNAME_NP 0 +#define SUPPORTS_PTHREAD_NAMING 0 #if defined(__ANDROID_API__) #if __ANDROID_API__ >= 26 -#undef SUPPORTS_PTHREAD_GETNAME_NP -#define SUPPORTS_PTHREAD_GETNAME_NP 1 +#undef SUPPORTS_PTHREAD_NAMING +#define SUPPORTS_PTHREAD_NAMING 1 #endif // __ANDROID_API__ >= 26 #elif defined(__linux__) -#undef SUPPORTS_PTHREAD_GETNAME_NP -#define SUPPORTS_PTHREAD_GETNAME_NP 1 +#undef SUPPORTS_PTHREAD_NAMING +#define SUPPORTS_PTHREAD_NAMING 1 #endif // defined(__ANDROID_API__) diff --git a/source/common/common/posix/thread_impl.cc b/source/common/common/posix/thread_impl.cc index c85bbfce57ec0..71cbf2b02eb6b 100644 --- a/source/common/common/posix/thread_impl.cc +++ b/source/common/common/posix/thread_impl.cc @@ -52,7 +52,7 @@ class ThreadImplPosix : public Thread { this); RELEASE_ASSERT(rc == 0, ""); -#if SUPPORTS_PTHREAD_GETNAME_NP +#if SUPPORTS_PTHREAD_NAMING // If the name was not specified, get it from the OS. If the name was // specified, write it into the thread, and assert that the OS sees it the // same way. @@ -93,7 +93,7 @@ class ThreadImplPosix : public Thread { } private: -#if SUPPORTS_PTHREAD_GETNAME_NP +#if SUPPORTS_PTHREAD_NAMING // Attempts to get the name from the operating system, returning true and // updating 'name' if successful. Note that during normal operation this // may fail, if the thread exits prior to the system call.