OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/time.h" | 5 #include "base/time.h" |
6 | 6 |
7 #include <sys/time.h> | 7 #include <sys/time.h> |
8 #include <time.h> | 8 #include <time.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 | 10 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 164 |
165 // Adjust from Unix (1970) to Windows (1601) epoch. | 165 // Adjust from Unix (1970) to Windows (1601) epoch. |
166 return Time((milliseconds * kMicrosecondsPerMillisecond) + | 166 return Time((milliseconds * kMicrosecondsPerMillisecond) + |
167 kWindowsEpochDeltaMicroseconds); | 167 kWindowsEpochDeltaMicroseconds); |
168 } | 168 } |
169 | 169 |
170 // TimeTicks ------------------------------------------------------------------ | 170 // TimeTicks ------------------------------------------------------------------ |
171 // FreeBSD 6 has CLOCK_MONOLITHIC but defines _POSIX_MONOTONIC_CLOCK to -1. | 171 // FreeBSD 6 has CLOCK_MONOLITHIC but defines _POSIX_MONOTONIC_CLOCK to -1. |
172 #if (defined(OS_POSIX) && \ | 172 #if (defined(OS_POSIX) && \ |
173 defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0) || \ | 173 defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0) || \ |
174 defined(OS_FREEBSD) || defined(OS_OPENBSD) || defined(OS_ANDROID) | 174 defined(OS_BSD) || defined(OS_ANDROID) |
175 | 175 |
176 // static | 176 // static |
177 TimeTicks TimeTicks::Now() { | 177 TimeTicks TimeTicks::Now() { |
178 uint64_t absolute_micro; | 178 uint64_t absolute_micro; |
179 | 179 |
180 struct timespec ts; | 180 struct timespec ts; |
181 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { | 181 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { |
182 NOTREACHED() << "clock_gettime(CLOCK_MONOTONIC) failed."; | 182 NOTREACHED() << "clock_gettime(CLOCK_MONOTONIC) failed."; |
183 return TimeTicks(); | 183 return TimeTicks(); |
184 } | 184 } |
(...skipping 27 matching lines...) Expand all Loading... |
212 | 212 |
213 struct timeval Time::ToTimeVal() const { | 213 struct timeval Time::ToTimeVal() const { |
214 struct timeval result; | 214 struct timeval result; |
215 int64 us = us_ - kTimeTToMicrosecondsOffset; | 215 int64 us = us_ - kTimeTToMicrosecondsOffset; |
216 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 216 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
217 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 217 result.tv_usec = us % Time::kMicrosecondsPerSecond; |
218 return result; | 218 return result; |
219 } | 219 } |
220 | 220 |
221 } // namespace base | 221 } // namespace base |
OLD | NEW |