Diff
Not logged in

Differences From Artifact [502c92cf26]:

To Artifact [f1a684d395]:


1
2
3
4
5
6
7
8
9
10
11
12

13
14
15
16
17
18
19
1
2
3
4
5
6
7
8
9
10
11

12
13
14
15
16
17
18
19











-
+







/* 
 * tclWinTime.c --
 *
 *	Contains Windows specific versions of Tcl functions that
 *	obtain time values from the operating system.
 *
 * Copyright 1995-1998 by Sun Microsystems, Inc.
 *
 * 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.28 2004/09/07 17:39:00 kennykb Exp $
 * RCS: @(#) $Id: tclWinTime.c,v 1.28.2.1 2005/02/02 15:54:07 kennykb Exp $
 */

#include "tclInt.h"

#define SECSPERDAY (60L * 60L * 24L)
#define SECSPERYEAR (SECSPERDAY * 365L)
#define SECSPER4YEAR (SECSPERYEAR * 4L + SECSPERDAY)
134
135
136
137
138
139
140











141
142
143
144
145
146
147
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158







+
+
+
+
+
+
+
+
+
+
+







                            Tcl_WideInt perfCounter,
			    Tcl_WideInt perfFreq
			));
static Tcl_WideInt		AccumulateSample _ANSI_ARGS_((
			    Tcl_WideInt perfCounter,
			    Tcl_WideUInt fileTime
			));

static void NativeScaleTime _ANSI_ARGS_ ((Tcl_Time* timebuf, ClientData clientData));
static void NativeGetTime   _ANSI_ARGS_ ((Tcl_Time* timebuf, ClientData clientData));

/* TIP #233 (Virtualized Time)
 * Data for the time hooks, if any.
 */

Tcl_GetTimeProc*   tclGetTimeProcPtr    = NativeGetTime;
Tcl_ScaleTimeProc* tclScaleTimeProcPtr  = NativeScaleTime;
ClientData         tclTimeClientData    = NULL;

/*
 *----------------------------------------------------------------------
 *
 * TclpGetSeconds --
 *
 *	This procedure returns the number of seconds from the epoch.
156
157
158
159
160
161
162
163


164
165
166
167
168
169
170
167
168
169
170
171
172
173

174
175
176
177
178
179
180
181
182







-
+
+







 *----------------------------------------------------------------------
 */

unsigned long
TclpGetSeconds()
{
    Tcl_Time t;
    Tcl_GetTime( &t );
    /* Tcl_GetTime inlined */
    (*tclGetTimeProcPtr) (&t, tclTimeClientData);
    return t.sec;
}

/*
 *----------------------------------------------------------------------
 *
 * TclpGetClicks --
191
192
193
194
195
196
197
198



199
200
201
202
203
204
205
203
204
205
206
207
208
209

210
211
212
213
214
215
216
217
218
219







-
+
+
+







     * Use the Tcl_GetTime abstraction to get the time in microseconds,
     * as nearly as we can, and return it.
     */

    Tcl_Time now;		/* Current Tcl time */
    unsigned long retval;	/* Value to return */

    Tcl_GetTime( &now );
    /* Tcl_GetTime inlined */
    (*tclGetTimeProcPtr) (&now, tclTimeClientData);

    retval = ( now.sec * 1000000 ) + now.usec;
    return retval;

}

/*
 *----------------------------------------------------------------------
253
254
255
256
257
258
259


























































260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 *
 *----------------------------------------------------------------------
 */

void
Tcl_GetTime(timePtr)
    Tcl_Time *timePtr;		/* Location to store time information. */
{
    (*tclGetTimeProcPtr) (timePtr, tclTimeClientData);
}

/*
 *----------------------------------------------------------------------
 *
 * NativeScaleTime --
 *
 *	TIP #233
 *	Scale from virtual time to the real-time. For native scaling the
 *	relationship is 1:1 and nothing has to be done.
 *
 * Results:
 *	Scales the time in timePtr.
 *
 * Side effects:
 *	See above.
 *
 *----------------------------------------------------------------------
 */

static void
NativeScaleTime (timePtr, clientData)
     Tcl_Time*  timePtr;
     ClientData clientData;
{
  /* Native scale is 1:1. Nothing is done */
}

/*
 *----------------------------------------------------------------------
 *
 * NativeGetTime --
 *
 *	TIP #233
 *	Gets the current system time in seconds and microseconds
 *	since the beginning of the epoch: 00:00 UCT, January 1, 1970.
 *
 * Results:
 *	Returns the current time in timePtr.
 *
 * Side effects:
 *	On the first call, initializes a set of static variables to
 *	keep track of the base value of the performance counter, the
 *	corresponding wall clock (obtained through ftime) and the
 *	frequency of the performance counter.  Also spins a thread
 *	whose function is to wake up periodically and monitor these
 *	values, adjusting them as necessary to correct for drift
 *	in the performance counter's oscillator.
 *
 *----------------------------------------------------------------------
 */

static void
NativeGetTime (timePtr, clientData)
     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 */
1178
1179
1180
1181
1182
1183
1184
































































1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
    /*
     * The MS implementation of localtime is thread safe because
     * it returns the time in a block of thread-local storage,
     * and Windows does not provide a Posix localtime_r function.
     */
    return localtime( timePtr );
}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_SetTimeProc --
 *
 *      TIP #233 (Virtualized Time)
 *	Registers two handlers for the virtualization of Tcl's
 *	access to time information.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Remembers the handlers, alters core behaviour.
 *
 *----------------------------------------------------------------------
 */

void
Tcl_SetTimeProc (getProc, scaleProc, clientData)
     Tcl_GetTimeProc*   getProc;
     Tcl_ScaleTimeProc* scaleProc;
     ClientData         clientData;
{
    tclGetTimeProcPtr   = getProc;
    tclScaleTimeProcPtr = scaleProc;
    tclTimeClientData   = clientData;
}

/*
 *----------------------------------------------------------------------
 *
 * Tcl_QueryTimeProc --
 *
 *      TIP #233 (Virtualized Time)
 *	Query which time handlers are registered.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
Tcl_QueryTimeProc (getProc, scaleProc, clientData)
     Tcl_GetTimeProc**   getProc;
     Tcl_ScaleTimeProc** scaleProc;
     ClientData*         clientData;
{
    if (getProc) {
        *getProc    = tclGetTimeProcPtr;
    }
    if (scaleProc) {
        *scaleProc  = tclScaleTimeProcPtr;
    }
    if (clientData) {
        *clientData = tclTimeClientData;
    }
}