Fixing issues that affect newest versions of NDK.

Bug: None
Change-Id: Idcdaf229ee91758d7cd78de8e56d709d10660052
Reviewed-on: https://webrtc-review.googlesource.com/57584
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22200}
This commit is contained in:
Mirko Bonadei 2018-02-26 17:06:51 +01:00 committed by Commit Bot
parent 461cdf0dd1
commit 7fd74ff1a5

View File

@ -10,6 +10,10 @@
#include "system_wrappers/source/event_timer_posix.h"
#if defined(WEBRTC_ANDROID)
#include <android/api-level.h>
#endif
#include <errno.h>
#include <pthread.h>
#include <signal.h>
@ -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);