crl_winapi_time.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #include <crl/crl_time.h>
  8. #ifdef CRL_USE_WINAPI_TIME
  9. #include <crl/winapi/crl_winapi_windows_h.h>
  10. namespace crl::details {
  11. namespace {
  12. double Frequency/* = 0.*/;
  13. double ProfileFrequency/* = 0.*/;
  14. } // namespace
  15. void init() {
  16. LARGE_INTEGER value;
  17. QueryPerformanceFrequency(&value);
  18. Frequency = 1000. / double(value.QuadPart);
  19. ProfileFrequency = 1000000. / double(value.QuadPart);
  20. }
  21. inner_time_type current_value() {
  22. LARGE_INTEGER value;
  23. QueryPerformanceCounter(&value);
  24. return value.QuadPart;
  25. }
  26. time convert(inner_time_type value) {
  27. return time(value * Frequency);
  28. }
  29. inner_profile_type current_profile_value() {
  30. LARGE_INTEGER value;
  31. QueryPerformanceCounter(&value);
  32. return value.QuadPart;
  33. }
  34. profile_time convert_profile(inner_profile_type value) {
  35. return profile_time(value * ProfileFrequency);
  36. }
  37. } // namespace crl::details
  38. #endif // CRL_USE_WINAPI_TIME