Remove non-monotonic clock support

Real time clock may cause problems as they can move (even backwards) if
the clock is changed, eg updated by NTP.

Non-monotonic clocks still in use on some platform (I'm looking at you,
Apple) for timed waits, but that should be less of an issue than actual
timestamps.

BUG=webrtc:5452

Review URL: https://codereview.webrtc.org/1613013002

Cr-Commit-Position: refs/heads/master@{#11375}
This commit is contained in:
sprang 2016-01-26 01:53:20 -08:00 committed by Commit bot
parent 4fd6cda067
commit e791ffd638
5 changed files with 23 additions and 48 deletions

View File

@ -179,7 +179,7 @@ void PlatformThread::Run() {
if (!name_.empty())
rtc::SetCurrentThreadName(name_.c_str());
do {
// The interface contract of Start/Stop is that for a successfull call to
// The interface contract of Start/Stop is that for a successful call to
// Start, there should be at least one call to the run function. So we
// call the function before checking |stop_|.
if (!run_function_(obj_))

View File

@ -99,15 +99,7 @@ static_library("system_wrappers") {
"source/logcat_trace_context.cc",
]
defines += [
"WEBRTC_THREAD_RR",
# TODO(leozwang): Investigate CLOCK_REALTIME and CLOCK_MONOTONIC
# support on Android. Keep WEBRTC_CLOCK_TYPE_REALTIME for now,
# remove it after I verify that CLOCK_MONOTONIC is fully functional
# with condition and event functions in system_wrappers.
"WEBRTC_CLOCK_TYPE_REALTIME",
]
defines += [ "WEBRTC_THREAD_RR" ]
deps += [ ":cpu_features_android" ]
@ -115,12 +107,7 @@ static_library("system_wrappers") {
}
if (is_linux) {
defines += [
"WEBRTC_THREAD_RR",
# TODO(andrew): can we select this automatically?
# Define this if the Linux system does not support CLOCK_MONOTONIC.
#"WEBRTC_CLOCK_TYPE_REALTIME",
]
defines += [ "WEBRTC_THREAD_RR" ]
libs += [ "rt" ]
}
@ -130,10 +117,7 @@ static_library("system_wrappers") {
}
if (is_ios || is_mac) {
defines += [
"WEBRTC_THREAD_RR",
"WEBRTC_CLOCK_TYPE_REALTIME",
]
defines += [ "WEBRTC_THREAD_RR" ]
}
if (is_ios) {

View File

@ -41,15 +41,18 @@ EventTimerPosix::EventTimerPosix()
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&mutex_, &attr);
#ifdef WEBRTC_CLOCK_TYPE_REALTIME
pthread_cond_init(&cond_, 0);
#else
pthread_condattr_t cond_attr;
pthread_condattr_init(&cond_attr);
// TODO(sprang): Remove HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC special case once
// 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))
pthread_condattr_setclock(&cond_attr, CLOCK_MONOTONIC);
#endif
pthread_cond_init(&cond_, &cond_attr);
pthread_condattr_destroy(&cond_attr);
#endif
}
EventTimerPosix::~EventTimerPosix() {
@ -75,11 +78,7 @@ EventTypeWrapper EventTimerPosix::Wait(unsigned long timeout) {
if (WEBRTC_EVENT_INFINITE != timeout) {
timespec end_at;
#ifndef WEBRTC_MAC
#ifdef WEBRTC_CLOCK_TYPE_REALTIME
clock_gettime(CLOCK_REALTIME, &end_at);
#else
clock_gettime(CLOCK_MONOTONIC, &end_at);
#endif
#else
timeval value;
struct timezone time_zone;
@ -95,8 +94,13 @@ EventTypeWrapper EventTimerPosix::Wait(unsigned long timeout) {
end_at.tv_sec++;
end_at.tv_nsec -= E9;
}
while (ret_val == 0 && !event_set_)
while (ret_val == 0 && !event_set_) {
#if defined(WEBRTC_ANDROID) && defined(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);
#endif // WEBRTC_ANDROID && HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC
}
} else {
while (ret_val == 0 && !event_set_)
ret_val = pthread_cond_wait(&cond_, &mutex_);
@ -119,8 +123,13 @@ EventTypeWrapper EventTimerPosix::Wait(timespec* end_at) {
int ret_val = 0;
RTC_CHECK_EQ(0, pthread_mutex_lock(&mutex_));
while (ret_val == 0 && !event_set_)
while (ret_val == 0 && !event_set_) {
#if defined(WEBRTC_ANDROID) && defined(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);
#endif // WEBRTC_ANDROID && HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC
}
RTC_DCHECK(ret_val == 0 || ret_val == ETIMEDOUT);
@ -172,11 +181,7 @@ bool EventTimerPosix::Process() {
pthread_mutex_lock(&mutex_);
if (created_at_.tv_sec == 0) {
#ifndef WEBRTC_MAC
#ifdef WEBRTC_CLOCK_TYPE_REALTIME
clock_gettime(CLOCK_REALTIME, &created_at_);
#else
clock_gettime(CLOCK_MONOTONIC, &created_at_);
#endif
#else
timeval value;
struct timezone time_zone;

View File

@ -106,12 +106,7 @@ int64_t TickTime::QueryOsForTicks() {
return now + (num_wrap_time_get_time << 32);
#elif defined(WEBRTC_LINUX)
struct timespec ts;
// TODO(wu): Remove CLOCK_REALTIME implementation.
#ifdef WEBRTC_CLOCK_TYPE_REALTIME
clock_gettime(CLOCK_REALTIME, &ts);
#else
clock_gettime(CLOCK_MONOTONIC, &ts);
#endif
return 1000000000LL * ts.tv_sec + ts.tv_nsec;
#elif defined(WEBRTC_MAC)
// Return absolute time as an offset from the first call to this function, so

View File

@ -97,11 +97,6 @@
['OS=="android"', {
'defines': [
'WEBRTC_THREAD_RR',
# TODO(leozwang): Investigate CLOCK_REALTIME and CLOCK_MONOTONIC
# support on Android. Keep WEBRTC_CLOCK_TYPE_REALTIME for now,
# remove it after I verify that CLOCK_MONOTONIC is fully functional
# with condition and event functions in system_wrappers.
'WEBRTC_CLOCK_TYPE_REALTIME',
],
'conditions': [
['build_with_chromium==1', {
@ -128,9 +123,6 @@
['OS=="linux"', {
'defines': [
'WEBRTC_THREAD_RR',
# TODO(andrew): can we select this automatically?
# Define this if the Linux system does not support CLOCK_MONOTONIC.
#'WEBRTC_CLOCK_TYPE_REALTIME',
],
'link_settings': {
'libraries': [ '-lrt', ],
@ -147,7 +139,6 @@
['OS=="ios" or OS=="mac"', {
'defines': [
'WEBRTC_THREAD_RR',
'WEBRTC_CLOCK_TYPE_REALTIME',
],
}],
['OS=="win"', {