From: Jarkko Hietaniemi Date: Sun, 1 Sep 2002 19:23:55 +0000 (+0300) Subject: use sysconf(_SC_CLK_TCK) for times() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5311654c160c66b924ce3fd64ced30ed3ff8a96b;p=p5sagit%2Fp5-mst-13.2.git use sysconf(_SC_CLK_TCK) for times() Message-ID: <20020901162355.GH12536@lyta.hut.fi> p4raw-id: //depot/perl@17833 --- diff --git a/embedvar.h b/embedvar.h index 1d76394..dbc4d18 100644 --- a/embedvar.h +++ b/embedvar.h @@ -211,6 +211,7 @@ #define PL_bufptr (PERL_GET_INTERP->Ibufptr) #define PL_checkav (PERL_GET_INTERP->Icheckav) #define PL_checkav_save (PERL_GET_INTERP->Icheckav_save) +#define PL_clocktick (PERL_GET_INTERP->Iclocktick) #define PL_collation_ix (PERL_GET_INTERP->Icollation_ix) #define PL_collation_name (PERL_GET_INTERP->Icollation_name) #define PL_collation_standard (PERL_GET_INTERP->Icollation_standard) @@ -514,6 +515,7 @@ #define PL_bufptr (vTHX->Ibufptr) #define PL_checkav (vTHX->Icheckav) #define PL_checkav_save (vTHX->Icheckav_save) +#define PL_clocktick (vTHX->Iclocktick) #define PL_collation_ix (vTHX->Icollation_ix) #define PL_collation_name (vTHX->Icollation_name) #define PL_collation_standard (vTHX->Icollation_standard) @@ -820,6 +822,7 @@ #define PL_Ibufptr PL_bufptr #define PL_Icheckav PL_checkav #define PL_Icheckav_save PL_checkav_save +#define PL_Iclocktick PL_clocktick #define PL_Icollation_ix PL_collation_ix #define PL_Icollation_name PL_collation_name #define PL_Icollation_standard PL_collation_standard diff --git a/intrpvar.h b/intrpvar.h index a957e5b..c64b838 100644 --- a/intrpvar.h +++ b/intrpvar.h @@ -524,6 +524,8 @@ PERLVAR(Isort_RealCmp, SVCOMPARE_t) PERLVARI(Icheckav_save, AV*, Nullav) /* save CHECK{}s when compiling */ +PERLVARI(Iclocktick, long, 0) /* this many times() ticks in a second */ + /* New variables must be added to the very end for binary compatibility. * XSUB.h provides wrapper functions via perlapi.h that make this * irrelevant, but not all code may be expected to #include XSUB.h. */ diff --git a/perl.c b/perl.c index 393ad4f..e04670d 100644 --- a/perl.c +++ b/perl.c @@ -26,6 +26,18 @@ char *nw_get_sitelib(const char *pl); #include #endif +#ifdef __BEOS__ +# define HZ 1000000 +#endif + +#ifndef HZ +# ifdef CLK_TCK +# define HZ CLK_TCK +# else +# define HZ 60 +# endif +#endif + #if !defined(STANDARD_C) && !defined(HAS_GETENV_PROTOTYPE) && !defined(PERL_MICRO) char *getenv (char *); /* Usually in */ #endif @@ -295,6 +307,14 @@ perl_construct(pTHXx) PL_origenviron = environ; #endif + /* Use sysconf(_SC_CLK_TCK) if available, if not + * available or if the sysconf() fails, use the HZ. */ +#if defined(HAS_SYSCONF) && defined(_SC_CLK_TCK) + PL_clocktick = sysconf(_SC_CLK_TCK); + if (PL_clocktick <= 0) +#endif + PL_clocktick = HZ; + ENTER; } diff --git a/perlapi.h b/perlapi.h index ddeeab3..7aa9592 100644 --- a/perlapi.h +++ b/perlapi.h @@ -150,6 +150,8 @@ END_EXTERN_C #define PL_checkav (*Perl_Icheckav_ptr(aTHX)) #undef PL_checkav_save #define PL_checkav_save (*Perl_Icheckav_save_ptr(aTHX)) +#undef PL_clocktick +#define PL_clocktick (*Perl_Iclocktick_ptr(aTHX)) #undef PL_collation_ix #define PL_collation_ix (*Perl_Icollation_ix_ptr(aTHX)) #undef PL_collation_name diff --git a/pp_sys.c b/pp_sys.c index 54699c8..9f15b0e 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -4351,26 +4351,6 @@ PP(pp_time) RETURN; } -/* XXX The POSIX name is CLK_TCK; it is to be preferred - to HZ. Probably. For now, assume that if the system - defines HZ, it does so correctly. (Will this break - on VMS?) - Probably we ought to use _sysconf(_SC_CLK_TCK), if - it's supported. --AD 9/96. -*/ - -#ifdef __BEOS__ -# define HZ 1000000 -#endif - -#ifndef HZ -# ifdef CLK_TCK -# define HZ CLK_TCK -# else -# define HZ 60 -# endif -#endif - PP(pp_tms) { #ifdef HAS_TIMES @@ -4384,11 +4364,11 @@ PP(pp_tms) /* is returned. */ #endif - PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_utime)/HZ))); + PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_utime)/(NV)PL_clocktick))); if (GIMME == G_ARRAY) { - PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_stime)/HZ))); - PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_cutime)/HZ))); - PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_cstime)/HZ))); + PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_stime)/(NV)PL_clocktick))); + PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_cutime)/(NV)PL_clocktick))); + PUSHs(sv_2mortal(newSVnv(((NV)PL_timesbuf.tms_cstime)/(NV)PL_clocktick))); } RETURN; #else