diff options
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclCmdMZ.c | 4 | ||||
-rw-r--r-- | generic/tclInt.h | 1 | ||||
-rw-r--r-- | generic/tclInterp.c | 43 | ||||
-rw-r--r-- | generic/tclTimer.c | 14 |
4 files changed, 50 insertions, 12 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index ba1fc41..ddb57b0 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -4003,7 +4003,7 @@ Tcl_TimeObjCmd( objPtr = objv[1]; i = count; #ifndef TCL_WIDE_CLICKS - Tcl_GetTime(&start); + TclpGetMonotonicTime(&start); #else start = TclpGetWideClicks(); #endif @@ -4014,7 +4014,7 @@ Tcl_TimeObjCmd( } } #ifndef TCL_WIDE_CLICKS - Tcl_GetTime(&stop); + TclpGetMonotonicTime(&stop); totalMicroSec = ((double) (stop.sec - start.sec)) * 1.0e6 + (stop.usec - start.usec); #else diff --git a/generic/tclInt.h b/generic/tclInt.h index d725688..f43de31 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -3207,6 +3207,7 @@ MODULE_SCOPE void TclpThreadSetMasterTSD(void *tsdKeyPtr, void *ptr); MODULE_SCOPE void * TclpThreadGetMasterTSD(void *tsdKeyPtr); MODULE_SCOPE void TclErrorStackResetIf(Tcl_Interp *interp, const char *msg, int length); +MODULE_SCOPE int TclpGetMonotonicTime(Tcl_Time *timePtr); /* *---------------------------------------------------------------- diff --git a/generic/tclInterp.c b/generic/tclInterp.c index d9dfd37..1bf3cf9 100644 --- a/generic/tclInterp.c +++ b/generic/tclInterp.c @@ -3404,7 +3404,7 @@ Tcl_LimitCheck( (ticker % iPtr->limit.timeGranularity == 0))) { Tcl_Time now; - Tcl_GetTime(&now); + TclpGetMonotonicTime(&now); if (iPtr->limit.time.sec < now.sec || (iPtr->limit.time.sec == now.sec && iPtr->limit.time.usec < now.usec)) { @@ -3956,7 +3956,25 @@ Tcl_LimitSetTime( Tcl_Time *timeLimitPtr) { Interp *iPtr = (Interp *) interp; - Tcl_Time nextMoment; + Tcl_Time nextMoment, mono, real, limit; + + if (TclpGetMonotonicTime(&mono)) { + Tcl_GetTime(&real); + limit = *timeLimitPtr; + limit.sec -= real.sec; + limit.usec -= real.usec; + if (limit.usec < 0) { + limit.sec -= 1; + limit.usec += 1000000; + } + limit.sec += mono.sec; + limit.usec += mono.usec; + if (limit.usec >= 1000000) { + limit.sec += 1; + limit.usec -= 1000000; + } + timeLimitPtr = &limit; + } memcpy(&iPtr->limit.time, timeLimitPtr, sizeof(Tcl_Time)); if (iPtr->limit.timeEvent != NULL) { @@ -4041,7 +4059,26 @@ Tcl_LimitGetTime( Tcl_Time *timeLimitPtr) { Interp *iPtr = (Interp *) interp; - + Tcl_Time mono, real, limit; + + if (TclpGetMonotonicTime(&mono)) { + Tcl_GetTime(&real); + limit = iPtr->limit.time; + limit.sec -= mono.sec; + limit.usec -= mono.usec; + if (limit.usec < 0) { + limit.sec -= 1; + limit.usec += 1000000; + } + limit.sec += real.sec; + limit.usec += real.usec; + if (limit.usec >= 1000000) { + limit.sec += 1; + limit.usec -= 1000000; + } + memcpy(timeLimitPtr, &limit, sizeof(Tcl_Time)); + return; + } memcpy(timeLimitPtr, &iPtr->limit.time, sizeof(Tcl_Time)); } diff --git a/generic/tclTimer.c b/generic/tclTimer.c index 3467305..16003b0 100644 --- a/generic/tclTimer.c +++ b/generic/tclTimer.c @@ -259,7 +259,7 @@ Tcl_CreateTimerHandler( * Compute when the event should fire. */ - Tcl_GetTime(&time); + TclpGetMonotonicTime(&time); time.sec += milliseconds/1000; time.usec += (milliseconds%1000)*1000; if (time.usec >= 1000000) { @@ -417,7 +417,7 @@ TimerSetupProc( * Compute the timeout for the next timer on the list. */ - Tcl_GetTime(&blockTime); + TclpGetMonotonicTime(&blockTime); blockTime.sec = tsdPtr->firstTimerHandlerPtr->time.sec - blockTime.sec; blockTime.usec = tsdPtr->firstTimerHandlerPtr->time.usec - blockTime.usec; @@ -468,7 +468,7 @@ TimerCheckProc( * Compute the timeout for the next timer on the list. */ - Tcl_GetTime(&blockTime); + TclpGetMonotonicTime(&blockTime); blockTime.sec = tsdPtr->firstTimerHandlerPtr->time.sec - blockTime.sec; blockTime.usec = tsdPtr->firstTimerHandlerPtr->time.usec - blockTime.usec; @@ -564,7 +564,7 @@ TimerHandlerEventProc( tsdPtr->timerPending = 0; currentTimerId = tsdPtr->lastTimerId; - Tcl_GetTime(&time); + TclpGetMonotonicTime(&time); while (1) { nextPtrPtr = &tsdPtr->firstTimerHandlerPtr; timerHandlerPtr = tsdPtr->firstTimerHandlerPtr; @@ -872,7 +872,7 @@ Tcl_AfterObjCmd( afterPtr->id = tsdPtr->afterId; tsdPtr->afterId += 1; - Tcl_GetTime(&wakeup); + TclpGetMonotonicTime(&wakeup); wakeup.sec += (long)(ms / 1000); wakeup.usec += ((long)(ms % 1000)) * 1000; if (wakeup.usec > 1000000) { @@ -1017,7 +1017,7 @@ AfterDelay( Tcl_Time endTime, now; Tcl_WideInt diff; - Tcl_GetTime(&now); + TclpGetMonotonicTime(&now); endTime = now; endTime.sec += (long)(ms/1000); endTime.usec += ((int)(ms%1000))*1000; @@ -1089,7 +1089,7 @@ AfterDelay( return TCL_ERROR; } } - Tcl_GetTime(&now); + TclpGetMonotonicTime(&now); } while (TCL_TIME_BEFORE(now, endTime)); return TCL_OK; } |