summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschodet2005-03-06 14:30:19 +0000
committerschodet2005-03-06 14:30:19 +0000
commit157f39d609ede8ad6136c09f6408dea8544a4913 (patch)
tree4a2a5682c0a795bad31dccd9da495bf6a7957b29
parent9765c8a6b33f01ca6386b87b903381536def331f (diff)
Correction du problème d'overflow après 11 jours.
-rw-r--r--2005/i/robert/src/timer/test_timer.cc1
-rw-r--r--2005/i/robert/src/timer/timer.cc7
-rw-r--r--2005/i/robert/src/timer/timer.hh5
3 files changed, 6 insertions, 7 deletions
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);
};