Delete unused code in rtc timeutils.

BUG=webrtc:5740

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

Cr-Commit-Position: refs/heads/master@{#12275}
This commit is contained in:
nisse
2016-04-07 02:12:07 -07:00
committed by Commit bot
parent fae14804ee
commit b0c293c5ab
3 changed files with 0 additions and 131 deletions

View File

@ -28,8 +28,6 @@
#include "webrtc/base/checks.h"
#include "webrtc/base/timeutils.h"
#define EFFICIENT_IMPLEMENTATION 1
namespace rtc {
const uint32_t HALF = 0x80000000;
@ -92,108 +90,24 @@ uint64_t TimeMicros() {
return static_cast<uint64_t>(TimeNanos() / kNumNanosecsPerMicrosec);
}
#if defined(WEBRTC_WIN)
static const uint64_t kFileTimeToUnixTimeEpochOffset = 116444736000000000ULL;
struct timeval {
long tv_sec, tv_usec; // NOLINT
};
// Emulate POSIX gettimeofday().
// Based on breakpad/src/third_party/glog/src/utilities.cc
static int gettimeofday(struct timeval *tv, void *tz) {
// FILETIME is measured in tens of microseconds since 1601-01-01 UTC.
FILETIME ft;
GetSystemTimeAsFileTime(&ft);
LARGE_INTEGER li;
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
// Convert to seconds and microseconds since Unix time Epoch.
int64_t micros = (li.QuadPart - kFileTimeToUnixTimeEpochOffset) / 10;
tv->tv_sec = static_cast<long>(micros / kNumMicrosecsPerSec); // NOLINT
tv->tv_usec = static_cast<long>(micros % kNumMicrosecsPerSec); // NOLINT
return 0;
}
// Emulate POSIX gmtime_r().
static struct tm *gmtime_r(const time_t *timep, struct tm *result) {
// On Windows, gmtime is thread safe.
struct tm *tm = gmtime(timep); // NOLINT
if (tm == NULL) {
return NULL;
}
*result = *tm;
return result;
}
#endif // WEBRTC_WIN
void CurrentTmTime(struct tm *tm, int *microseconds) {
struct timeval timeval;
if (gettimeofday(&timeval, NULL) < 0) {
// Incredibly unlikely code path.
timeval.tv_sec = timeval.tv_usec = 0;
}
time_t secs = timeval.tv_sec;
gmtime_r(&secs, tm);
*microseconds = timeval.tv_usec;
}
uint32_t TimeAfter(int32_t elapsed) {
RTC_DCHECK_GE(elapsed, 0);
RTC_DCHECK_LT(static_cast<uint32_t>(elapsed), HALF);
return Time() + elapsed;
}
bool TimeIsBetween(uint32_t earlier, uint32_t middle, uint32_t later) {
if (earlier <= later) {
return ((earlier <= middle) && (middle <= later));
} else {
return !((later < middle) && (middle < earlier));
}
}
bool TimeIsLaterOrEqual(uint32_t earlier, uint32_t later) {
#if EFFICIENT_IMPLEMENTATION
int32_t diff = later - earlier;
return (diff >= 0 && static_cast<uint32_t>(diff) < HALF);
#else
const bool later_or_equal = TimeIsBetween(earlier, later, earlier + HALF);
return later_or_equal;
#endif
}
bool TimeIsLater(uint32_t earlier, uint32_t later) {
#if EFFICIENT_IMPLEMENTATION
int32_t diff = later - earlier;
return (diff > 0 && static_cast<uint32_t>(diff) < HALF);
#else
const bool earlier_or_equal = TimeIsBetween(later, earlier, later + HALF);
return !earlier_or_equal;
#endif
}
int32_t TimeDiff(uint32_t later, uint32_t earlier) {
#if EFFICIENT_IMPLEMENTATION
return later - earlier;
#else
const bool later_or_equal = TimeIsBetween(earlier, later, earlier + HALF);
if (later_or_equal) {
if (earlier <= later) {
return static_cast<long>(later - earlier);
} else {
return static_cast<long>(later + (UINT32_MAX - earlier) + 1);
}
} else {
if (later <= earlier) {
return -static_cast<long>(earlier - later);
} else {
return -static_cast<long>(earlier + (UINT32_MAX - later) + 1);
}
}
#endif
}
int64_t TimeDiff64(int64_t later, int64_t earlier) {

View File

@ -29,9 +29,6 @@ static const int64_t kNumNanosecsPerMillisec =
static const int64_t kNumNanosecsPerMicrosec =
kNumNanosecsPerSec / kNumMicrosecsPerSec;
// January 1970, in NTP milliseconds.
static const int64_t kJan1970AsNtpMillisecs = INT64_C(2208988800000);
typedef uint32_t TimeStamp;
// Returns the current time in milliseconds in 32 bits.
@ -52,16 +49,9 @@ uint64_t TimeMicros();
// Returns the current time in nanoseconds.
uint64_t TimeNanos();
// Stores current time in *tm and microseconds in *microseconds.
void CurrentTmTime(struct tm *tm, int *microseconds);
// Returns a future timestamp, 'elapsed' milliseconds from now.
uint32_t TimeAfter(int32_t elapsed);
// Comparisons between time values, which can wrap around.
bool TimeIsBetween(uint32_t earlier,
uint32_t middle,
uint32_t later); // Inclusive
bool TimeIsLaterOrEqual(uint32_t earlier, uint32_t later); // Inclusive
bool TimeIsLater(uint32_t earlier, uint32_t later); // Exclusive
@ -93,11 +83,6 @@ inline int32_t TimeUntil(uint32_t later) {
return TimeDiff(later, Time());
}
// Converts a unix timestamp in nanoseconds to an NTP timestamp in ms.
inline int64_t UnixTimestampNanosecsToNtpMillisecs(int64_t unix_ts_ns) {
return unix_ts_ns / kNumNanosecsPerMillisec + kJan1970AsNtpMillisecs;
}
class TimestampWrapAroundHandler {
public:
TimestampWrapAroundHandler();

View File

@ -49,19 +49,6 @@ TEST(TimeTest, Comparison) {
EXPECT_TRUE( TimeIsLater(ts_now, ts_later));
EXPECT_TRUE( TimeIsLater(ts_earlier, ts_later));
// Common comparisons
EXPECT_TRUE( TimeIsBetween(ts_earlier, ts_now, ts_later));
EXPECT_FALSE(TimeIsBetween(ts_earlier, ts_later, ts_now));
EXPECT_FALSE(TimeIsBetween(ts_now, ts_earlier, ts_later));
EXPECT_TRUE( TimeIsBetween(ts_now, ts_later, ts_earlier));
EXPECT_TRUE( TimeIsBetween(ts_later, ts_earlier, ts_now));
EXPECT_FALSE(TimeIsBetween(ts_later, ts_now, ts_earlier));
// Edge cases
EXPECT_TRUE( TimeIsBetween(ts_earlier, ts_earlier, ts_earlier));
EXPECT_TRUE( TimeIsBetween(ts_earlier, ts_earlier, ts_later));
EXPECT_TRUE( TimeIsBetween(ts_earlier, ts_later, ts_later));
// Earlier of two times
EXPECT_EQ(ts_earlier, TimeMin(ts_earlier, ts_earlier));
EXPECT_EQ(ts_earlier, TimeMin(ts_earlier, ts_now));
@ -127,23 +114,6 @@ TEST(TimeTest, BoundaryComparison) {
EXPECT_EQ(-100, TimeDiff(ts_earlier, ts_later));
}
TEST(TimeTest, DISABLED_CurrentTmTime) {
struct tm tm;
int microseconds;
time_t before = ::time(NULL);
CurrentTmTime(&tm, &microseconds);
time_t after = ::time(NULL);
// Assert that 'tm' represents a time between 'before' and 'after'.
// mktime() uses local time, so we have to compensate for that.
time_t local_delta = before - ::mktime(::gmtime(&before)); // NOLINT
time_t t = ::mktime(&tm) + local_delta;
EXPECT_TRUE(before <= t && t <= after);
EXPECT_TRUE(0 <= microseconds && microseconds < 1000000);
}
TEST(TimeTest, TestTimeDiff64) {
int64_t ts_diff = 100;
int64_t ts_earlier = rtc::Time64();