OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 exploded->month = timestruct.tm_mon + 1; | 136 exploded->month = timestruct.tm_mon + 1; |
137 exploded->day_of_week = timestruct.tm_wday; | 137 exploded->day_of_week = timestruct.tm_wday; |
138 exploded->day_of_month = timestruct.tm_mday; | 138 exploded->day_of_month = timestruct.tm_mday; |
139 exploded->hour = timestruct.tm_hour; | 139 exploded->hour = timestruct.tm_hour; |
140 exploded->minute = timestruct.tm_min; | 140 exploded->minute = timestruct.tm_min; |
141 exploded->second = timestruct.tm_sec; | 141 exploded->second = timestruct.tm_sec; |
142 exploded->millisecond = milliseconds % kMillisecondsPerSecond; | 142 exploded->millisecond = milliseconds % kMillisecondsPerSecond; |
143 } | 143 } |
144 | 144 |
145 // TimeTicks ------------------------------------------------------------------ | 145 // TimeTicks ------------------------------------------------------------------ |
146 | 146 // FreeBSD 6 has CLOCK_MONOLITHIC but defines _POSIX_MONOTONIC_CLOCK to -1. |
147 #if defined(OS_POSIX) && \ | 147 #if (defined(OS_POSIX) && \ |
148 defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 | 148 defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0) || \ |
| 149 defined(OS_FREEBSD) |
149 | 150 |
150 // static | 151 // static |
151 TimeTicks TimeTicks::Now() { | 152 TimeTicks TimeTicks::Now() { |
152 uint64_t absolute_micro; | 153 uint64_t absolute_micro; |
153 | 154 |
154 struct timespec ts; | 155 struct timespec ts; |
155 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { | 156 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) { |
156 NOTREACHED() << "clock_gettime(CLOCK_MONOTONIC) failed."; | 157 NOTREACHED() << "clock_gettime(CLOCK_MONOTONIC) failed."; |
157 return TimeTicks(); | 158 return TimeTicks(); |
158 } | 159 } |
159 | 160 |
160 absolute_micro = | 161 absolute_micro = |
161 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + | 162 (static_cast<int64>(ts.tv_sec) * Time::kMicrosecondsPerSecond) + |
162 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); | 163 (static_cast<int64>(ts.tv_nsec) / Time::kNanosecondsPerMicrosecond); |
163 | 164 |
164 return TimeTicks(absolute_micro); | 165 return TimeTicks(absolute_micro); |
165 } | 166 } |
166 | 167 |
167 #else // _POSIX_MONOTONIC_CLOCK | 168 #else // _POSIX_MONOTONIC_CLOCK |
168 #error No usable tick clock function on this platform. | 169 #error No usable tick clock function on this platform. |
169 #endif // _POSIX_MONOTONIC_CLOCK | 170 #endif // _POSIX_MONOTONIC_CLOCK |
170 | 171 |
171 // static | 172 // static |
172 TimeTicks TimeTicks::HighResNow() { | 173 TimeTicks TimeTicks::HighResNow() { |
173 return Now(); | 174 return Now(); |
174 } | 175 } |
175 | 176 |
176 } // namespace base | 177 } // namespace base |
OLD | NEW |