From 0c6991ea27fc98b21e58b1470c52f98a82dea2cd Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 8 Aug 2002 21:36:22 +0000 Subject: [PATCH] Fixes for IRIX 32bit timmer on O2. From Tom Jolley. --- include/osg/Timer | 33 ++++++++++++++++++++++----------- src/osg/Timer.cpp | 2 ++ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/include/osg/Timer b/include/osg/Timer index 4abaca747..a68f0fa3c 100644 --- a/include/osg/Timer +++ b/include/osg/Timer @@ -46,11 +46,11 @@ class SG_EXPORT Timer { ~Timer() {} #if defined __DARWIN_OSX__ || defined macintosh - // PJA MAC OSX - inline Tick() pollutes namespace so badly - // we cant compile, due to Carbon.h ... - Timer_t tick() const; + // PJA MAC OSX - inline Tick() pollutes namespace so badly + // we cant compile, due to Carbon.h ... + Timer_t tick() const; #else - inline Timer_t tick() const; + inline Timer_t tick() const; #endif inline double delta_s( Timer_t t1, Timer_t t2 ) const { return (double)(t2 - t1)*_secsPerClick; } @@ -60,13 +60,16 @@ class SG_EXPORT Timer { private : - double _secsPerClick; - bool _useStandardClock; + double _secsPerClick; + bool _useStandardClock; # ifdef __sgi - unsigned long* _clockAddress_32; - unsigned long long* _clockAddress_64; - int _cycleCntrSize; + unsigned long* _clockAddress_32; + unsigned long long* _clockAddress_64; + int _cycleCntrSize; + // for SGI machines with 32 bit clocks. + mutable unsigned long _lastClockValue; + mutable unsigned long long _rollOver; # endif }; @@ -154,7 +157,7 @@ class SG_EXPORT Timer { namespace osg{ - inline Timer_t Timer::tick() const + inline Timer_t Timer::tick() const { if (_useStandardClock) { @@ -167,7 +170,15 @@ class SG_EXPORT Timer { if ( _clockAddress_64 ) return *_clockAddress_64; else - return *_clockAddress_32; + { + unsigned long clockValue = *_clockAddress_32; + if( _lastClockValue > clockValue ) + { + _rollOver += 0x100000000L; + } + _lastClockValue = clockValue; + return _rollOver + clockValue; + } } } } diff --git a/src/osg/Timer.cpp b/src/osg/Timer.cpp index 2be509845..46e289a87 100644 --- a/src/osg/Timer.cpp +++ b/src/osg/Timer.cpp @@ -157,6 +157,8 @@ using namespace osg; _clockAddress_32 = 0; _clockAddress_64 = 0; + _rollOver = 0; + _lastClockValue = 0; if( (fd = open( "/dev/mmem", O_RDONLY )) < 0 ) {