From 4a54265e840f3cfa8a50143d093c69bba3c8defc Mon Sep 17 00:00:00 2001 From: Jeff Hill Date: Tue, 25 Jun 2002 15:08:59 +0000 Subject: [PATCH] check for overflow condition when adjusting time estimate --- src/libCom/osi/os/WIN32/osdTime.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/libCom/osi/os/WIN32/osdTime.cpp b/src/libCom/osi/os/WIN32/osdTime.cpp index 81ea9a9dd..ec444c04c 100644 --- a/src/libCom/osi/os/WIN32/osdTime.cpp +++ b/src/libCom/osi/os/WIN32/osdTime.cpp @@ -288,7 +288,8 @@ currentTime::currentTime () : } else { errlogPrintf ( - "win32 osdTime.cpp detected questionable system date prior to EPICS epoch\n" ); + "win32 osdTime.cpp detected questionable " + "system date prior to EPICS epoch\n" ); this->epicsTimeLast = 0; } @@ -340,11 +341,23 @@ void currentTime::getCurrentTime ( epicsTimeStamp & dest ) offset = ( MAXLONGLONG - this->lastPerfCounter ) + ( curPerfCounter.QuadPart + MAXLONGLONG ); } - offset *= EPICS_TIME_TICKS_PER_SEC; - offset /= this->perfCounterFreq; + if ( offset < MAXLONGLONG / EPICS_TIME_TICKS_PER_SEC ) { + offset *= EPICS_TIME_TICKS_PER_SEC; + offset /= this->perfCounterFreq; + } + else { + double fpOffset = static_cast < double > ( offset ); + fpOffset *= EPICS_TIME_TICKS_PER_SEC; + fpOffset /= static_cast < double > ( this->perfCounterFreq ); + offset = static_cast < LONGLONG > ( fpOffset ); + } LONGLONG epicsTimeCurrent = this->epicsTimeLast + offset; if ( this->epicsTimeLast > epicsTimeCurrent ) { - errlogPrintf ( "currentTime::getCurrentTime(): time discontinuity detected\n" ); + double diff = this->epicsTimeLast - epicsTimeCurrent; + errlogPrintf ( + "currentTime::getCurrentTime(): %f sec " + "time discontinuity detected\n", + diff ); } this->epicsTimeLast = epicsTimeCurrent; this->lastPerfCounter = curPerfCounter.QuadPart; @@ -489,7 +502,7 @@ epicsTimerNotify::expireStatus currentTime::expire ( const epicsTime & ) // is to just assume the new time base this->epicsTimeLast = epicsTimeFromCurrentFileTime; this->perfCounterFreq = this->perfCounterFreqPLL; - debugPrintf ( ( "currentTime: time discontinuity detected\n" ) ); + debugPrintf ( ( "currentTime: did someone adjust the date?\n" ) ); } else { // update the effective performance counter frequency that will bring