diff options
author | sebres <sebres@users.sourceforge.net> | 2017-07-03 13:29:42 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2017-07-03 13:29:42 (GMT) |
commit | 62e00681cf398709d6a32eaa1ae0ccae3a5da9ef (patch) | |
tree | 4f7ad28b70f39e5c0b7d69c038442b825999ef55 /generic/tclEvent.c | |
parent | 913dc38311eb8c0ecbf81444db4d7d0a9276c4e5 (diff) | |
download | tcl-62e00681cf398709d6a32eaa1ae0ccae3a5da9ef.zip tcl-62e00681cf398709d6a32eaa1ae0ccae3a5da9ef.tar.gz tcl-62e00681cf398709d6a32eaa1ae0ccae3a5da9ef.tar.bz2 |
interim commit: trying to resolve time-freezes with new facilities timeJump/timeJumpEpoch
Diffstat (limited to 'generic/tclEvent.c')
-rw-r--r-- | generic/tclEvent.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/generic/tclEvent.c b/generic/tclEvent.c index 05e3109..53668d0 100644 --- a/generic/tclEvent.c +++ b/generic/tclEvent.c @@ -1385,7 +1385,7 @@ Tcl_VwaitObjCmd( char *nameString; int optc = objc - 2; /* options count without cmd and varname */ double ms = -1; - Tcl_Time wakeup; + Tcl_Time lastNow, wakeup; long tolerance = 0; if (objc < 2) { @@ -1416,7 +1416,8 @@ Tcl_VwaitObjCmd( /* if timeout specified - create timer event or no-wait by 0ms */ if (ms != -1) { if (ms > 0) { - Tcl_GetTime(&wakeup); + Tcl_GetTime(&lastNow); + wakeup = lastNow; TclTimeAddMilliseconds(&wakeup, ms); #ifdef TMR_RES_TOLERANCE tolerance = (ms < 1000 ? ms : 1000) * @@ -1439,11 +1440,26 @@ Tcl_VwaitObjCmd( if (ms > 0) { Tcl_Time blockTime; Tcl_GetTime(&blockTime); + /* + * Note time can be switched backwards, certainly adjust end-time + * by possible time-jumps back. + */ + if (TCL_TIME_BEFORE(blockTime, lastNow)) { + /* backwards time-jump - simply shift wakeup-time */ + wakeup.sec -= (lastNow.sec - blockTime.sec); + wakeup.usec -= (lastNow.usec - blockTime.usec); + if (wakeup.usec < 0) { + wakeup.usec += 1000000; + wakeup.sec--; + } + } + /* calculate blocking time */ + lastNow = blockTime; blockTime.sec = wakeup.sec - blockTime.sec; blockTime.usec = wakeup.usec - blockTime.usec; if (blockTime.usec < 0) { - blockTime.sec--; blockTime.usec += 1000000; + blockTime.sec--; } /* be sure process at least one event */ if ( blockTime.sec < 0 |