From 10965843da5d03f5b1151b89dc08d13223bcdc9c Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Sun, 24 Nov 2019 12:21:06 +0100 Subject: [PATCH] JKQTPHighResTimer now uses C++11 chrono lib as fallback --- lib/jkqtcommon/jkqtphighrestimer.cpp | 11 +++-------- lib/jkqtcommon/jkqtphighrestimer.h | 10 ++-------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/jkqtcommon/jkqtphighrestimer.cpp b/lib/jkqtcommon/jkqtphighrestimer.cpp index 3b78d4ced7..c18a489ba2 100644 --- a/lib/jkqtcommon/jkqtphighrestimer.cpp +++ b/lib/jkqtcommon/jkqtphighrestimer.cpp @@ -43,7 +43,7 @@ void JKQTPHighResTimer::start(){ freq=static_cast(fr.QuadPart); QueryPerformanceCounter(&last); #else - gettimeofday(&last,0); + last=std::chrono::system_clock::now(); #endif }; @@ -55,13 +55,8 @@ double JKQTPHighResTimer::getTime(){ QueryPerformanceCounter(&now); return (static_cast(now.QuadPart-last.QuadPart)/freq)*1e6; #else - struct timeval tv; - gettimeofday(&tv,0); - - int t1, t2; - t1 = last.tv_sec * 1000000 + last.tv_usec; - t2 = tv.tv_sec * 1000000 + tv.tv_usec; - return abs(t2 - t1); + auto no=std::chrono::system_clock::now(); + return std::chrono::duration_cast(no-last).count(); #endif diff --git a/lib/jkqtcommon/jkqtphighrestimer.h b/lib/jkqtcommon/jkqtphighrestimer.h index 1d16b60c92..0f3607749d 100644 --- a/lib/jkqtcommon/jkqtphighrestimer.h +++ b/lib/jkqtcommon/jkqtphighrestimer.h @@ -22,6 +22,7 @@ #include #include #include +#include #include "jkqtcommon_imexport.h" @@ -37,18 +38,11 @@ # endif #endif -#ifndef __WINDOWS__ -# ifndef __LINUX__ -# warning("these methods are ment to be used under windows or linux ... no other system were tested") -# endif -#endif - #if defined(__WINDOWS__) #include #elif defined(__LINUX__) #include #else - #warning("your operating system is not supported: you will have to implement this on your systems") #include #endif @@ -133,7 +127,7 @@ class JKQTCOMMON_LIB_EXPORT JKQTPHighResTimer { /** \brief internal: time stamp of the last call of start() */ LARGE_INTEGER last; #else - struct timeval last; + std::chrono::system_clock::timepoint last; #endif /** \brief internal: timer frequency */ double freq;