diff options
author | sebres <sebres@users.sourceforge.net> | 2017-02-09 11:36:17 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2017-02-09 11:36:17 (GMT) |
commit | fb811680f60f0555a27685601c519ff931956593 (patch) | |
tree | 1fd7d26262a58c457148ba5448a9339c3d92771a /unix | |
parent | 1ff982ffd6785745b647bbe0bb46aca7e13ace8e (diff) | |
download | tcl-fb811680f60f0555a27685601c519ff931956593.zip tcl-fb811680f60f0555a27685601c519ff931956593.tar.gz tcl-fb811680f60f0555a27685601c519ff931956593.tar.bz2 |
[timerate] bug fix: missing scale conversion by Mac OSX on platform where high resolution clicks are not microseconds based;
[win] use high resolution timer for the wide clicks and microseconds directly, prevent several forwards/backwards conversions;
[win, unix, mac-osx] normalize some functions for common usage in different time units (clicks, micro- and nanoseconds)
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 d634449..8ec6e8a 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 */ /* |