unittest-cpp/UnitTest++/Posix/TimeHelpers.cpp
paul.bristow d288acf175 Add support for Cygwin
Add UNITTEST_CYGWIN directive and use it to:
include Posix/TimeHelpers.h for Cygwin,
exclude the signal handling in SignalTranslator.h/.cpp as Cygwin does not have
the necessary Posix signal handling support, i.e. sigjmp_buf or siglongjmp.

Reimplement SleepMs in TimeHelpers.cpp using C++11 rather than usleep as that
is not present on Cygwin.

Update CMakeLists.txt to exclude SignalTranslator.h/.cpp from the build.
2017-12-27 07:56:41 +00:00

35 lines
693 B
C++

#include "TimeHelpers.h"
#include <chrono>
#include <thread>
#include <unistd.h>
namespace UnitTest {
Timer::Timer()
{
m_startTime.tv_sec = 0;
m_startTime.tv_usec = 0;
}
void Timer::Start()
{
gettimeofday(&m_startTime, 0);
}
double Timer::GetTimeInMs() const
{
struct timeval currentTime;
gettimeofday(&currentTime, 0);
double const dsecs = currentTime.tv_sec - m_startTime.tv_sec;
double const dus = currentTime.tv_usec - m_startTime.tv_usec;
return (dsecs * 1000.0) + (dus / 1000.0);
}
void TimeHelpers::SleepMs(int ms)
{
std::this_thread::sleep_for(std::chrono::microseconds(ms * 1000));
}
}