summaryrefslogtreecommitdiffstats
path: root/win/tclWinTime.c
diff options
context:
space:
mode:
Diffstat (limited to 'win/tclWinTime.c')
-rw-r--r--win/tclWinTime.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/win/tclWinTime.c b/win/tclWinTime.c
index 1204ec7..e4a6a8a 100644
--- a/win/tclWinTime.c
+++ b/win/tclWinTime.c
@@ -120,9 +120,10 @@ static TimeInfo timeInfo = {
*/
static struct {
int initialized; /* 1 if initialized, 0 otherwise */
- int perfCounter; /* 1 if performance counter usable for wide clicks */
+ int perfCounter; /* 1 if performance counter usable for wide
+ * clicks */
double microsecsScale; /* Denominator scale between clock / microsecs */
-} wideClick = {0, 0.0};
+} wideClick = {0, 0, 0.0};
/*
@@ -257,7 +258,7 @@ TclpGetWideClicks(void)
/*
* The frequency of the performance counter is fixed at system boot and
- * is consistent across all processors. Therefore, the frequency need
+ * is consistent across all processors. Therefore, the frequency need
* only be queried upon application initialization.
*/
if (QueryPerformanceFrequency(&perfCounterFreq)) {
@@ -268,7 +269,7 @@ TclpGetWideClicks(void)
wideClick.perfCounter = 0;
wideClick.microsecsScale = 1;
}
-
+
wideClick.initialized = 1;
}
if (wideClick.perfCounter) {
@@ -289,7 +290,7 @@ TclpGetWideClicks(void)
*
* TclpWideClickInMicrosec --
*
- * This procedure return scale to convert wide click values from the
+ * This procedure return scale to convert wide click values from the
* TclpGetWideClicks native resolution to microsecond resolution
* and back.
*
@@ -328,7 +329,7 @@ TclpWideClickInMicrosec(void)
*----------------------------------------------------------------------
*/
-Tcl_WideInt
+Tcl_WideInt
TclpGetMicroseconds(void)
{
Tcl_WideInt usecSincePosixEpoch;
@@ -476,7 +477,7 @@ NativeCalc100NsTicks(
LONGLONG curCounterFreq,
LONGLONG curCounter
) {
- return fileTimeLastCall +
+ return fileTimeLastCall +
((curCounter - perfCounterLastCall) * 10000000 / curCounterFreq);
}
@@ -493,7 +494,6 @@ NativeGetMicroseconds(void)
if (!timeInfo.initialized) {
TclpInitLock();
if (!timeInfo.initialized) {
-
timeInfo.posixEpoch.LowPart = 0xD53E8000;
timeInfo.posixEpoch.HighPart = 0x019DB1DE;
@@ -624,8 +624,12 @@ NativeGetMicroseconds(void)
/*
* If calibration cycle occurred after we get curCounter
*/
+
if (curCounter.QuadPart <= perfCounterLastCall) {
- /* Calibrated file-time is saved from posix in 100-ns ticks */
+ /*
+ * Calibrated file-time is saved from posix in 100-ns ticks
+ */
+
return fileTimeLastCall / 10;
}
@@ -1127,7 +1131,6 @@ CalibrationThread(
UpdateTimeEachSecond();
}
- /* lint */
return (DWORD) 0;
}
@@ -1158,7 +1161,8 @@ UpdateTimeEachSecond(void)
/* Current value returned from
* QueryPerformanceCounter. */
FILETIME curSysTime; /* Current system time. */
- static LARGE_INTEGER lastFileTime; /* File time of the previous calibration */
+ static LARGE_INTEGER lastFileTime;
+ /* File time of the previous calibration */
LARGE_INTEGER curFileTime; /* File time at the time this callback was
* scheduled. */
Tcl_WideInt estFreq; /* Estimated perf counter frequency. */
@@ -1186,7 +1190,7 @@ UpdateTimeEachSecond(void)
return;
}
QueryPerformanceCounter(&curPerfCounter);
-
+
lastFileTime.QuadPart = curFileTime.QuadPart;
/*
@@ -1254,7 +1258,7 @@ UpdateTimeEachSecond(void)
/* calculate new frequency and estimate drift to the next second */
vt1 = 20000000 + curFileTime.QuadPart;
driftFreq = (estFreq * 20000000 / (vt1 - vt0));
- /*
+ /*
* Avoid too large drifts (only half of the current difference),
* that allows also be more accurate (aspire to the smallest tdiff),
* so then we can prolong calibration interval by tdiff < 100000
@@ -1262,13 +1266,13 @@ UpdateTimeEachSecond(void)
driftFreq = timeInfo.curCounterFreq.QuadPart +
(driftFreq - timeInfo.curCounterFreq.QuadPart) / 2;
- /*
+ /*
* Average between estimated, 2 current and 5 drifted frequencies,
* (do the soft drifting as possible)
*/
estFreq = (estFreq + 2 * timeInfo.curCounterFreq.QuadPart + 5 * driftFreq) / 8;
}
-
+
/* Avoid too large discrepancy from nominal frequency */
if (estFreq > 1003*timeInfo.nominalFreq.QuadPart/1000) {
estFreq = 1003*timeInfo.nominalFreq.QuadPart/1000;
@@ -1277,9 +1281,9 @@ UpdateTimeEachSecond(void)
estFreq = 997*timeInfo.nominalFreq.QuadPart/1000;
vt0 = curFileTime.QuadPart;
} else if (vt0 != curFileTime.QuadPart) {
- /*
+ /*
* Be sure the clock ticks never backwards (avoid it by negative drifting)
- * just compare native time (in 100-ns) before and hereafter using
+ * just compare native time (in 100-ns) before and hereafter using
* new calibrated values) and do a small adjustment (short time freeze)
*/
LARGE_INTEGER newPerfCounter;