diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-12-13 14:24:34 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-12-13 14:24:34 +0100 |
commit | 566e698caf23dc034335cfbb05641726ec4c273b (patch) | |
tree | 62d60388c11a76ccd18f2d71b742caedcebab732 /include/arch | |
parent | ebd3e2890cad3fbc9b0293b91173995d191ee804 (diff) |
add fake counter driver for arch=posix
Diffstat (limited to 'include/arch')
-rw-r--r-- | include/arch/posix/driver/counter.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/include/arch/posix/driver/counter.h b/include/arch/posix/driver/counter.h new file mode 100644 index 0000000..6390d14 --- /dev/null +++ b/include/arch/posix/driver/counter.h @@ -0,0 +1,31 @@ +#include <stdint.h> +#include <time.h> + +class Counter { + private: + Counter(const Counter ©); + uint64_t start_sec, start_nsec; + + public: + uint64_t value; + volatile uint8_t overflowed; + + Counter() : overflowed(0) {} + + inline void start() { + struct timespec ts; + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); + start_sec = ts.tv_sec; + start_nsec = ts.tv_nsec; + } + + inline void stop() { + struct timespec ts; + clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts); + + value = (ts.tv_sec - start_sec) * 1000000000UL; + value += ts.tv_nsec - start_nsec; + } +}; + +extern Counter counter; |