#pragma once
#include <chrono>
#include <cmath>
#include <ctime>
namespace ableton
{
namespace platforms
{
#if defined(__FreeBSD_kernel__)
#define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC
#endif
namespace linux_
{
template <clockid_t CLOCK>
class Clock
{
public:
std::chrono::microseconds micros() const
{
::timespec ts;
::clock_gettime(CLOCK, &ts);
std::uint64_t ns = ts.tv_sec * 1000000000ULL + ts.tv_nsec;
return std::chrono::microseconds(ns / 1000ULL);
}
};
using ClockMonotonic = Clock<CLOCK_MONOTONIC>;
using ClockMonotonicRaw = Clock<CLOCK_MONOTONIC_RAW>;
} } }