summaryrefslogtreecommitdiffstats
path: root/win/tclWinTime.c
diff options
context:
space:
mode:
authorandreas_kupries <akupries@shaw.ca>2005-01-21 22:24:43 (GMT)
committerandreas_kupries <akupries@shaw.ca>2005-01-21 22:24:43 (GMT)
commitf11befd3bbce6f1f7a8cd43bb51bf6126ba125bf (patch)
tree403c7dfd1bf849fa476cb6ccaf3a2231eaca625a /win/tclWinTime.c
parent2587836dd5f442ad7f95eb68cd40e56545b72663 (diff)
downloadtcl-f11befd3bbce6f1f7a8cd43bb51bf6126ba125bf.zip
tcl-f11befd3bbce6f1f7a8cd43bb51bf6126ba125bf.tar.gz
tcl-f11befd3bbce6f1f7a8cd43bb51bf6126ba125bf.tar.bz2
* generic/tclStubInit.c: Regenerated the stubs support code from
* generic/tclDecls.h: the modified tcl.decls (TIP #233, see below). * doc/GetTime.3: Implemented TIP #233, i.e. the * generic/tcl.decls: 'Virtualization of Tcl's Sense of Time'. * generic/tcl.h: Declared, implemented, and documented the * generic/tclInt.h: specified new API functions. Moved the * unix/tclUnixEvent.c: native (OS) access to time information * unix/tclUnixNotfy.c: into standard handler functions. Inserted * unix/tclUnixTime.c: hooks calling on the handlers where native * win/tclWinNotify.c: access was done before, and where scaling * win/tclWinTime.c: between domains (real/virtual) is required.
Diffstat (limited to 'win/tclWinTime.c')
-rw-r--r--win/tclWinTime.c142
1 files changed, 139 insertions, 3 deletions
diff --git a/win/tclWinTime.c b/win/tclWinTime.c
index 48460bb..47294df 100644
--- a/win/tclWinTime.c
+++ b/win/tclWinTime.c
@@ -9,7 +9,7 @@
* 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.29 2005/01/21 22:25:35 andreas_kupries Exp $
*/
#include "tclInt.h"
@@ -138,6 +138,17 @@ 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;
/*
*----------------------------------------------------------------------
@@ -160,7 +171,8 @@ unsigned long
TclpGetSeconds()
{
Tcl_Time t;
- Tcl_GetTime( &t );
+ /* Tcl_GetTime inlined */
+ (*tclGetTimeProcPtr) (&t, tclTimeClientData);
return t.sec;
}
@@ -195,7 +207,9 @@ TclpGetClicks()
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;
@@ -258,6 +272,64 @@ 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;
@@ -1182,3 +1254,67 @@ TclpLocaltime( timePtr )
*/
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;
+ }
+}
+