OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 exploded->hour = timestruct.tm_hour; | 140 exploded->hour = timestruct.tm_hour; |
141 exploded->minute = timestruct.tm_min; | 141 exploded->minute = timestruct.tm_min; |
142 exploded->second = timestruct.tm_sec; | 142 exploded->second = timestruct.tm_sec; |
143 exploded->millisecond = milliseconds % kMillisecondsPerSecond; | 143 exploded->millisecond = milliseconds % kMillisecondsPerSecond; |
144 } | 144 } |
145 | 145 |
146 // TimeTicks ------------------------------------------------------------------ | 146 // TimeTicks ------------------------------------------------------------------ |
147 // FreeBSD 6 has CLOCK_MONOLITHIC but defines _POSIX_MONOTONIC_CLOCK to -1. | 147 // FreeBSD 6 has CLOCK_MONOLITHIC but defines _POSIX_MONOTONIC_CLOCK to -1. |
148 #if (defined(OS_POSIX) && \ | 148 #if (defined(OS_POSIX) && \ |
149 defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0) || \ | 149 defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0) || \ |
150 defined(OS_FREEBSD) | 150 defined(OS_FREEBSD) || defined(OS_OPENBSD) |
151 | 151 |
152 // static | 152 // static |
153 TimeTicks TimeTicks::Now() { | 153 TimeTicks TimeTicks::Now() { |
154 uint64_t absolute_micro; | 154 uint64_t absolute_micro; |
155 | 155 |
156 struct timespec ts; | 156 struct timespec ts; |
157 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { | 157 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { |
158 NOTREACHED() << "clock_gettime(CLOCK_MONOTONIC) failed."; | 158 NOTREACHED() << "clock_gettime(CLOCK_MONOTONIC) failed."; |
159 return TimeTicks(); | 159 return TimeTicks(); |
160 } | 160 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 192 |
193 struct timeval Time::ToTimeVal() const { | 193 struct timeval Time::ToTimeVal() const { |
194 struct timeval result; | 194 struct timeval result; |
195 int64 us = us_ - kTimeTToMicrosecondsOffset; | 195 int64 us = us_ - kTimeTToMicrosecondsOffset; |
196 result.tv_sec = us / Time::kMicrosecondsPerSecond; | 196 result.tv_sec = us / Time::kMicrosecondsPerSecond; |
197 result.tv_usec = us % Time::kMicrosecondsPerSecond; | 197 result.tv_usec = us % Time::kMicrosecondsPerSecond; |
198 return result; | 198 return result; |
199 } | 199 } |
200 | 200 |
201 } // namespace base | 201 } // namespace base |
OLD | NEW |