snapcast/common/timeDefs.h
(no author) a7118fd0a4 time stuff
git-svn-id: svn://elaine/murooma/trunk@301 d8a302eb-03bc-478d-80e4-98257eca68ef
2014-09-28 07:43:34 +00:00

49 lines
994 B
C++

#ifndef TIME_DEFS_H
#define TIME_DEFS_H
#include <chrono>
#include <sys/time.h>
namespace chronos
{
typedef std::chrono::high_resolution_clock hrc;
typedef std::chrono::time_point<hrc> time_point_hrc;
typedef std::chrono::seconds sec;
typedef std::chrono::milliseconds msec;
typedef std::chrono::microseconds usec;
typedef std::chrono::nanoseconds nsec;
static void addUs(timeval& tv, int us)
{
if (us < 0)
{
timeval t;
t.tv_sec = -us / 1000000;
t.tv_usec = (-us % 1000000);
timersub(&tv, &t, &tv);
return;
}
tv.tv_usec += us;
tv.tv_sec += (tv.tv_usec / 1000000);
tv.tv_usec %= 1000000;
}
static long getTickCount()
{
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
return now.tv_sec*1000 + now.tv_nsec / 1000000;
}
template <class Rep, class Period>
std::chrono::duration<Rep, Period> abs(std::chrono::duration<Rep, Period> d)
{
Rep x = d.count();
return std::chrono::duration<Rep, Period>(x >= 0 ? x : -x);
}
}
#endif