#include <algorithm>
#include <time.h>
+#include <unistd.h>
#include <sys/timeb.h>
+#include <sys/syscall.h>
#include <timefunc.hxx>
#include <i18n.h>
+
+// define missing POSIX.1b constants...
+
+#ifndef CLOCK_REALTIME
+#define CLOCK_REALTIME 0
+#endif
+#ifndef CLOCK_MONOTONIC
+#define CLOCK_MONOTONIC 1
+#endif
+
+
+
using namespace std;
double prec_time(void)
}
return *this;
} // eo operator-=(const Intervals&)
+
+
+
+/*
+** clock funcs:
+*/
+
+
+/**
+ * @brief fetches the value from the monotonic clock source.
+ * @param[out] seconds the seconds.
+ * @param[out] nano_seconds the nano seconds.
+ * @return @a true if the clock was successfully read.
+ */
+bool monotonic_clock_gettime(long int& seconds, long int& nano_seconds)
+{
+ struct timespec tp[1];
+ int res= ::syscall(__NR_clock_gettime, CLOCK_MONOTONIC, tp);
+ if (0 == res)
+ {
+ seconds= tp->tv_sec;
+ nano_seconds= tp->tv_nsec;
+ }
+ return (res==0);
+} // eo monotonic_clock_gettime(long int&,long int&)
+
+
+/**
+ * @brief fetches the value from the monotonic clock source.
+ * @param[out] seconds the seconds.
+ * @param[out] nano_seconds the nano seconds.
+ * @return @a true if the clock was successfully read.
+ */
+bool realtime_clock_gettime(long int& seconds, long int& nano_seconds)
+{
+ struct timespec tp[1];
+ int res= ::syscall(__NR_clock_gettime, CLOCK_REALTIME, tp);
+ if (0 == res)
+ {
+ seconds= tp->tv_sec;
+ nano_seconds= tp->tv_nsec;
+ }
+ return (res==0);
+} // eo realtime_clock_gettime(long int&,long int&)
+
+
#include <timefunc.hxx>
#include <filefunc.hxx>
+#include <unistd.h>
+
+
using namespace std;
using namespace I2n;
using namespace CppUnit;
CPPUNIT_TEST(IntervalComparisons);
+ CPPUNIT_TEST(MonotonicClock);
+
CPPUNIT_TEST_SUITE_END();
protected:
CPPUNIT_ASSERT_EQUAL( false, intervals2.contains( intervals1 ));
} // eo IntervalComparisons()
+
+
+ void MonotonicClock()
+ {
+ long sec0, nsec0;
+ long sec1, nsec1;
+
+ bool res = monotonic_clock_gettime(sec0,nsec0);
+ CPPUNIT_ASSERT_EQUAL( true, res );
+
+ usleep(250000);
+ res= monotonic_clock_gettime(sec1,nsec1);
+ CPPUNIT_ASSERT_EQUAL( true, res);
+
+ long delta_sec = sec1 - sec0;
+ long delta_nsec= nsec1 - nsec0;
+
+ long delta_millisec= ( delta_nsec / 1000000L) + delta_sec * 1000L;
+
+ CPPUNIT_ASSERT( delta_millisec >= 250 - /*fuzz*/ 1);
+ CPPUNIT_ASSERT( delta_millisec < 300 );
+ } // eo MonotonicClock()
+
+
}; // eo class TestTimeFunc