From 82e973c044da9fffa2a08a78b038b424ebe27d6d Mon Sep 17 00:00:00 2001 From: Alexander Mueller <alexander.mueller@hs.uni-hamburg.de> Date: Wed, 31 Aug 2005 10:04:42 +0000 Subject: [PATCH] BugID: 310 After investigation of this problem it became clear that the seconds converted to usec will not fit in a "unsigned long". So this must be "unsigned long long". The second reason for the problem is the fact the the Timer class was not able to handle a negative timedelta. This can occur if the running NTP service corrects the system time with a time in the past. This is solved too. --- MAC/GCF/TM/src/Timer/GTM_Timer.cc | 25 ++++++++++++++----------- MAC/GCF/TM/src/Timer/GTM_Timer.h | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/MAC/GCF/TM/src/Timer/GTM_Timer.cc b/MAC/GCF/TM/src/Timer/GTM_Timer.cc index 89f009dd2cb..780d8b11778 100644 --- a/MAC/GCF/TM/src/Timer/GTM_Timer.cc +++ b/MAC/GCF/TM/src/Timer/GTM_Timer.cc @@ -1,3 +1,4 @@ + //# GTM_Timer.cc: one line description //# //# Copyright (C) 2002-2003 @@ -51,9 +52,9 @@ GTMTimer::GTMTimer(GCFRawPort& port, void GTMTimer::decreaseTime() { - unsigned long uSec = getElapsedTime(); + long uSec = getElapsedTime(); - if (_timeLeft > uSec) + if ((long)_timeLeft > uSec) { _timeLeft -= uSec; } @@ -76,9 +77,11 @@ void GTMTimer::decreaseTime() if (_intervalTime < timeoverflow) { LOG_ERROR(formatString( - "Timerinterval %fsec of timer %d is to small for performance reasons.", + "Timerinterval %fsec of timer %d is to small for performance reasons (tdelta: %ld, tleft: %lu).", ((double) _intervalTime) / 1000000.0, - _id)); + _id, + uSec, + _timeLeft)); do { timeoverflow -= _intervalTime; @@ -99,19 +102,19 @@ void GTMTimer::saveTime() gettimeofday(&_savedTime, &timeZone); } -unsigned long GTMTimer::getElapsedTime() +long GTMTimer::getElapsedTime() { timeval oldTime(_savedTime); - unsigned long uSecDiff(0); + long uSecDiff(0); saveTime(); - uSecDiff = ((unsigned long) (_savedTime.tv_usec) + - (unsigned long) (_savedTime.tv_sec) * 1000000) - - ((unsigned long) (oldTime.tv_usec) + - (unsigned long) (oldTime.tv_sec) * 1000000); + uSecDiff = ((unsigned long long) (_savedTime.tv_usec) + + (unsigned long long) (_savedTime.tv_sec) * 1000000) - + ((unsigned long long) (oldTime.tv_usec) + + (unsigned long long) (oldTime.tv_sec) * 1000000); - return uSecDiff; + return uSecDiff; } } // namespace TM } // namespace GCF diff --git a/MAC/GCF/TM/src/Timer/GTM_Timer.h b/MAC/GCF/TM/src/Timer/GTM_Timer.h index 6d8a0c0b719..0b6726e487d 100644 --- a/MAC/GCF/TM/src/Timer/GTM_Timer.h +++ b/MAC/GCF/TM/src/Timer/GTM_Timer.h @@ -67,7 +67,7 @@ class GTMTimer private: // helper methods void saveTime (); - unsigned long getElapsedTime(); + long getElapsedTime(); private: // attributes GCFRawPort& _port; -- GitLab