From: Rafael Garcia-Suarez Date: Thu, 8 Apr 2004 09:59:22 +0000 (+0000) Subject: Upgrade to Time::HiRes 1.57. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c1dc6e7c2abc83afe1699df9920e363a653f04ef;p=p5sagit%2Fp5-mst-13.2.git Upgrade to Time::HiRes 1.57. p4raw-id: //depot/perl@22673 --- diff --git a/ext/Time/HiRes/Changes b/ext/Time/HiRes/Changes index 7db2cf3..33194b7 100644 --- a/ext/Time/HiRes/Changes +++ b/ext/Time/HiRes/Changes @@ -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, diff --git a/ext/Time/HiRes/HiRes.pm b/ext/Time/HiRes/HiRes.pm index 574dfd4..b6c8747 100644 --- a/ext/Time/HiRes/HiRes.pm +++ b/ext/Time/HiRes/HiRes.pm @@ -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; diff --git a/ext/Time/HiRes/HiRes.xs b/ext/Time/HiRes/HiRes.xs index afde108..fb516cd 100644 --- a/ext/Time/HiRes/HiRes.xs +++ b/ext/Time/HiRes/HiRes.xs @@ -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);