| 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/time.h" | 5 #include "base/time/time.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <sys/time.h> | 8 #include <sys/time.h> |
| 9 #include <time.h> | 9 #include <time.h> |
| 10 #if defined(OS_ANDROID) | 10 #if defined(OS_ANDROID) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 22 | 22 |
| 23 #if defined(OS_ANDROID) | 23 #if defined(OS_ANDROID) |
| 24 #include "base/os_compat_android.h" | 24 #include "base/os_compat_android.h" |
| 25 #elif defined(OS_NACL) | 25 #elif defined(OS_NACL) |
| 26 #include "base/os_compat_nacl.h" | 26 #include "base/os_compat_nacl.h" |
| 27 #endif | 27 #endif |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 #if !defined(OS_MACOSX) |
| 31 // Define a system-specific SysTime that wraps either to a time_t or | 32 // Define a system-specific SysTime that wraps either to a time_t or |
| 32 // a time64_t depending on the host system, and associated convertion. | 33 // a time64_t depending on the host system, and associated convertion. |
| 33 // See crbug.com/162007 | 34 // See crbug.com/162007 |
| 34 #if defined(OS_ANDROID) | 35 #if defined(OS_ANDROID) |
| 35 typedef time64_t SysTime; | 36 typedef time64_t SysTime; |
| 36 | 37 |
| 37 SysTime SysTimeFromTimeStruct(struct tm* timestruct, bool is_local) { | 38 SysTime SysTimeFromTimeStruct(struct tm* timestruct, bool is_local) { |
| 38 if (is_local) | 39 if (is_local) |
| 39 return mktime64(timestruct); | 40 return mktime64(timestruct); |
| 40 else | 41 else |
| (...skipping 18 matching lines...) Expand all Loading... |
| 59 } | 60 } |
| 60 | 61 |
| 61 void SysTimeToTimeStruct(SysTime t, struct tm* timestruct, bool is_local) { | 62 void SysTimeToTimeStruct(SysTime t, struct tm* timestruct, bool is_local) { |
| 62 if (is_local) | 63 if (is_local) |
| 63 localtime_r(&t, timestruct); | 64 localtime_r(&t, timestruct); |
| 64 else | 65 else |
| 65 gmtime_r(&t, timestruct); | 66 gmtime_r(&t, timestruct); |
| 66 } | 67 } |
| 67 #endif // OS_ANDROID | 68 #endif // OS_ANDROID |
| 68 | 69 |
| 69 #if !defined(OS_MACOSX) | |
| 70 // Helper function to get results from clock_gettime() as TimeTicks object. | 70 // Helper function to get results from clock_gettime() as TimeTicks object. |
| 71 // Minimum requirement is MONOTONIC_CLOCK to be supported on the system. | 71 // Minimum requirement is MONOTONIC_CLOCK to be supported on the system. |
| 72 // FreeBSD 6 has CLOCK_MONOTONIC but defines _POSIX_MONOTONIC_CLOCK to -1. | 72 // FreeBSD 6 has CLOCK_MONOTONIC but defines _POSIX_MONOTONIC_CLOCK to -1. |
| 73 #if (defined(OS_POSIX) && \ | 73 #if (defined(OS_POSIX) && \ |
| 74 defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0) || \ | 74 defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0) || \ |
| 75 defined(OS_BSD) || defined(OS_ANDROID) | 75 defined(OS_BSD) || defined(OS_ANDROID) |
| 76 base::TimeTicks ClockNow(clockid_t clk_id) { | 76 base::TimeTicks ClockNow(clockid_t clk_id) { |
| 77 uint64_t absolute_micro; | 77 uint64_t absolute_micro; |
| 78 | 78 |
| 79 struct timespec ts; | 79 struct timespec ts; |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; | 380 result.tv_usec = static_cast<suseconds_t>(Time::kMicrosecondsPerSecond) - 1; |
| 381 return result; | 381 return result; |
| 382 } | 382 } |
| 383 int64 us = us_ - kTimeTToMicrosecondsOffset; | 383 int64 us = us_ - kTimeTToMicrosecondsOffset; |
| 384 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 384 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
| 385 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 385 result.tv_usec = us % Time::kMicrosecondsPerSecond; |
| 386 return result; | 386 return result; |
| 387 } | 387 } |
| 388 | 388 |
| 389 } // namespace base | 389 } // namespace base |
| OLD | NEW |