| // Copyright 2017 The Cobalt Authors. All Rights Reserved. |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #ifndef STARBOARD_SHARED_WIN32_TIME_UTILS_H_ |
| #define STARBOARD_SHARED_WIN32_TIME_UTILS_H_ |
| |
| #include "starboard/common/log.h" |
| |
| namespace starboard { |
| namespace shared { |
| namespace win32 { |
| |
| inline int64_t ConvertFileTimeTicksToUsec(const LARGE_INTEGER ticks) { |
| // According to |
| // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284(v=vs.85).aspx |
| // FILETIME format is "Contains a 64-bit value representing the number of |
| // 100-nanosecond intervals since January 1, 1601 (UTC)" |
| const uint64_t kNumber100nanosecondTicksInMicrosecond = 10; |
| return ticks.QuadPart / kNumber100nanosecondTicksInMicrosecond; |
| } |
| |
| inline int64_t ConvertFileTimeToUsec(const FILETIME file_time) { |
| // According to |
| // https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284(v=vs.85).aspx |
| // FILETIME format is "Contains a 64-bit value representing the number of |
| // 100-nanosecond intervals since January 1, 1601 (UTC)" |
| LARGE_INTEGER ticks; |
| ticks.QuadPart = (static_cast<LONGLONG>(file_time.dwHighDateTime) << 32) | |
| file_time.dwLowDateTime; |
| return ConvertFileTimeTicksToUsec(ticks); |
| } |
| |
| // Many Win32 calls take millis, but Starboard uses microseconds. |
| // Many nplb tests assume waits are at least as long as requested, so |
| // round up. |
| inline DWORD ConvertUsecToMillisRoundUp(int64_t duration_usec) { |
| const int64_t milliseconds_to_sleep = (duration_usec + 1000 - 1) / 1000; |
| return static_cast<DWORD>(milliseconds_to_sleep); |
| } |
| |
| } // namespace win32 |
| } // namespace shared |
| } // namespace starboard |
| |
| #endif // STARBOARD_SHARED_WIN32_TIME_UTILS_H_ |