OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // 0x0fffffff ~3.1 days, the code will not take that long to execute | 99 // 0x0fffffff ~3.1 days, the code will not take that long to execute |
100 // so it must have been a wrap around. | 100 // so it must have been a wrap around. |
101 if (old > 0xf0000000 && now < 0x0fffffff) { | 101 if (old > 0xf0000000 && now < 0x0fffffff) { |
102 // TODO(pbos): Fix unsafe use of static locals. | 102 // TODO(pbos): Fix unsafe use of static locals. |
103 num_wrap_time_get_time++; | 103 num_wrap_time_get_time++; |
104 } | 104 } |
105 } | 105 } |
106 return now + (num_wrap_time_get_time << 32); | 106 return now + (num_wrap_time_get_time << 32); |
107 #elif defined(WEBRTC_LINUX) | 107 #elif defined(WEBRTC_LINUX) |
108 struct timespec ts; | 108 struct timespec ts; |
109 // TODO(wu): Remove CLOCK_REALTIME implementation. | |
110 #ifdef WEBRTC_CLOCK_TYPE_REALTIME | |
111 clock_gettime(CLOCK_REALTIME, &ts); | |
112 #else | |
113 clock_gettime(CLOCK_MONOTONIC, &ts); | 109 clock_gettime(CLOCK_MONOTONIC, &ts); |
114 #endif | |
115 return 1000000000LL * ts.tv_sec + ts.tv_nsec; | 110 return 1000000000LL * ts.tv_sec + ts.tv_nsec; |
116 #elif defined(WEBRTC_MAC) | 111 #elif defined(WEBRTC_MAC) |
117 // Return absolute time as an offset from the first call to this function, so | 112 // Return absolute time as an offset from the first call to this function, so |
118 // that we can do floating-point (double) operations on it without losing | 113 // that we can do floating-point (double) operations on it without losing |
119 // precision. This holds true until the elapsed time is ~11 days, | 114 // precision. This holds true until the elapsed time is ~11 days, |
120 // at which point we'll start to lose some precision, though not enough to | 115 // at which point we'll start to lose some precision, though not enough to |
121 // matter for millisecond accuracy for another couple years after that. | 116 // matter for millisecond accuracy for another couple years after that. |
122 // TODO(pbos): Fix unsafe use of static locals. | 117 // TODO(pbos): Fix unsafe use of static locals. |
123 static uint64_t timebase_start = 0; | 118 static uint64_t timebase_start = 0; |
124 if (timebase_start == 0) { | 119 if (timebase_start == 0) { |
125 timebase_start = mach_absolute_time(); | 120 timebase_start = mach_absolute_time(); |
126 } | 121 } |
127 return mach_absolute_time() - timebase_start; | 122 return mach_absolute_time() - timebase_start; |
128 #else | 123 #else |
129 struct timeval tv; | 124 struct timeval tv; |
130 gettimeofday(&tv, NULL); | 125 gettimeofday(&tv, NULL); |
131 return 1000000LL * tv.tv_sec + tv.tv_usec; | 126 return 1000000LL * tv.tv_sec + tv.tv_usec; |
132 #endif | 127 #endif |
133 } | 128 } |
134 | 129 |
135 } // namespace webrtc | 130 } // namespace webrtc |
OLD | NEW |