Skip to content
Snippets Groups Projects
Commit e684d88a authored by Takuya ASADA's avatar Takuya ASADA Committed by Avi Kivity
Browse files

clock: Add fill_tv(), duration to timeval conversion function

parent c8845bb5
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@
#include <drivers/clock.hh>
#include <chrono>
#include <sys/time.h>
namespace osv {
/**
......@@ -172,4 +173,16 @@ inline bool operator>(std::chrono::duration<Rep, Period> d, std::nullptr_t)
return d.count() > 0;
}
// Convenient inline function for converting std::chrono::duration,
// of a clock with any period, into the classic Posix "struct timeval":
template <class Rep, class Period>
static inline void fill_tv(std::chrono::duration<Rep, Period> d, timeval *tv)
{
using namespace std::chrono;
auto sec = duration_cast<seconds>(d);
auto usec = duration_cast<microseconds>(d - sec);
tv->tv_sec = sec.count();
tv->tv_usec = usec.count();
}
#endif /* OSV_CLOCK_HH_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment