OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 #if defined(TARGET_OS_WINDOWS) | 6 #if defined(TARGET_OS_WINDOWS) |
7 | 7 |
8 #include <errno.h> // NOLINT | 8 #include <errno.h> // NOLINT |
9 #include <time.h> // NOLINT | 9 #include <time.h> // NOLINT |
10 | 10 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 unicode_argc = argc; | 161 unicode_argc = argc; |
162 } | 162 } |
163 for (int i = 0; i < unicode_argc; i++) { | 163 for (int i = 0; i < unicode_argc; i++) { |
164 wchar_t* arg = unicode_argv[i]; | 164 wchar_t* arg = unicode_argv[i]; |
165 argv[i] = StringUtilsWin::WideToUtf8(arg); | 165 argv[i] = StringUtilsWin::WideToUtf8(arg); |
166 } | 166 } |
167 LocalFree(unicode_argv); | 167 LocalFree(unicode_argv); |
168 return true; | 168 return true; |
169 } | 169 } |
170 | 170 |
171 int64_t TimerUtils::GetCurrentTimeMilliseconds() { | 171 int64_t TimerUtils::GetCurrentMonotonicMillis() { |
172 return GetCurrentTimeMicros() / 1000; | 172 return GetCurrentMonotonicMicros() / 1000; |
173 } | 173 } |
174 | 174 |
175 int64_t TimerUtils::GetCurrentTimeMicros() { | 175 static int64_t qpc_ticks_per_second = 0; |
176 static const int64_t kTimeEpoc = 116444736000000000LL; | |
177 static const int64_t kTimeScaler = 10; // 100 ns to us. | |
178 | 176 |
179 // Although win32 uses 64-bit integers for representing timestamps, | 177 int64_t TimerUtils::GetCurrentMonotonicMicros() { |
180 // these are packed into a FILETIME structure. The FILETIME | 178 if (qpc_ticks_per_second == 0) { |
181 // structure is just a struct representing a 64-bit integer. The | 179 // QueryPerformanceCounter not supported, fallback. |
182 // TimeStamp union allows access to both a FILETIME and an integer | 180 return GetCurrentTimeMicros(); |
183 // representation of the timestamp. The Windows timestamp is in | 181 } |
184 // 100-nanosecond intervals since January 1, 1601. | 182 // Grab performance counter value. |
185 union TimeStamp { | 183 LARGE_INTEGER now; |
186 FILETIME ft_; | 184 QueryPerformanceCounter(&now); |
187 int64_t t_; | 185 int64_t qpc_value = static_cast<int64_t>(now.QuadPart); |
188 }; | 186 // Convert to microseconds. |
189 TimeStamp time; | 187 int64_t seconds = qpc_value / qpc_ticks_per_second; |
190 GetSystemTimeAsFileTime(&time.ft_); | 188 int64_t leftover_ticks = qpc_value - (seconds * qpc_ticks_per_second); |
191 return (time.t_ - kTimeEpoc) / kTimeScaler; | 189 int64_t result = seconds * kMicrosecondsPerSecond; |
| 190 result += ((leftover_ticks * kMicrosecondsPerSecond) / qpc_ticks_per_second); |
| 191 return result; |
| 192 } |
| 193 |
| 194 |
| 195 void* OS::AlignedAllocate(intptr_t size, intptr_t alignment) { |
| 196 const int kMinimumAlignment = 16; |
| 197 ASSERT(Utils::IsPowerOfTwo(alignment)); |
| 198 ASSERT(alignment >= kMinimumAlignment); |
| 199 void* p = _aligned_malloc(size, alignment); |
| 200 if (p == NULL) { |
| 201 UNREACHABLE(); |
| 202 } |
| 203 return p; |
192 } | 204 } |
193 | 205 |
194 void TimerUtils::Sleep(int64_t millis) { | 206 void TimerUtils::Sleep(int64_t millis) { |
195 ::Sleep(millis); | 207 ::Sleep(millis); |
196 } | 208 } |
197 | 209 |
198 } // namespace bin | 210 } // namespace bin |
199 } // namespace dart | 211 } // namespace dart |
200 | 212 |
201 #endif // defined(TARGET_OS_WINDOWS) | 213 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |