Upgrade to Time::HiRes 1.57.
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Thu, 8 Apr 2004 09:59:22 +0000 (09:59 +0000)
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>
Thu, 8 Apr 2004 09:59:22 +0000 (09:59 +0000)
p4raw-id: //depot/perl@22673

ext/Time/HiRes/Changes
ext/Time/HiRes/HiRes.pm
ext/Time/HiRes/HiRes.xs

index 7db2cf3..33194b7 100644 (file)
@@ -1,5 +1,11 @@
 Revision history for Perl extension Time::HiRes.
 
+1.57
+       - Window/Cygwin: if the performance counter drifts by more than
+         two seconds from the system clock (due to ntp adjustments,
+         for example), recalibrate our internal counter: from Jan Dubois,
+         based on [cpan #5933] by Jerry D. Hedden.
+
 1.56
        - Give a clearer message if the tests timeout (perl change #22253)
        - Don't use /tmp or its moral equivalents (perl bug #15036,
index 574dfd4..b6c8747 100644 (file)
@@ -15,7 +15,7 @@ require DynaLoader;
                 d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer
                 d_nanosleep);
        
-$VERSION = '1.56';
+$VERSION = '1.57';
 $XS_VERSION = $VERSION;
 $VERSION = eval $VERSION;
 
index afde108..fb516cd 100644 (file)
@@ -181,6 +181,12 @@ START_MY_CXT
 #undef gettimeofday
 #define gettimeofday(tp, not_used) _gettimeofday(aTHX_ tp, not_used)
 
+/* If the performance counter delta drifts more than 2 seconds from the
+ * system time then we recalibrate to system time.  This means we may
+ * move *backwards* in time! */
+
+#define MAX_DIFF Const64(20000000)
+
 static int
 _gettimeofday(pTHX_ struct timeval *tp, void *not_used)
 {
@@ -190,11 +196,19 @@ _gettimeofday(pTHX_ struct timeval *tp, void *not_used)
     FT_t ft;
 
     if (MY_CXT.run_count++) {
+       __int64 diff;
+       FT_t filtim;
+       GetSystemTimeAsFileTime(&filtim.ft_val);
         QueryPerformanceCounter((LARGE_INTEGER*)&ticks);
         ticks -= MY_CXT.base_ticks;
         ft.ft_i64 = MY_CXT.base_systime_as_filetime.ft_i64
                     + Const64(10000000) * (ticks / MY_CXT.tick_frequency)
                     +(Const64(10000000) * (ticks % MY_CXT.tick_frequency)) / MY_CXT.tick_frequency;
+       diff = ft.ft_i64 - MY_CXT.base_systime_as_filetime.ft_i64;
+       if (diff < -MAX_DIFF || diff > MAX_DIFF) {
+            MY_CXT.base_ticks = ticks;
+            ft.ft_i64 = filtim.ft_i64;
+       }
     }
     else {
         QueryPerformanceFrequency((LARGE_INTEGER*)&MY_CXT.tick_frequency);