summaryrefslogtreecommitdiff
path: root/src/utils/timer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/timer.cpp')
-rw-r--r--src/utils/timer.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/utils/timer.cpp b/src/utils/timer.cpp
index b0a05bc5..a1d8bd46 100644
--- a/src/utils/timer.cpp
+++ b/src/utils/timer.cpp
@@ -19,9 +19,15 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <time.h>
#include "timer.h"
+#include <time.h>
+#include <sys/time.h>
+
+#ifdef _WIN32
+#include "wingettimeofday.h"
+#endif
+
namespace utils
{
@@ -52,8 +58,18 @@ int Timer::poll()
int elapsed = 0;
if (active)
{
- elapsed = (getTimeInMillisec() - lastpulse) / interval;
- lastpulse += interval * elapsed;
+ uint64_t now = getTimeInMillisec();
+ if (now > lastpulse)
+ {
+ elapsed = (now - lastpulse) / interval;
+ lastpulse += interval * elapsed;
+ }
+ else
+ {
+ // Time has made a jump to the past. This should be a rare
+ // occurence, so just reset lastpulse to prevent problems.
+ lastpulse = now;
+ }
};
return elapsed;
}