diff options
Diffstat (limited to 'include/arch/posix')
-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; |