crl_linux_time.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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_LINUX_TIME
  9. #include <time.h>
  10. namespace crl::details {
  11. void init() {
  12. }
  13. inner_time_type current_value() {
  14. timespec ts;
  15. clock_gettime(CLOCK_MONOTONIC, &ts);
  16. const auto seconds = inner_time_type(ts.tv_sec);
  17. const auto milliseconds = inner_time_type(ts.tv_nsec) / 1000000;
  18. return seconds * 1000 + milliseconds;
  19. }
  20. time convert(inner_time_type value) {
  21. return time(value);
  22. }
  23. inner_profile_type current_profile_value() {
  24. timespec ts;
  25. clock_gettime(CLOCK_MONOTONIC, &ts);
  26. const auto seconds = inner_profile_type(ts.tv_sec);
  27. const auto milliseconds = inner_profile_type(ts.tv_nsec) / 1000;
  28. return seconds * 1000000 + milliseconds;
  29. }
  30. profile_time convert_profile(inner_profile_type value) {
  31. return profile_time(value);
  32. }
  33. } // namespace crl::details
  34. #endif // CRL_USE_LINUX_TIME