OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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) | 16 #if defined(OS_ANDROID) |
17 #include "base/os_compat_android.h" | 17 #include "base/os_compat_android.h" |
18 #elif defined(OS_NACL) | 18 #elif defined(OS_NACL) |
19 #include "base/os_compat_nacl.h" | 19 #include "base/os_compat_nacl.h" |
20 #endif | 20 #endif |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 | 23 |
24 #if defined(OS_ANDROID) | 24 #if defined(OS_ANDROID) |
25 #define _POSIX_MONOTONIC_CLOCK 1 | 25 #define _POSIX_MONOTONIC_CLOCK 1 |
26 #endif | 26 #endif |
27 #if defined(OS_CHROMEOS) | |
28 // Force definition of the system trace clock; it is a chromeos-only api | |
29 // at the moment and surfacing it in the right place requires mucking | |
30 // with glibc et al. | |
31 #define CLOCK_SYSTEM_TRACE 11 | |
32 #endif | |
33 | 27 |
34 struct timespec TimeDelta::ToTimeSpec() const { | 28 struct timespec TimeDelta::ToTimeSpec() const { |
35 int64 microseconds = InMicroseconds(); | 29 int64 microseconds = InMicroseconds(); |
36 time_t seconds = 0; | 30 time_t seconds = 0; |
37 if (microseconds >= Time::kMicrosecondsPerSecond) { | 31 if (microseconds >= Time::kMicrosecondsPerSecond) { |
38 seconds = InSeconds(); | 32 seconds = InSeconds(); |
39 microseconds -= seconds * Time::kMicrosecondsPerSecond; | 33 microseconds -= seconds * Time::kMicrosecondsPerSecond; |
40 } | 34 } |
41 struct timespec result = | 35 struct timespec result = |
42 {seconds, | 36 {seconds, |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 | 260 |
267 struct timeval Time::ToTimeVal() const { | 261 struct timeval Time::ToTimeVal() const { |
268 struct timeval result; | 262 struct timeval result; |
269 int64 us = us_ - kTimeTToMicrosecondsOffset; | 263 int64 us = us_ - kTimeTToMicrosecondsOffset; |
270 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 264 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
271 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 265 result.tv_usec = us % Time::kMicrosecondsPerSecond; |
272 return result; | 266 return result; |
273 } | 267 } |
274 | 268 |
275 } // namespace base | 269 } // namespace base |
OLD | NEW |