 Chromium Code Reviews
 Chromium Code Reviews Issue 1639543005:
  Use rtc::time for all your timing needs!  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master
    
  
    Issue 1639543005:
  Use rtc::time for all your timing needs!  (Closed) 
  Base URL: https://chromium.googlesource.com/external/webrtc.git@master| OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 
| 3 * | 3 * | 
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license | 
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source | 
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found | 
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may | 
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. | 
| 9 */ | 9 */ | 
| 10 | 10 | 
| (...skipping 28 matching lines...) Expand all Loading... | |
| 39 #if defined(WEBRTC_MAC) | 39 #if defined(WEBRTC_MAC) | 
| 40 static mach_timebase_info_data_t timebase; | 40 static mach_timebase_info_data_t timebase; | 
| 41 if (timebase.denom == 0) { | 41 if (timebase.denom == 0) { | 
| 42 // Get the timebase if this is the first time we run. | 42 // Get the timebase if this is the first time we run. | 
| 43 // Recommended by Apple's QA1398. | 43 // Recommended by Apple's QA1398. | 
| 44 if (mach_timebase_info(&timebase) != KERN_SUCCESS) { | 44 if (mach_timebase_info(&timebase) != KERN_SUCCESS) { | 
| 45 RTC_DCHECK(false); | 45 RTC_DCHECK(false); | 
| 46 } | 46 } | 
| 47 } | 47 } | 
| 48 // Use timebase to convert absolute time tick units into nanoseconds. | 48 // Use timebase to convert absolute time tick units into nanoseconds. | 
| 49 ticks = mach_absolute_time() * timebase.numer / timebase.denom; | 49 ticks = mach_absolute_time() * timebase.numer / timebase.denom; | 
| 
tommi
2016/01/26 23:23:46
since we're here - can we do something about this
 
sprang_webrtc
2016/01/27 08:48:47
Are your sure "low initial value" applies here? Th
 
noahric
2016/04/05 04:48:28
FYI, the reason it was different was: https://code
 | |
| 50 #elif defined(WEBRTC_POSIX) | 50 #elif defined(WEBRTC_POSIX) | 
| 51 struct timespec ts; | 51 struct timespec ts; | 
| 52 // TODO: Do we need to handle the case when CLOCK_MONOTONIC | 52 // TODO: Do we need to handle the case when CLOCK_MONOTONIC | 
| 53 // is not supported? | 53 // is not supported? | 
| 54 clock_gettime(CLOCK_MONOTONIC, &ts); | 54 clock_gettime(CLOCK_MONOTONIC, &ts); | 
| 55 ticks = kNumNanosecsPerSec * static_cast<int64_t>(ts.tv_sec) + | 55 ticks = kNumNanosecsPerSec * static_cast<int64_t>(ts.tv_sec) + | 
| 56 static_cast<int64_t>(ts.tv_nsec); | 56 static_cast<int64_t>(ts.tv_nsec); | 
| 57 #elif defined(WEBRTC_WIN) | 57 #elif defined(WEBRTC_WIN) | 
| 58 static volatile LONG last_timegettime = 0; | 58 static volatile LONG last_timegettime = 0; | 
| 59 static volatile int64_t num_wrap_timegettime = 0; | 59 static volatile int64_t num_wrap_timegettime = 0; | 
| 60 volatile LONG* last_timegettime_ptr = &last_timegettime; | 60 volatile LONG* last_timegettime_ptr = &last_timegettime; | 
| 61 DWORD now = timeGetTime(); | 61 DWORD now = timeGetTime(); | 
| 62 // Atomically update the last gotten time | 62 // Atomically update the last gotten time | 
| 63 DWORD old = InterlockedExchange(last_timegettime_ptr, now); | 63 DWORD old = InterlockedExchange(last_timegettime_ptr, now); | 
| 64 if (now < old) { | 64 if (now < old) { | 
| 65 // If now is earlier than old, there may have been a race between | 65 // If now is earlier than old, there may have been a race between | 
| 66 // threads. | 66 // threads. | 
| 67 // 0x0fffffff ~3.1 days, the code will not take that long to execute | 67 // 0x0fffffff ~3.1 days, the code will not take that long to execute | 
| 68 // so it must have been a wrap around. | 68 // so it must have been a wrap around. | 
| 69 if (old > 0xf0000000 && now < 0x0fffffff) { | 69 if (old > 0xf0000000 && now < 0x0fffffff) { | 
| 70 num_wrap_timegettime++; | 70 num_wrap_timegettime++; | 
| 71 } | 71 } | 
| 72 } | 72 } | 
| 73 ticks = now + (num_wrap_timegettime << 32); | 73 ticks = now + (num_wrap_timegettime << 32); | 
| 74 // TODO: Calculate with nanosecond precision. Otherwise, we're just | 74 // TODO: Calculate with nanosecond precision. Otherwise, we're just | 
| 75 // wasting a multiply and divide when doing Time() on Windows. | 75 // wasting a multiply and divide when doing Time() on Windows. | 
| 76 ticks = ticks * kNumNanosecsPerMillisec; | 76 ticks = ticks * kNumNanosecsPerMillisec; | 
| 77 #else | |
| 
pbos-webrtc
2016/01/26 15:00:22
#else #error? Do we ever build with none of these
 
sprang_webrtc
2016/01/27 08:48:47
Agreed it makes more sense to have #error here ins
 | |
| 78 struct timeval tv; | |
| 79 gettimeofday(&tv, NULL); | |
| 80 ticks = | |
| 81 (kNumNanosecsPerSec * tv.tv_sec) + (kNumNanosecsPerMicrosec * tv.tv_usec); | |
| 77 #endif | 82 #endif | 
| 78 return ticks; | 83 return ticks; | 
| 79 } | 84 } | 
| 80 | 85 | 
| 81 uint32_t Time() { | 86 uint32_t Time() { | 
| 82 return static_cast<uint32_t>(TimeNanos() / kNumNanosecsPerMillisec); | 87 return static_cast<uint32_t>(TimeNanos() / kNumNanosecsPerMillisec); | 
| 83 } | 88 } | 
| 84 | 89 | 
| 85 uint64_t TimeMicros() { | 90 uint64_t TimeMicros() { | 
| 86 return static_cast<uint64_t>(TimeNanos() / kNumNanosecsPerMicrosec); | 91 return static_cast<uint64_t>(TimeNanos() / kNumNanosecsPerMicrosec); | 
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 242 if (expiry_in_leap_year && month <= 2 - 1) // |month| is zero based. | 247 if (expiry_in_leap_year && month <= 2 - 1) // |month| is zero based. | 
| 243 day -= 1; | 248 day -= 1; | 
| 244 | 249 | 
| 245 // Combine all variables into seconds from 1970-01-01 00:00 (except |month| | 250 // Combine all variables into seconds from 1970-01-01 00:00 (except |month| | 
| 246 // which was accumulated into |day| above). | 251 // which was accumulated into |day| above). | 
| 247 return (((static_cast<int64_t> | 252 return (((static_cast<int64_t> | 
| 248 (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec; | 253 (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec; | 
| 249 } | 254 } | 
| 250 | 255 | 
| 251 } // namespace rtc | 256 } // namespace rtc | 
| OLD | NEW |