summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authordas <das>2006-08-21 01:08:41 (GMT)
committerdas <das>2006-08-21 01:08:41 (GMT)
commitd9504ba9f92205956e0b4aa1fa79e44b10a9d68d (patch)
tree79988284b81c4c2f62215be9b742d8dca444ab1c /unix
parentd70383944a28777ea679b1e1b4be38c2a42b3960 (diff)
downloadtcl-d9504ba9f92205956e0b4aa1fa79e44b10a9d68d.zip
tcl-d9504ba9f92205956e0b4aa1fa79e44b10a9d68d.tar.gz
tcl-d9504ba9f92205956e0b4aa1fa79e44b10a9d68d.tar.bz2
* generic/tclClock.c (ClockClicksObjCmd): add support for Darwin
* generic/tclCmdMZ.c (Tcl_TimeObjCmd): nanosecond resolution timer * generic/tclInt.h: to [clock clicks] and [time] * unix/configure.in (Darwin): when TCL_WIDE_CLICKS defined. * unix/tclUnixTime.c (TclpGetWideClicks, TclpWideClicksToNanoseconds): * unix/configure: autoconf-2.59 * unix/tclConfig.h.in: autoheader-2.59
Diffstat (limited to 'unix')
-rwxr-xr-xunix/configure5
-rw-r--r--unix/configure.in4
-rw-r--r--unix/tclConfig.h.in3
-rw-r--r--unix/tclUnixTime.c94
4 files changed, 104 insertions, 2 deletions
diff --git a/unix/configure b/unix/configure
index 6ae76a6..65ff57e 100755
--- a/unix/configure
+++ b/unix/configure
@@ -14564,6 +14564,11 @@ cat >>confdefs.h <<\_ACEOF
_ACEOF
+cat >>confdefs.h <<\_ACEOF
+#define TCL_WIDE_CLICKS 1
+_ACEOF
+
+
for ac_header in AvailabilityMacros.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
diff --git a/unix/configure.in b/unix/configure.in
index 3ffccf3..6c3ff2a 100644
--- a/unix/configure.in
+++ b/unix/configure.in
@@ -3,7 +3,7 @@ dnl This file is an input file used by the GNU "autoconf" program to
dnl generate the file "configure", which is run during Tcl installation
dnl to configure the system for the local environment.
#
-# RCS: @(#) $Id: configure.in,v 1.143 2006/07/20 06:18:38 das Exp $
+# RCS: @(#) $Id: configure.in,v 1.144 2006/08/21 01:08:42 das Exp $
AC_INIT([tcl],[8.5])
AC_PREREQ(2.59)
@@ -438,6 +438,8 @@ if test "`uname -s`" = "Darwin" ; then
[Are we to override what our default encoding is?])
AC_DEFINE(TCL_LOAD_FROM_MEMORY, 1,
[Can this platform load code from memory?])
+ AC_DEFINE(TCL_WIDE_CLICKS, 1,
+ [Does this platform have wide high-resolution clicks?])
AC_CHECK_HEADERS(AvailabilityMacros.h)
if test "$ac_cv_header_AvailabilityMacros_h" = yes; then
AC_CACHE_CHECK([if weak import is available], tcl_cv_cc_weak_import, [
diff --git a/unix/tclConfig.h.in b/unix/tclConfig.h.in
index b61ddfb..501c83f 100644
--- a/unix/tclConfig.h.in
+++ b/unix/tclConfig.h.in
@@ -316,6 +316,9 @@
/* Do we allow unloading of shared libraries? */
#undef TCL_UNLOAD_DLLS
+/* Does this platform have wide high-resolution clicks? */
+#undef TCL_WIDE_CLICKS
+
/* Are wide integers to be implemented with C 'long's? */
#undef TCL_WIDE_INT_IS_LONG
diff --git a/unix/tclUnixTime.c b/unix/tclUnixTime.c
index 12ba965..09003a7 100644
--- a/unix/tclUnixTime.c
+++ b/unix/tclUnixTime.c
@@ -9,11 +9,15 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixTime.c,v 1.26 2005/11/02 23:26:50 dkf Exp $
+ * RCS: @(#) $Id: tclUnixTime.c,v 1.27 2006/08/21 01:08:42 das Exp $
*/
#include "tclInt.h"
#include <locale.h>
+#if defined(TCL_WIDE_CLICKS) && defined(MAC_OSX_TCL)
+#include <mach/mach_time.h>
+#endif
+
#define TM_YEAR_BASE 1900
#define IsLeapYear(x) (((x)%4 == 0) && ((x)%100 != 0 || (x)%400 == 0))
@@ -129,6 +133,94 @@ TclpGetClicks(void)
return now;
}
+#ifdef TCL_WIDE_CLICKS
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * TclpGetWideClicks --
+ *
+ * This procedure returns a WideInt value that represents the highest
+ * resolution clock available on the system. There are no garantees on
+ * what the resolution will be. In Tcl we will call this value a "click".
+ * The start time is also system dependant.
+ *
+ * Results:
+ * Number of WideInt clicks from some start time.
+ *
+ * Side effects:
+ * None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+Tcl_WideInt
+TclpGetWideClicks(void)
+{
+ Tcl_WideInt now;
+
+ if (tclGetTimeProcPtr != NativeGetTime) {
+ Tcl_Time time;
+
+ (*tclGetTimeProcPtr) (&time, tclTimeClientData);
+ now = (Tcl_WideInt) (time.sec*1000000 + time.usec);
+ } else {
+#ifdef MAC_OSX_TCL
+ now = (Tcl_WideInt) (mach_absolute_time() & INT64_MAX);
+#else
+#error Wide high-resolution clicks not implemented on this platform
+#endif
+ }
+
+ return now;
+}
+
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * TclpWideClicksToNanoseconds --
+ *
+ * This procedure converts click values from the TclpGetWideClicks native
+ * resolution to nanosecond resolution.
+ *
+ * Results:
+ * Number of nanoseconds from some start time.
+ *
+ * Side effects:
+ * None.
+ *
+ *-----------------------------------------------------------------------------
+ */
+
+Tcl_WideInt
+TclpWideClicksToNanoseconds(Tcl_WideInt clicks)
+{
+ Tcl_WideInt nsec;
+
+ if (tclGetTimeProcPtr != NativeGetTime) {
+ nsec = clicks * 1000;
+ } else {
+#ifdef MAC_OSX_TCL
+ static mach_timebase_info_data_t tb;
+ static uint64_t maxClicksForUInt64;
+
+ if (!tb.denom) {
+ mach_timebase_info(&tb);
+ maxClicksForUInt64 = UINT64_MAX / tb.numer;
+ }
+ if ((uint64_t) clicks < maxClicksForUInt64) {
+ nsec = (Tcl_WideInt) ((uint64_t) clicks * tb.numer / tb.denom);
+ } else {
+ nsec = (Tcl_WideInt) ((long double) clicks * tb.numer / tb.denom);
+ }
+#else
+#error Wide high-resolution clicks not implemented on this platform
+#endif
+ }
+
+ return nsec;
+}
+#endif /* TCL_WIDE_CLICKS */
/*
*----------------------------------------------------------------------