posix_clock_get_time.cpp 803 B

12345678910111213141516171819202122232425262728293031
  1. //
  2. // $Id$
  3. //
  4. #include<__vic/posix/time.h>
  5. #include<__vic/throw_errno.h>
  6. namespace __vic { namespace posix {
  7. #if _POSIX_TIMERS > 0
  8. //----------------------------------------------------------------------------
  9. time_spec clock_base::get_time_(clockid_t id)
  10. {
  11. time_spec ts;
  12. if(::clock_gettime(id, &ts)) throw_errno("clock_gettime");
  13. return ts;
  14. }
  15. //----------------------------------------------------------------------------
  16. #else
  17. //----------------------------------------------------------------------------
  18. time_spec nanoseconds_since_epoch()
  19. {
  20. ::timeval tv;
  21. if(::gettimeofday(&tv, nullptr)) throw_errno("gettimeofday");
  22. return time_spec(tv.tv_sec, tv.tv_usec * 1000L);
  23. }
  24. //----------------------------------------------------------------------------
  25. #endif
  26. }} // namespace