Commit cb88701a authored by Daniel Friesel's avatar Daniel Friesel
Browse files

posix counter: switch to clock_monotonic

parent a1b9127d
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -9,13 +9,13 @@
#include <stdint.h>
#include <time.h>

typedef uint64_t counter_value_t;
typedef int64_t counter_value_t;
typedef uint8_t counter_overflow_t;

class Counter {
	private:
		Counter(const Counter &copy);
		uint64_t start_sec, start_nsec;
		int64_t start_sec, start_nsec;

	public:
		uint64_t value;
@@ -25,16 +25,16 @@ class Counter {

		inline void start() {
			struct timespec ts;
			clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
			clock_gettime(CLOCK_MONOTONIC, &ts);
			start_sec = ts.tv_sec;
			start_nsec = ts.tv_nsec;
		}

		inline void stop() {
			struct timespec ts;
			clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
			clock_gettime(CLOCK_MONOTONIC, &ts);

			value = (ts.tv_sec - start_sec) * 1000000000UL;
			value = (ts.tv_sec - start_sec) * 1000000000L;
			value += ts.tv_nsec - start_nsec;
		}
};