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 |
11 #include <limits> | 11 #include <limits> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 | 15 |
| 16 #if defined(OS_ANDROID) |
| 17 #include "base/os_compat_android.h" |
| 18 #endif |
| 19 |
16 namespace base { | 20 namespace base { |
17 | 21 |
| 22 #if defined(OS_ANDROID) |
| 23 #define _POSIX_MONOTONIC_CLOCK 1 |
| 24 #endif |
| 25 |
18 struct timespec TimeDelta::ToTimeSpec() const { | 26 struct timespec TimeDelta::ToTimeSpec() const { |
19 int64 microseconds = InMicroseconds(); | 27 int64 microseconds = InMicroseconds(); |
20 time_t seconds = 0; | 28 time_t seconds = 0; |
21 if (microseconds >= Time::kMicrosecondsPerSecond) { | 29 if (microseconds >= Time::kMicrosecondsPerSecond) { |
22 seconds = InSeconds(); | 30 seconds = InSeconds(); |
23 microseconds -= seconds * Time::kMicrosecondsPerSecond; | 31 microseconds -= seconds * Time::kMicrosecondsPerSecond; |
24 } | 32 } |
25 struct timespec result = | 33 struct timespec result = |
26 {seconds, | 34 {seconds, |
27 microseconds * Time::kNanosecondsPerMicrosecond}; | 35 microseconds * Time::kNanosecondsPerMicrosecond}; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 212 |
205 struct timeval Time::ToTimeVal() const { | 213 struct timeval Time::ToTimeVal() const { |
206 struct timeval result; | 214 struct timeval result; |
207 int64 us = us_ - kTimeTToMicrosecondsOffset; | 215 int64 us = us_ - kTimeTToMicrosecondsOffset; |
208 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 216 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
209 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 217 result.tv_usec = us % Time::kMicrosecondsPerSecond; |
210 return result; | 218 return result; |
211 } | 219 } |
212 | 220 |
213 } // namespace base | 221 } // namespace base |
OLD | NEW |