diff options
author | sebres <sebres@users.sourceforge.net> | 2017-05-16 12:41:01 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2017-05-16 12:41:01 (GMT) |
commit | 658198240aecba2e0bbee884e21f0cb0c3f732d5 (patch) | |
tree | 4f6d780f650cba9a388f875c2f93cb08a57c53b1 /unix | |
parent | ab808831bd7d76198dfc874049b9fd00b009646e (diff) | |
parent | 4a5d28ee4e72a4e58dc65546f814c1cd71f3accc (diff) | |
download | tcl-658198240aecba2e0bbee884e21f0cb0c3f732d5.zip tcl-658198240aecba2e0bbee884e21f0cb0c3f732d5.tar.gz tcl-658198240aecba2e0bbee884e21f0cb0c3f732d5.tar.bz2 |
back-ported branch sebres-8-6-timerate (new command "timerate" for 8.5)
Diffstat (limited to 'unix')
-rw-r--r-- | unix/tclUnixTime.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/unix/tclUnixTime.c b/unix/tclUnixTime.c index 11b0ecf..1b4ea15 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 */ /* |