From 157f39d609ede8ad6136c09f6408dea8544a4913 Mon Sep 17 00:00:00 2001 From: schodet Date: Sun, 6 Mar 2005 14:30:19 +0000 Subject: Correction du problème d'overflow après 11 jours. --- 2005/i/robert/src/timer/test_timer.cc | 1 - 2005/i/robert/src/timer/timer.cc | 7 +++---- 2005/i/robert/src/timer/timer.hh | 5 +++-- 3 files changed, 6 insertions(+), 7 deletions(-) (limited to '2005/i/robert/src/timer') diff --git a/2005/i/robert/src/timer/test_timer.cc b/2005/i/robert/src/timer/test_timer.cc index 4a2296b..a2c9380 100644 --- a/2005/i/robert/src/timer/test_timer.cc +++ b/2005/i/robert/src/timer/test_timer.cc @@ -30,7 +30,6 @@ int main (void) { - sleep (2); cout << "timer 0 " << Timer::getProgramTime () << ' ' << Timer::getRoundTime () << endl; sleep (1); diff --git a/2005/i/robert/src/timer/timer.cc b/2005/i/robert/src/timer/timer.cc index 970a648..d70ee63 100644 --- a/2005/i/robert/src/timer/timer.cc +++ b/2005/i/robert/src/timer/timer.cc @@ -71,14 +71,13 @@ Timer::getInstance (void) } /// Retourne la date système. -int +long long Timer::getSystemTime (void) { timeval tv; gettimeofday (&tv, 0); - // Ça veut dire, un bug tous les 11 jours... - // XXX Attention, si le robot est à l'heure, on peut mal tomber. - return (tv.tv_sec % 1000000) * 1000 + tv.tv_usec / 1000; + return ((long long) tv.tv_sec % 1000000) * 1000 + + (long long) tv.tv_usec / 1000; } /// Constructeur. diff --git a/2005/i/robert/src/timer/timer.hh b/2005/i/robert/src/timer/timer.hh index 4c41b0e..23f2ea7 100644 --- a/2005/i/robert/src/timer/timer.hh +++ b/2005/i/robert/src/timer/timer.hh @@ -25,9 +25,10 @@ // // }}} +/// Classe de chronométrage. class Timer { - int programStart_, roundStart_; + long long programStart_, roundStart_; public: /// Retourne le temps depuis le début du programme en millisecondes. static int getProgramTime (void); @@ -42,7 +43,7 @@ class Timer /// Retourne une référence vers l'instance unique. static Timer &getInstance (void); /// Retourne la date système. - static int getSystemTime (void); + static long long getSystemTime (void); /// Constructeur. Timer (void); }; -- cgit v1.2.3