Diff
Not logged in

Differences From Artifact [3f1a769a85]:

To Artifact [f4d299b4b9]:


277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
277
278
279
280
281
282
283


284
285
286
287
288
289
290







-
-








static void
NativeGetTime(
    Tcl_Time *timePtr,
    ClientData clientData)
{
    struct _timeb t;
    int useFtime = 1;		/* Flag == TRUE if we need to fall back on
				 * ftime rather than using the perf counter. */

    /*
     * Initialize static storage on the first trip through.
     *
     * Note: Outer check for 'initialized' is a performance win since it
     * avoids an extra mutex lock in the common case.
     */
394
395
396
397
398
399
400




401
402
403
404
405
406
407
408
409
410
411
412
413





414
415



416













417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433







434
435
436
437
438

439
440

441
442

443
444
445
446
447



448
449
450
451



452
453
454
455
456
457
458
459
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425

426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449






450
451
452
453
454
455
456

457
458
459

460
461

462


463





464
465
466
467



468
469
470

471
472
473
474
475
476
477







+
+
+
+













+
+
+
+
+


+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+











-
-
-
-
-
-
+
+
+
+
+
+
+
-



-
+

-
+
-
-
+
-
-
-
-
-
+
+
+

-
-
-
+
+
+
-








    if (timeInfo.perfCounterAvailable && timeInfo.curCounterFreq.QuadPart!=0) {
	/*
	 * Query the performance counter and use it to calculate the current
	 * time.
	 */

	ULARGE_INTEGER fileTimeLastCall;
	LARGE_INTEGER perfCounterLastCall, curCounterFreq;
				/* Copy with current data of calibration cycle */

	LARGE_INTEGER curCounter;
				/* Current performance counter. */
	Tcl_WideInt curFileTime;/* Current estimated time, expressed as 100-ns
				 * ticks since the Windows epoch. */
	static LARGE_INTEGER posixEpoch;
				/* Posix epoch expressed as 100-ns ticks since
				 * the windows epoch. */
	Tcl_WideInt usecSincePosixEpoch;
				/* Current microseconds since Posix epoch. */

	posixEpoch.LowPart = 0xD53E8000;
	posixEpoch.HighPart = 0x019DB1DE;

	QueryPerformanceCounter(&curCounter);

	/*
	 * Hold time section locked as short as possible
	 */
	EnterCriticalSection(&timeInfo.cs);

	fileTimeLastCall.QuadPart = timeInfo.fileTimeLastCall.QuadPart;
	perfCounterLastCall.QuadPart = timeInfo.perfCounterLastCall.QuadPart;
	curCounterFreq.QuadPart = timeInfo.curCounterFreq.QuadPart;
	QueryPerformanceCounter(&curCounter);

	LeaveCriticalSection(&timeInfo.cs);

	/*
	 * If calibration cycle occurred after we get curCounter
	 */
	if (curCounter.QuadPart <= perfCounterLastCall.QuadPart) {
	    usecSincePosixEpoch =
		(fileTimeLastCall.QuadPart - posixEpoch.QuadPart) / 10;
	    timePtr->sec = (long) (usecSincePosixEpoch / 1000000);
	    timePtr->usec = (unsigned long) (usecSincePosixEpoch % 1000000);
	    return;
	}

	/*
	 * If it appears to be more than 1.1 seconds since the last trip
	 * through the calibration loop, the performance counter may have
	 * jumped forward. (See MSDN Knowledge Base article Q274323 for a
	 * description of the hardware problem that makes this test
	 * necessary.) If the counter jumps, we don't want to use it directly.
	 * Instead, we must return system time. Eventually, the calibration
	 * loop should recover.
	 */

	if (curCounter.QuadPart - timeInfo.perfCounterLastCall.QuadPart <
		11 * timeInfo.curCounterFreq.QuadPart / 10) {
	    curFileTime = timeInfo.fileTimeLastCall.QuadPart +
		 ((curCounter.QuadPart - timeInfo.perfCounterLastCall.QuadPart)
		    * 10000000 / timeInfo.curCounterFreq.QuadPart);
	    timeInfo.fileTimeLastCall.QuadPart = curFileTime;
	if (curCounter.QuadPart - perfCounterLastCall.QuadPart <
		11 * curCounterFreq.QuadPart / 10
	) {
	    curFileTime = fileTimeLastCall.QuadPart +
		 ((curCounter.QuadPart - perfCounterLastCall.QuadPart)
		    * 10000000 / curCounterFreq.QuadPart);

	    timeInfo.perfCounterLastCall.QuadPart = curCounter.QuadPart;
	    usecSincePosixEpoch = (curFileTime - posixEpoch.QuadPart) / 10;
	    timePtr->sec = (long) (usecSincePosixEpoch / 1000000);
	    timePtr->usec = (unsigned long) (usecSincePosixEpoch % 1000000);
	    useFtime = 0;
	    return;
	}

    }
	LeaveCriticalSection(&timeInfo.cs);
    }


    if (useFtime) {
	/*
	 * High resolution timer is not available. Just use ftime.
	 */
    /*
     * High resolution timer is not available. Just use ftime.
     */

	_ftime(&t);
	timePtr->sec = (long)t.time;
	timePtr->usec = t.millitm * 1000;
    _ftime(&t);
    timePtr->sec = (long)t.time;
    timePtr->usec = t.millitm * 1000;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * StopCalibration --
 *