crl_mac_time.cpp 1018 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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_MAC_TIME
  9. #include <mach/mach_time.h>
  10. namespace crl::details {
  11. namespace {
  12. double Frequency/* = 0.*/;
  13. double ProfileFrequency/* = 0.*/;
  14. } // namespace
  15. void init() {
  16. mach_timebase_info_data_t tb = { 0, 0 };
  17. mach_timebase_info(&tb);
  18. Frequency = (double(tb.numer) / tb.denom) / 1000000.;
  19. ProfileFrequency = (double(tb.numer) / tb.denom) / 1000.;
  20. }
  21. inner_time_type current_value() {
  22. return mach_absolute_time();
  23. }
  24. time convert(inner_time_type value) {
  25. return time(value * Frequency);
  26. }
  27. inner_profile_type current_profile_value() {
  28. return mach_absolute_time();
  29. }
  30. profile_time convert_profile(inner_profile_type value) {
  31. return profile_time(value * ProfileFrequency);
  32. }
  33. } // namespace crl::details
  34. #endif // CRL_USE_MAC_TIME