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 |
| 11 #include "bin/log.h" |
11 #include "bin/utils.h" | 12 #include "bin/utils.h" |
12 #include "bin/utils_win.h" | 13 #include "bin/utils_win.h" |
13 #include "bin/log.h" | |
14 #include "platform/assert.h" | 14 #include "platform/assert.h" |
15 | 15 |
16 | |
17 namespace dart { | 16 namespace dart { |
18 namespace bin { | 17 namespace bin { |
19 | 18 |
20 void FormatMessageIntoBuffer(DWORD code, wchar_t* buffer, int buffer_length) { | 19 void FormatMessageIntoBuffer(DWORD code, wchar_t* buffer, int buffer_length) { |
21 DWORD message_size = | 20 DWORD message_size = |
22 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, | 21 FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, |
23 NULL, | 22 NULL, |
24 code, | 23 code, |
25 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), | 24 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
26 buffer, | 25 buffer, |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 WideCharToMultiByte(CP_UTF8, 0, arg, -1, NULL, 0, NULL, NULL); | 177 WideCharToMultiByte(CP_UTF8, 0, arg, -1, NULL, 0, NULL, NULL); |
179 char* utf8_arg = reinterpret_cast<char*>(malloc(arg_len)); | 178 char* utf8_arg = reinterpret_cast<char*>(malloc(arg_len)); |
180 WideCharToMultiByte(CP_UTF8, 0, arg, -1, utf8_arg, arg_len, NULL, NULL); | 179 WideCharToMultiByte(CP_UTF8, 0, arg, -1, utf8_arg, arg_len, NULL, NULL); |
181 argv[i] = utf8_arg; | 180 argv[i] = utf8_arg; |
182 } | 181 } |
183 LocalFree(unicode_argv); | 182 LocalFree(unicode_argv); |
184 return true; | 183 return true; |
185 } | 184 } |
186 | 185 |
187 | 186 |
| 187 // Although win32 uses 64-bit integers for representing timestamps, |
| 188 // these are packed into a FILETIME structure. The FILETIME |
| 189 // structure is just a struct representing a 64-bit integer. The |
| 190 // TimeStamp union allows access to both a FILETIME and an integer |
| 191 // representation of the timestamp. The Windows timestamp is in |
| 192 // 100-nanosecond intervals since January 1, 1601. |
| 193 union TimeStamp { |
| 194 FILETIME ft_; |
| 195 int64_t t_; |
| 196 }; |
| 197 |
| 198 |
188 static int64_t GetCurrentTimeMicros() { | 199 static int64_t GetCurrentTimeMicros() { |
189 static const int64_t kTimeEpoc = 116444736000000000LL; | 200 static const int64_t kTimeEpoc = 116444736000000000LL; |
190 static const int64_t kTimeScaler = 10; // 100 ns to us. | 201 static const int64_t kTimeScaler = 10; // 100 ns to us. |
191 | 202 |
192 // Although win32 uses 64-bit integers for representing timestamps, | |
193 // these are packed into a FILETIME structure. The FILETIME | |
194 // structure is just a struct representing a 64-bit integer. The | |
195 // TimeStamp union allows access to both a FILETIME and an integer | |
196 // representation of the timestamp. The Windows timestamp is in | |
197 // 100-nanosecond intervals since January 1, 1601. | |
198 union TimeStamp { | |
199 FILETIME ft_; | |
200 int64_t t_; | |
201 }; | |
202 TimeStamp time; | 203 TimeStamp time; |
203 GetSystemTimeAsFileTime(&time.ft_); | 204 GetSystemTimeAsFileTime(&time.ft_); |
204 return (time.t_ - kTimeEpoc) / kTimeScaler; | 205 return (time.t_ - kTimeEpoc) / kTimeScaler; |
205 } | 206 } |
206 | 207 |
207 | 208 |
208 static int64_t qpc_ticks_per_second = 0; | 209 static int64_t qpc_ticks_per_second = 0; |
209 | 210 |
210 void TimerUtils::InitOnce() { | 211 void TimerUtils::InitOnce() { |
211 LARGE_INTEGER ticks_per_sec; | 212 LARGE_INTEGER ticks_per_sec; |
(...skipping 29 matching lines...) Expand all Loading... |
241 | 242 |
242 | 243 |
243 void TimerUtils::Sleep(int64_t millis) { | 244 void TimerUtils::Sleep(int64_t millis) { |
244 ::Sleep(millis); | 245 ::Sleep(millis); |
245 } | 246 } |
246 | 247 |
247 } // namespace bin | 248 } // namespace bin |
248 } // namespace dart | 249 } // namespace dart |
249 | 250 |
250 #endif // defined(TARGET_OS_WINDOWS) | 251 #endif // defined(TARGET_OS_WINDOWS) |
OLD | NEW |