summaryrefslogtreecommitdiffstats
path: root/win/tclWinTime.c
diff options
context:
space:
mode:
Diffstat (limited to 'win/tclWinTime.c')
-rw-r--r--win/tclWinTime.c255
1 files changed, 70 insertions, 185 deletions
diff --git a/win/tclWinTime.c b/win/tclWinTime.c
index fc91e2b..7045c72 100644
--- a/win/tclWinTime.c
+++ b/win/tclWinTime.c
@@ -1,4 +1,4 @@
-/*
+/*
* tclWinTime.c --
*
* Contains Windows specific versions of Tcl functions that obtain time
@@ -8,8 +8,6 @@
*
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
- *
- * RCS: @(#) $Id: tclWinTime.c,v 1.31 2005/07/24 22:56:51 dkf Exp $
*/
#include "tclInt.h"
@@ -29,11 +27,11 @@
* month, where index 1 is January.
*/
-static int normalDays[] = {
+static const int normalDays[] = {
-1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364
};
-static int leapDays[] = {
+static const int leapDays[] = {
-1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
};
@@ -67,7 +65,7 @@ typedef struct TimeInfo {
/*
* The following values are used for calculating virtual time. Virtual
* time is always equal to:
- * lastFileTime + (current perf counter - lastCounter)
+ * lastFileTime + (current perf counter - lastCounter)
* * 10000000 / curCounterFreq
* and lastFileTime and lastCounter are updated any time that virtual time
* is returned to a caller.
@@ -89,7 +87,7 @@ typedef struct TimeInfo {
} TimeInfo;
static TimeInfo timeInfo = {
- { NULL },
+ { NULL, 0, 0, NULL, NULL, 0 },
0,
0,
(HANDLE) NULL,
@@ -119,7 +117,7 @@ static struct tm * ComputeGMT(const time_t *tp);
static void StopCalibration(ClientData clientData);
static DWORD WINAPI CalibrationThread(LPVOID arg);
static void UpdateTimeEachSecond(void);
-static void ResetCounterSamples(Tcl_WideUInt fileTime,
+static void ResetCounterSamples(Tcl_WideUInt fileTime,
Tcl_WideInt perfCounter, Tcl_WideInt perfFreq);
static Tcl_WideInt AccumulateSample(Tcl_WideInt perfCounter,
Tcl_WideUInt fileTime);
@@ -154,11 +152,11 @@ ClientData tclTimeClientData = NULL;
*/
unsigned long
-TclpGetSeconds()
+TclpGetSeconds(void)
{
Tcl_Time t;
- (*tclGetTimeProcPtr) (&t, tclTimeClientData); /* Tcl_GetTime inlined. */
+ tclGetTimeProcPtr(&t, tclTimeClientData); /* Tcl_GetTime inlined. */
return t.sec;
}
@@ -182,7 +180,7 @@ TclpGetSeconds()
*/
unsigned long
-TclpGetClicks()
+TclpGetClicks(void)
{
/*
* Use the Tcl_GetTime abstraction to get the time in microseconds, as
@@ -192,7 +190,7 @@ TclpGetClicks()
Tcl_Time now; /* Current Tcl time */
unsigned long retval; /* Value to return */
- (*tclGetTimeProcPtr) (&now, tclTimeClientData); /* Tcl_GetTime inlined */
+ tclGetTimeProcPtr(&now, tclTimeClientData); /* Tcl_GetTime inlined */
retval = (now.sec * 1000000) + now.usec;
return retval;
@@ -202,35 +200,6 @@ TclpGetClicks()
/*
*----------------------------------------------------------------------
*
- * TclpGetTimeZone --
- *
- * Determines the current timezone. The method varies wildly between
- * different Platform implementations, so its hidden in this function.
- *
- * Results:
- * Minutes west of GMT.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-int
-TclpGetTimeZone(currentTime)
- unsigned long currentTime;
-{
- int timeZone;
-
- tzset();
- timeZone = timezone / 60;
-
- return timeZone;
-}
-
-/*
- *----------------------------------------------------------------------
- *
* Tcl_GetTime --
*
* Gets the current system time in seconds and microseconds since the
@@ -251,10 +220,10 @@ TclpGetTimeZone(currentTime)
*/
void
-Tcl_GetTime(timePtr)
- Tcl_Time *timePtr; /* Location to store time information. */
+Tcl_GetTime(
+ Tcl_Time *timePtr) /* Location to store time information. */
{
- (*tclGetTimeProcPtr) (timePtr, tclTimeClientData);
+ tclGetTimeProcPtr(timePtr, tclTimeClientData);
}
/*
@@ -275,9 +244,9 @@ Tcl_GetTime(timePtr)
*/
static void
-NativeScaleTime(timePtr, clientData)
- Tcl_Time *timePtr;
- ClientData clientData;
+NativeScaleTime(
+ Tcl_Time *timePtr,
+ ClientData clientData)
{
/*
* Native scale is 1:1. Nothing is done.
@@ -307,11 +276,11 @@ NativeScaleTime(timePtr, clientData)
*/
static void
-NativeGetTime(timePtr, clientData)
- Tcl_Time *timePtr;
- ClientData clientData;
+NativeGetTime(
+ Tcl_Time *timePtr,
+ ClientData clientData)
{
- struct timeb t;
+ struct _timeb t;
int useFtime = 1; /* Flag == TRUE if we need to fall back on
* ftime rather than using the perf counter. */
@@ -322,7 +291,7 @@ NativeGetTime(timePtr, clientData)
* avoids an extra mutex lock in the common case.
*/
- if (!timeInfo.initialized) {
+ if (!timeInfo.initialized) {
TclpInitLock();
if (!timeInfo.initialized) {
timeInfo.perfCounterAvailable =
@@ -379,7 +348,7 @@ NativeGetTime(timePtr, clientData)
&& regs[1] == 0x756e6547 /* "Genu" */
&& regs[3] == 0x49656e69 /* "ineI" */
&& regs[2] == 0x6c65746e /* "ntel" */
- && TclWinCPUID(1, regs) == TCL_OK
+ && TclWinCPUID(1, regs) == TCL_OK
&& ((regs[0]&0x00000F00) == 0x00000F00 /* Pentium 4 */
|| ((regs[0] & 0x00F00000) /* Extended family */
&& (regs[3] & 0x10000000))) /* Hyperthread */
@@ -416,7 +385,7 @@ NativeGetTime(timePtr, clientData)
WaitForSingleObject(timeInfo.readyEvent, INFINITE);
CloseHandle(timeInfo.readyEvent);
- Tcl_CreateExitHandler(StopCalibration, (ClientData) NULL);
+ Tcl_CreateExitHandler(StopCalibration, NULL);
}
timeInfo.initialized = TRUE;
}
@@ -446,7 +415,7 @@ NativeGetTime(timePtr, clientData)
QueryPerformanceCounter(&curCounter);
- /*
+ /*
* 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
@@ -464,21 +433,21 @@ NativeGetTime(timePtr, clientData)
timeInfo.fileTimeLastCall.QuadPart = curFileTime;
timeInfo.perfCounterLastCall.QuadPart = curCounter.QuadPart;
usecSincePosixEpoch = (curFileTime - posixEpoch.QuadPart) / 10;
- timePtr->sec = (time_t) (usecSincePosixEpoch / 1000000);
+ timePtr->sec = (long) (usecSincePosixEpoch / 1000000);
timePtr->usec = (unsigned long) (usecSincePosixEpoch % 1000000);
useFtime = 0;
}
LeaveCriticalSection(&timeInfo.cs);
}
-
+
if (useFtime) {
/*
* High resolution timer is not available. Just use ftime.
*/
- ftime(&t);
- timePtr->sec = t.time;
+ _ftime(&t);
+ timePtr->sec = (long)t.time;
timePtr->usec = t.millitm * 1000;
}
}
@@ -502,8 +471,8 @@ NativeGetTime(timePtr, clientData)
*/
static void
-StopCalibration(ClientData unused)
- /* Client data is unused */
+StopCalibration(
+ ClientData unused) /* Client data is unused */
{
SetEvent(timeInfo.exitEvent);
@@ -520,92 +489,6 @@ StopCalibration(ClientData unused)
/*
*----------------------------------------------------------------------
*
- * TclpGetTZName --
- *
- * Gets the current timezone string.
- *
- * Results:
- * Returns a pointer to a static string, or NULL on failure.
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
-char *
-TclpGetTZName(int dst)
-{
- int len;
- char *zone, *p;
- TIME_ZONE_INFORMATION tz;
- Tcl_Encoding encoding;
- ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
- char *name = tsdPtr->tzName;
-
- /*
- * tzset() under Borland doesn't seem to set up tzname[] at all.
- * tzset() under MSVC has the following weird observed behavior:
- * First time we call "clock format [clock seconds] -format %Z -gmt 1"
- * we get "GMT", but on all subsequent calls we get the current time
- * ezone string, even though env(TZ) is GMT and the variable _timezone
- * is 0.
- */
-
- name[0] = '\0';
-
- zone = getenv("TZ");
- if (zone != NULL) {
- /*
- * TZ is of form "NST-4:30NDT", where "NST" would be the name of the
- * standard time zone for this area, "-4:30" is the offset from GMT in
- * hours, and "NDT is the name of the daylight savings time zone in
- * this area. The offset and DST strings are optional.
- */
-
- len = strlen(zone);
- if (len > 3) {
- len = 3;
- }
- if (dst != 0) {
- /*
- * Skip the offset string and get the DST string.
- */
-
- p = zone + len;
- p += strspn(p, "+-:0123456789");
- if (*p != '\0') {
- zone = p;
- len = strlen(zone);
- if (len > 3) {
- len = 3;
- }
- }
- }
- Tcl_ExternalToUtf(NULL, NULL, zone, len, 0, NULL, name,
- sizeof(tsdPtr->tzName), NULL, NULL, NULL);
- }
- if (name[0] == '\0') {
- if (GetTimeZoneInformation(&tz) == TIME_ZONE_ID_UNKNOWN) {
- /*
- * MSDN: On NT this is returned if DST is not used in the current
- * TZ
- */
-
- dst = 0;
- }
- encoding = Tcl_GetEncoding(NULL, "unicode");
- Tcl_ExternalToUtf(NULL, encoding,
- (char *) ((dst) ? tz.DaylightName : tz.StandardName), -1,
- 0, NULL, name, sizeof(tsdPtr->tzName), NULL, NULL, NULL);
- Tcl_FreeEncoding(encoding);
- }
- return name;
-}
-
-/*
- *----------------------------------------------------------------------
- *
* TclpGetDate --
*
* This function converts between seconds and struct tm. If useGMT is
@@ -622,9 +505,9 @@ TclpGetTZName(int dst)
*/
struct tm *
-TclpGetDate(t, useGMT)
- CONST time_t *t;
- int useGMT;
+TclpGetDate(
+ const time_t *t,
+ int useGMT)
{
struct tm *tmPtr;
time_t time;
@@ -660,7 +543,7 @@ TclpGetDate(t, useGMT)
}
time = *t - timezone;
-
+
/*
* If we aren't near to overflowing the long, just add the bias and
* use the normal calculation. Otherwise we will need to adjust the
@@ -685,7 +568,7 @@ TclpGetDate(t, useGMT)
tmPtr->tm_sec += 60;
time -= 60;
}
-
+
time = tmPtr->tm_min + time/60;
tmPtr->tm_min = (int)(time % 60);
if (tmPtr->tm_min < 0) {
@@ -701,9 +584,9 @@ TclpGetDate(t, useGMT)
}
time /= 24;
- tmPtr->tm_mday += time;
- tmPtr->tm_yday += time;
- tmPtr->tm_wday = (tmPtr->tm_wday + time) % 7;
+ tmPtr->tm_mday += (int)time;
+ tmPtr->tm_yday += (int)time;
+ tmPtr->tm_wday = (tmPtr->tm_wday + (int)time) % 7;
}
} else {
tmPtr = ComputeGMT(t);
@@ -729,13 +612,13 @@ TclpGetDate(t, useGMT)
*/
static struct tm *
-ComputeGMT(tp)
- const time_t *tp;
+ComputeGMT(
+ const time_t *tp)
{
struct tm *tmPtr;
long tmp, rem;
int isLeap;
- int *days;
+ const int *days;
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
tmPtr = &tsdPtr->tm;
@@ -744,8 +627,8 @@ ComputeGMT(tp)
* Compute the 4 year span containing the specified time.
*/
- tmp = *tp / SECSPER4YEAR;
- rem = *tp % SECSPER4YEAR;
+ tmp = (long)(*tp / SECSPER4YEAR);
+ rem = (long)(*tp % SECSPER4YEAR);
/*
* Correct for weird mod semantics so the remainder is always positive.
@@ -787,7 +670,7 @@ ComputeGMT(tp)
tmPtr->tm_yday = rem / SECSPERDAY;
rem %= SECSPERDAY;
-
+
/*
* Compute the time of day.
*/
@@ -812,7 +695,7 @@ ComputeGMT(tp)
* Compute day of week. Epoch started on a Thursday.
*/
- tmPtr->tm_wday = (*tp / SECSPERDAY) + 4;
+ tmPtr->tm_wday = (long)(*tp / SECSPERDAY) + 4;
if ((*tp % SECSPERDAY) < 0) {
tmPtr->tm_wday--;
}
@@ -851,7 +734,8 @@ ComputeGMT(tp)
*/
static DWORD WINAPI
-CalibrationThread(LPVOID arg)
+CalibrationThread(
+ LPVOID arg)
{
FILETIME curFileTime;
DWORD waitResult;
@@ -918,7 +802,7 @@ CalibrationThread(LPVOID arg)
*/
static void
-UpdateTimeEachSecond()
+UpdateTimeEachSecond(void)
{
LARGE_INTEGER curPerfCounter;
/* Current value returned from
@@ -989,11 +873,11 @@ UpdateTimeEachSecond()
* sec, so that virtual time 2 sec from now will be
*
* vt1 = 20000000 + curFileTime
- *
+ *
* The frequency that we need to use to drift the counter back into place
* is estFreq * 20000000 / (vt1 - vt0)
*/
-
+
vt0 = 10000000 * (curPerfCounter.QuadPart
- timeInfo.perfCounterLastCall.QuadPart)
/ timeInfo.curCounterFreq.QuadPart
@@ -1090,7 +974,9 @@ ResetCounterSamples(
*/
static Tcl_WideInt
-AccumulateSample(Tcl_WideInt perfCounter, Tcl_WideUInt fileTime)
+AccumulateSample(
+ Tcl_WideInt perfCounter,
+ Tcl_WideUInt fileTime)
{
Tcl_WideUInt workFTSample; /* File time sample being removed from or
* added to the circular buffer. */
@@ -1128,22 +1014,22 @@ AccumulateSample(Tcl_WideInt perfCounter, Tcl_WideUInt fileTime)
/*
* Estimate the frequency.
*/
-
+
workPCSample = timeInfo.perfCounterSample[timeInfo.sampleNo];
workFTSample = timeInfo.fileTimeSample[timeInfo.sampleNo];
estFreq = 10000000 * (perfCounter - workPCSample)
/ (fileTime - workFTSample);
timeInfo.perfCounterSample[timeInfo.sampleNo] = perfCounter;
timeInfo.fileTimeSample[timeInfo.sampleNo] = (Tcl_WideInt) fileTime;
-
+
/*
* Advance the sample number.
*/
-
+
if (++timeInfo.sampleNo >= SAMPLES) {
timeInfo.sampleNo = 0;
- }
-
+ }
+
return estFreq;
}
}
@@ -1165,8 +1051,8 @@ AccumulateSample(Tcl_WideInt perfCounter, Tcl_WideUInt fileTime)
*/
struct tm *
-TclpGmtime(timePtr)
- CONST time_t *timePtr; /* Pointer to the number of seconds since the
+TclpGmtime(
+ const time_t *timePtr) /* Pointer to the number of seconds since the
* local system's epoch */
{
/*
@@ -1196,10 +1082,9 @@ TclpGmtime(timePtr)
*/
struct tm *
-TclpLocaltime(timePtr)
- CONST time_t *timePtr; /* Pointer to the number of seconds since the
+TclpLocaltime(
+ const time_t *timePtr) /* Pointer to the number of seconds since the
* local system's epoch */
-
{
/*
* The MS implementation of localtime is thread safe because it returns
@@ -1228,10 +1113,10 @@ TclpLocaltime(timePtr)
*/
void
-Tcl_SetTimeProc(getProc, scaleProc, clientData)
- Tcl_GetTimeProc *getProc;
- Tcl_ScaleTimeProc *scaleProc;
- ClientData clientData;
+Tcl_SetTimeProc(
+ Tcl_GetTimeProc *getProc,
+ Tcl_ScaleTimeProc *scaleProc,
+ ClientData clientData)
{
tclGetTimeProcPtr = getProc;
tclScaleTimeProcPtr = scaleProc;
@@ -1255,10 +1140,10 @@ Tcl_SetTimeProc(getProc, scaleProc, clientData)
*/
void
-Tcl_QueryTimeProc(getProc, scaleProc, clientData)
- Tcl_GetTimeProc ** getProc;
- Tcl_ScaleTimeProc **scaleProc;
- ClientData *clientData;
+Tcl_QueryTimeProc(
+ Tcl_GetTimeProc **getProc,
+ Tcl_ScaleTimeProc **scaleProc,
+ ClientData *clientData)
{
if (getProc) {
*getProc = tclGetTimeProcPtr;