summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixTime.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2016-09-26 15:38:23 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2016-09-26 15:38:23 (GMT)
commit4be64948c96e8b037c13a0b2166ba37572ab6a2a (patch)
tree44b289ba647c1797b19ba9faef5d103df37d4a7c /unix/tclUnixTime.c
parent848a94dd3acbd7420103354f2d6773e8e7f077a7 (diff)
parent2a21b737eaf5db0eb26712dae12203c3c75fbd42 (diff)
downloadtcl-4be64948c96e8b037c13a0b2166ba37572ab6a2a.zip
tcl-4be64948c96e8b037c13a0b2166ba37572ab6a2a.tar.gz
tcl-4be64948c96e8b037c13a0b2166ba37572ab6a2a.tar.bz2
Merge core-8-6-branch. upstream androwish modifications.
Diffstat (limited to 'unix/tclUnixTime.c')
-rw-r--r--unix/tclUnixTime.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/unix/tclUnixTime.c b/unix/tclUnixTime.c
index 315bcf9..a983ea2 100644
--- a/unix/tclUnixTime.c
+++ b/unix/tclUnixTime.c
@@ -105,6 +105,12 @@ TclpGetClicks(void)
{
unsigned long now;
+#ifdef HAVE_CLOCK_GETTIME
+ Tcl_Time time;
+
+ TclpGetMonotonicTime(&time);
+ now = time.sec*1000000 + time.usec;
+#else
#ifdef NO_GETTOD
if (tclGetTimeProcPtr != NativeGetTime) {
Tcl_Time time;
@@ -125,6 +131,7 @@ TclpGetClicks(void)
tclGetTimeProcPtr(&time, tclTimeClientData);
now = time.sec*1000000 + time.usec;
#endif
+#endif
return now;
}
@@ -376,9 +383,11 @@ Tcl_SetTimeProc(
Tcl_ScaleTimeProc *scaleProc,
ClientData clientData)
{
+#ifndef HAVE_CLOCK_GETTIME
tclGetTimeProcPtr = getProc;
tclScaleTimeProcPtr = scaleProc;
tclTimeClientData = clientData;
+#endif
}
/*
@@ -533,6 +542,58 @@ CleanupMemory(
}
/*
+ *----------------------------------------------------------------------
+ *
+ * TclpGetMononoticTime --
+ *
+ * Like Tcl_GetTime() but return a monotonic clock source,
+ * if possible. Otherwise fall back to real (wall clock) time.
+ *
+ * Results:
+ * 1 if monotonic, 0 otherwise.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+TclpGetMonotonicTime(Tcl_Time *timePtr)
+{
+#ifdef HAVE_CLOCK_GETTIME
+ int ret;
+ struct timespec ts;
+ static int useMonoClock = -1;
+
+ if (useMonoClock) {
+ ret = (clock_gettime(CLOCK_MONOTONIC, &ts) == 0);
+ if (useMonoClock < 0) {
+ useMonoClock = ret;
+ if (!ret) {
+ (void) clock_gettime(CLOCK_REALTIME, &ts);
+ }
+ } else if (!ret) {
+ Tcl_Panic("clock_gettime(CLOCK_MONOTONIC) failed");
+ }
+ } else {
+ (void) clock_gettime(CLOCK_REALTIME, &ts);
+ ret = 0;
+ }
+ timePtr->sec = ts.tv_sec;
+ timePtr->usec = ts.tv_nsec / 1000;
+ return ret;
+#else
+ struct timeval tv;
+
+ (void) gettimeofday(&tv, NULL);
+ timePtr->sec = tv.tv_sec;
+ timePtr->usec = tv.tv_usec;
+ return 0;
+#endif
+}
+
+/*
* Local Variables:
* mode: c
* c-basic-offset: 4