summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2022-08-09 11:41:13 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2022-08-09 11:41:13 +0200
commitcb88701a8c2f155a898fa1af637f9377c8db71d8 (patch)
tree79f38a8f8cff8d501068fb5f82b771eb9f87bc1e
parenta1b9127d160fb41b1e68892aa8daa68f69e96d90 (diff)
posix counter: switch to clock_monotonic
-rw-r--r--include/arch/posix/driver/counter.h10
1 files changed, 5 insertions, 5 deletions
diff --git a/include/arch/posix/driver/counter.h b/include/arch/posix/driver/counter.h
index e37bfd7..5d10500 100644
--- a/include/arch/posix/driver/counter.h
+++ b/include/arch/posix/driver/counter.h
@@ -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;
}
};