1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-04 08:30:54 +02:00

- Use floatsecondsgetfn() and floatsecondssetfn() inside the int* version

of the functions (for improved accuracy).
- Added getrawseconds() and setrawsecodns() to allow the code to save and
  restore the actual start time of the $SECONDS variable.
- Changed the code that was adding in the child's elapsed time into the
  parent $SECONDS variable to just restore the raw time.
This commit is contained in:
Wayne Davison 2002-10-31 18:32:40 +00:00
parent fd3bac933f
commit a2365a60db

View file

@ -97,7 +97,9 @@ mod_export unsigned char bangchar;
/**/ /**/
unsigned char hatchar, hashchar; unsigned char hatchar, hashchar;
/* $SECONDS = time(NULL) - shtimer.tv_sec */ /* $SECONDS = now.tv_sec - shtimer.tv_sec
* + (now.tv_usec - shtimer.tv_usec) / 1000000.0
* (rounded to an integer if the parameter is not set to float) */
/**/ /**/
struct timeval shtimer; struct timeval shtimer;
@ -2672,7 +2674,7 @@ randomsetfn(Param pm, zlong v)
zlong zlong
intsecondsgetfn(Param pm) intsecondsgetfn(Param pm)
{ {
return time(NULL) - shtimer.tv_sec; return (zlong)floatsecondsgetfn(pm);
} }
/* Function to set value of special parameter `SECONDS' */ /* Function to set value of special parameter `SECONDS' */
@ -2681,8 +2683,7 @@ intsecondsgetfn(Param pm)
void void
intsecondssetfn(Param pm, zlong x) intsecondssetfn(Param pm, zlong x)
{ {
shtimer.tv_sec = time(NULL) - x; floatsecondssetfn(pm, (double)x);
shtimer.tv_usec = 0;
} }
/**/ /**/
@ -2706,8 +2707,23 @@ floatsecondssetfn(Param pm, double x)
struct timezone dummy_tz; struct timezone dummy_tz;
gettimeofday(&now, &dummy_tz); gettimeofday(&now, &dummy_tz);
shtimer.tv_sec = now.tv_sec - (int)x; shtimer.tv_sec = now.tv_sec - (zlong)x;
shtimer.tv_usec = now.tv_usec - (int)((x - (double)(int)x) * 1000000.0); shtimer.tv_usec = now.tv_usec - (zlong)((x - (zlong)x) * 1000000.0);
}
/**/
double
getrawseconds(void)
{
return (double)shtimer.tv_sec + (double)shtimer.tv_usec / 1000000.0;
}
/**/
void
setrawseconds(double x)
{
shtimer.tv_sec = (zlong)x;
shtimer.tv_usec = (zlong)((x - (zlong)x) * 1000000.0);
} }
/**/ /**/
@ -3487,19 +3503,10 @@ scanendscope(HashNode hn, int flags)
{ {
setsecondstype(pm, PM_TYPE(tpm->flags), PM_TYPE(pm->flags)); setsecondstype(pm, PM_TYPE(tpm->flags), PM_TYPE(pm->flags));
/* /*
* We restore SECONDS by adding back in the elapsed * We restore SECONDS by restoring its raw internal value
* time (from the point we reset shtimer) rather * that we cached off into tpm->u.dval.
* than restoring it completely, since SECONDS should
* run in the calling function, too.
*/ */
if (PM_TYPE(pm->flags) == PM_INTEGER) setrawseconds(tpm->u.dval);
{
pm->sets.ifn(pm, pm->gets.ifn(pm) + tpm->u.val);
}
else
{
pm->sets.ffn(pm, pm->gets.ffn(pm) + tpm->u.dval);
}
tpm->flags |= PM_NORESTORE; tpm->flags |= PM_NORESTORE;
} }
DPUTS(!tpm || PM_TYPE(pm->flags) != PM_TYPE(tpm->flags) || DPUTS(!tpm || PM_TYPE(pm->flags) != PM_TYPE(tpm->flags) ||