diff --git a/system_wrappers/source/event_timer_posix.cc b/system_wrappers/source/event_timer_posix.cc index 2a6a580c64..e79aa9900a 100644 --- a/system_wrappers/source/event_timer_posix.cc +++ b/system_wrappers/source/event_timer_posix.cc @@ -10,6 +10,10 @@ #include "system_wrappers/source/event_timer_posix.h" +#if defined(WEBRTC_ANDROID) +#include +#endif + #include #include #include @@ -20,6 +24,17 @@ #include "rtc_base/checks.h" +#if defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC) +// Chromium build is always defining this macro if __ANDROID_API__ < 20. +#undef HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC +#endif + +#if defined(WEBRTC_ANDROID) && defined(__ANDROID_API__) +#define HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC (__ANDROID_API__ < 21) +#else +#define HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC 0 +#endif + namespace webrtc { // static @@ -48,8 +63,7 @@ EventTimerPosix::EventTimerPosix() // all supported Android platforms support pthread_condattr_setclock. // TODO(sprang): Add support for monotonic clock on Apple platforms. #if !(defined(WEBRTC_MAC) || defined(WEBRTC_IOS)) && \ - !(defined(WEBRTC_ANDROID) && \ - defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC)) + !(defined(WEBRTC_ANDROID) && HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC) pthread_condattr_setclock(&cond_attr, CLOCK_MONOTONIC); #endif pthread_cond_init(&cond_, &cond_attr); @@ -96,7 +110,7 @@ EventTypeWrapper EventTimerPosix::Wait(unsigned long timeout_ms) { end_at.tv_nsec -= kNanosecondsPerSecond; } while (ret_val == 0 && !event_set_) { -#if defined(WEBRTC_ANDROID) && defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC) +#if defined(WEBRTC_ANDROID) && HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC ret_val = pthread_cond_timedwait_monotonic_np(&cond_, &mutex_, &end_at); #else ret_val = pthread_cond_timedwait(&cond_, &mutex_, &end_at); @@ -129,7 +143,7 @@ EventTypeWrapper EventTimerPosix::Wait(timespec* end_at, bool reset_event) { } while (ret_val == 0 && !event_set_) { -#if defined(WEBRTC_ANDROID) && defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC) +#if defined(WEBRTC_ANDROID) && HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC ret_val = pthread_cond_timedwait_monotonic_np(&cond_, &mutex_, end_at); #else ret_val = pthread_cond_timedwait(&cond_, &mutex_, end_at);