summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixTime.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2018-06-01 16:04:22 (GMT)
committerdgp <dgp@users.sourceforge.net>2018-06-01 16:04:22 (GMT)
commit1545e3155786a2643bbabc7e7e5ef8b1a1d47d4a (patch)
treefac0aaec99f3cb2a5d7d163aab3078b8e8429465 /unix/tclUnixTime.c
parent5e3ca11761b27133a62ee5cd5e340956c640ca8d (diff)
parent71f7b946a6a525d6c5163a34bd1c2d2ad72f25c8 (diff)
downloadtcl-1545e3155786a2643bbabc7e7e5ef8b1a1d47d4a.zip
tcl-1545e3155786a2643bbabc7e7e5ef8b1a1d47d4a.tar.gz
tcl-1545e3155786a2643bbabc7e7e5ef8b1a1d47d4a.tar.bz2
Rebase the sebres clock bounty work to the 8.7 branch.
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 6a73ac2..1d8b351 100644
--- a/unix/tclUnixTime.c
+++ b/unix/tclUnixTime.c
@@ -87,6 +87,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
@@ -219,6 +245,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 */
/*