summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixTime.c
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2017-05-09 21:58:12 (GMT)
committersebres <sebres@users.sourceforge.net>2017-05-09 21:58:12 (GMT)
commit0283b4f5f3320e17a8ec17c3ec2aa6c07b9a8911 (patch)
tree182c2e3249563354f32d676f8dea488daf9e3f76 /unix/tclUnixTime.c
parent4ba2d9a81ad7f1d8b015c4f3f1dd0e6f603ecc3b (diff)
parentdb083499bfff8aee794512e3da2f0ad2f201f6b0 (diff)
downloadtcl-0283b4f5f3320e17a8ec17c3ec2aa6c07b9a8911.zip
tcl-0283b4f5f3320e17a8ec17c3ec2aa6c07b9a8911.tar.gz
tcl-0283b4f5f3320e17a8ec17c3ec2aa6c07b9a8911.tar.bz2
back-ported branch sebres_trunk_timerate (new command "timerate" for 8.6)
Diffstat (limited to 'unix/tclUnixTime.c')
-rw-r--r--unix/tclUnixTime.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/unix/tclUnixTime.c b/unix/tclUnixTime.c
index 6a3766d..375e366 100644
--- a/unix/tclUnixTime.c
+++ b/unix/tclUnixTime.c
@@ -84,6 +84,32 @@ TclpGetSeconds(void)
/*
*----------------------------------------------------------------------
*
+ * TclpGetMicroseconds --
+ *
+ * This procedure returns the number of microseconds from the epoch.
+ * On most Unix systems the epoch is Midnight Jan 1, 1970 GMT.
+ *
+ * Results:
+ * Number of microseconds from the epoch.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+Tcl_WideInt
+TclpGetMicroseconds(void)
+{
+ Tcl_Time time;
+
+ tclGetTimeProcPtr(&time, tclTimeClientData);
+ return ((Tcl_WideInt)time.sec)*1000000 + time.usec;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* TclpGetClicks --
*
* This procedure returns a value that represents the highest resolution
@@ -216,6 +242,51 @@ TclpWideClicksToNanoseconds(
return nsec;
}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TclpWideClickInMicrosec --
+ *
+ * This procedure return scale to convert click values from the
+ * TclpGetWideClicks native resolution to microsecond resolution
+ * and back.
+ *
+ * Results:
+ * 1 click in microseconds as double.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+double
+TclpWideClickInMicrosec(void)
+{
+ if (tclGetTimeProcPtr != NativeGetTime) {
+ return 1.0;
+ } else {
+#ifdef MAC_OSX_TCL
+ static int initialized = 0;
+ static double scale = 0.0;
+
+ if (initialized) {
+ return scale;
+ } else {
+ mach_timebase_info_data_t tb;
+
+ mach_timebase_info(&tb);
+ /* value of tb.numer / tb.denom = 1 click in nanoseconds */
+ scale = ((double)tb.numer) / tb.denom / 1000;
+ initialized = 1;
+ return scale;
+ }
+#else
+#error Wide high-resolution clicks not implemented on this platform
+#endif
+ }
+}
#endif /* TCL_WIDE_CLICKS */
/*