2014-05-01 09:39:11 -04:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
2014-04-30 13:46:41 -04:00
|
|
|
#include "IncludeWindows.h"
|
|
|
|
#endif
|
2014-05-01 09:39:11 -04:00
|
|
|
#if defined(__linux__) || defined(__APPLE__)
|
2014-04-30 13:46:41 -04:00
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "UMicroseconds.h"
|
|
|
|
|
2015-10-04 15:11:15 -04:00
|
|
|
namespace wvNS {
|
2014-04-30 13:46:41 -04:00
|
|
|
UMicroseconds& UMicroseconds::ReadTime()
|
|
|
|
{
|
2014-05-16 12:19:41 -04:00
|
|
|
// Note: g_get_monotonic_time() may be a viable alternative
|
|
|
|
// (it is on Linux and OSX); if not, this code should really go into libpbd
|
2014-05-01 09:39:11 -04:00
|
|
|
#ifdef PLATFORM_WINDOWS
|
2014-04-30 13:46:41 -04:00
|
|
|
LARGE_INTEGER Frequency, Count ;
|
2014-04-29 16:05:54 -04:00
|
|
|
|
2014-04-30 13:46:41 -04:00
|
|
|
QueryPerformanceFrequency(&Frequency) ;
|
|
|
|
QueryPerformanceCounter(&Count);
|
|
|
|
theTime = uint64_t((Count.QuadPart * 1000000.0 / Frequency.QuadPart));
|
2014-04-29 16:05:54 -04:00
|
|
|
|
2014-05-16 12:19:41 -04:00
|
|
|
#elif defined __MACH__ // OSX, BSD..
|
|
|
|
|
|
|
|
clock_serv_t cclock;
|
|
|
|
mach_timespec_t mts;
|
|
|
|
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
|
|
|
|
clock_get_time(cclock, &mts);
|
|
|
|
mach_port_deallocate(mach_task_self(), cclock);
|
|
|
|
theTime = (uint64_t)mts.tv_sec * 1e6 + (uint64_t)mts.tv_nsec / 1000;
|
|
|
|
|
|
|
|
#else // Linux, POSIX
|
2014-04-29 16:05:54 -04:00
|
|
|
|
2014-05-16 12:19:41 -04:00
|
|
|
struct timespec *ts
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, ts);
|
|
|
|
theTime = (uint64_t)ts.tv_sec * 1e6 + (uint64_t)buf.tv_nsec / 1000;
|
2014-04-29 16:05:54 -04:00
|
|
|
|
2014-04-30 13:46:41 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
/*
|
2015-10-04 15:11:15 -04:00
|
|
|
Removed in favor of the posix implementation.
|
2014-05-01 09:39:11 -04:00
|
|
|
#ifdef __APPLE__
|
2014-04-30 13:46:41 -04:00
|
|
|
uint32_t UMicroseconds::hi() {return reinterpret_cast<UnsignedWide*>(&theTime)->hi;}
|
|
|
|
uint32_t UMicroseconds::lo() {return reinterpret_cast<UnsignedWide*>(&theTime)->lo;}
|
|
|
|
#endif
|
2014-04-29 16:30:56 -04:00
|
|
|
*/
|
2014-04-30 13:46:41 -04:00
|
|
|
void UMicrosecondsAccumulator::Start()
|
|
|
|
{
|
|
|
|
m_start_time.ReadTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UMicrosecondsAccumulator::Stop()
|
|
|
|
{
|
|
|
|
UMicroseconds stop_time;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-04-30 13:46:41 -04:00
|
|
|
m_accumulator += stop_time.GetNativeTime() - m_start_time.GetNativeTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UMicrosecondsAccumulator::Clear()
|
|
|
|
{
|
|
|
|
m_start_time = 0;
|
|
|
|
m_accumulator = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UMicroseconds UMicrosecondsAccumulator::GetAccumulatedTime() const
|
|
|
|
{
|
|
|
|
return m_accumulator;
|
|
|
|
}
|
|
|
|
|
|
|
|
UMicrosecondsAccumulator& UMicrosecondsAccumulator::operator+=(const UMicrosecondsAccumulator& inaccum_to_add)
|
|
|
|
{
|
|
|
|
m_accumulator += inaccum_to_add.GetAccumulatedTime();
|
|
|
|
return *this;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-10-04 15:11:15 -04:00
|
|
|
} // namespace wvNS {
|