summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embedvar.h3
-rw-r--r--intrpvar.h2
-rw-r--r--perl.c20
-rw-r--r--perlapi.h2
-rw-r--r--pp_sys.c28
5 files changed, 31 insertions, 24 deletions
diff --git a/embedvar.h b/embedvar.h
index 1d76394729..dbc4d18fa0 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 a957e5bc29..c64b838a3c 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 393ad4f75b..e04670d900 100644
--- a/perl.c
+++ b/perl.c
@@ -26,6 +26,18 @@ char *nw_get_sitelib(const char *pl);
#include <unistd.h>
#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 <stdlib.h> */
#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 ddeeab3ae9..7aa9592dd3 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 54699c8841..9f15b0e924 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