From 786dfea3c881bb4807685637edf1925833614c02 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 16 Dec 2001 16:30:34 +0000 Subject: [PATCH] From John Davis, a little addition to the Windows version of the osg::Timer constructor such that a static variable is used to force the constructor to check the number of clock cycles per second once, this means that multiple timers can now be created with incurring a the 1 second delay used for timming the clock speed every time the constructor is called. --- src/osg/Timer.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/osg/Timer.cpp b/src/osg/Timer.cpp index 5a8bfb3b0..fa02575d5 100644 --- a/src/osg/Timer.cpp +++ b/src/osg/Timer.cpp @@ -29,11 +29,19 @@ using namespace osg; else { - Timer_t start_time = tick(); - Sleep (1000); - Timer_t end_time = tick(); + // use a static here to ensure that the Sleep(..) for 1 sec + // is not incurred more than once per app execution. + static double _tempSecsPerClick=0.0; + if (_tempSecsPerClick==0.0) + { + Timer_t start_time = tick(); + Sleep (1000); + Timer_t end_time = tick(); + + _tempSecsPerClick = 1.0/(double)(end_time-start_time); + } + _secsPerClick = _tempSecsPerClick; - _secsPerClick = 1.0/(double)(end_time-start_time); } } @@ -136,13 +144,9 @@ using namespace osg; Timer::Timer( void ) { - _useStandardClock = false; + _useStandardClock = false; // default to false. - if (_useStandardClock) - { - _secsPerClick = 1e-6; // gettimeofday()'s precision. - } - else + if (!_useStandardClock) { __psunsigned_t phys_addr, raddr; unsigned int cycleval; @@ -178,7 +182,20 @@ using namespace osg; _clockAddress = (unsigned long *)iotimer_addr; _secsPerClick = (double)(cycleval)* 1e-12; + + // this is to force the use of the standard clock in + // instances which the realtime clock is of such a small + // size that it will loop too rapidly for proper realtime work. + // this happens on the O2 for instance. + if (_cycleCntrSize<=32) _useStandardClock=true; + } + + if (_useStandardClock) + { + _secsPerClick = 1e-6; // gettimeofday()'s precision. + } + } #elif defined (__APPLE_CC__) || defined (macintosh)