Skip to content

Commit

Permalink
android: fix pthread compiler conditionals (envoyproxy#12081)
Browse files Browse the repository at this point in the history
android: fix pthread compiler conditionals
Risk Level: Low
Testing: Local builds / CI in Envoy Mobile
Docs Changes: None

Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: scheler <santosh.cheler@appdynamics.com>
  • Loading branch information
rebello95 authored and scheler committed Aug 4, 2020
1 parent 0ed0464 commit caf2e4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
24 changes: 10 additions & 14 deletions include/envoy/common/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,19 +248,15 @@ 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
#define SUPPORTS_PTHREAD_NAMING 0
#if defined(__ANDROID_API__)
#if __ANDROID_API__ >= 26
#undef SUPPORTS_PTHREAD_NAMING
#define SUPPORTS_PTHREAD_NAMING 1
#endif // __ANDROID_API__ >= 26
#elif defined(__linux__)
#undef SUPPORTS_PTHREAD_NAMING
#define SUPPORTS_PTHREAD_NAMING 1
#endif // defined(__ANDROID_API__)
4 changes: 2 additions & 2 deletions source/common/common/posix/thread_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit caf2e4b

Please sign in to comment.