[m-rev.] diff: Allow MR_CLOCK_TICKS_PER_SECOND to be defined as CLOCKS_PER_SEC.

Peter Wang novalazy at gmail.com
Wed Oct 7 13:54:57 AEDT 2015


Allow MR_CLOCK_TICKS_PER_SECOND to be defined as CLOCKS_PER_SEC
instead of CLK_TCK.  The latter is an older name that may not be
defined, e.g. by MinGW-w64 headers in some conditions.

runtime/mercury_timing.h:
    As above.

configure.ac:
    Make the test for time profiling support match the code in
    mercury_timing.h

library/time.m:
    Prevent a compilation error when MR_CLOCK_TICKS_PER_SECOND
    is undefined.
---
 configure.ac             | 25 +++++++++++++++++--------
 library/time.m           |  2 +-
 runtime/mercury_timing.h |  5 ++++-
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4588106..f3fbe6e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2879,9 +2879,9 @@ CC="$save_CC"
 AC_MSG_CHECKING(whether we can support time profiling on this system)
 AC_CACHE_VAL(mercury_cv_profiling,
 AC_TRY_CPP([
-/* The following code comes from runtime/mercury_prof.c */
-#include    <unistd.h>
+/* The following code comes from runtime/mercury_timing.h */
 #include    <errno.h>
+#include    <limits.h>
 #include    <string.h>
 #include    <signal.h>
 
@@ -2889,18 +2889,27 @@ AC_TRY_CPP([
 #include    <sys/param.h>
 #endif
 
+#ifdef MR_HAVE_UNISTD_H
+  #include  <unistd.h>
+#endif
+
 #ifdef MR_HAVE_SYS_TIME_H
 #include    <sys/time.h>
 #endif
 
-/*
-** If HZ is not defined, we may be able to use sysconf(_SC_CLK_TCK) instead.
-*/
-#if !defined(HZ) && defined(MR_HAVE_SYSCONF) && defined(_SC_CLK_TCK)
-#define HZ ((int)sysconf(_SC_CLK_TCK))
+#ifdef HZ
+  #define MR_CLOCK_TICKS_PER_SECOND	HZ
+#elif defined(MR_HAVE_SYSCONF) && defined(_SC_CLK_TCK)
+  #define MR_CLOCK_TICKS_PER_SECOND	((int) sysconf(_SC_CLK_TCK))
+#elif defined(CLOCKS_PER_SEC)
+  #define MR_CLOCK_TICKS_PER_SECOND	CLOCKS_PER_SEC
+#elif defined(CLK_TCK)
+  #define MR_CLOCK_TICKS_PER_SECOND	CLK_TCK
+#else
+  /* just leave it undefined */
 #endif
 
-#if !defined(HZ) || !defined(SIGPROF) || !defined(MR_HAVE_SETITIMER)
+#if !defined(MR_CLOCK_TICKS_PER_SECOND) || !defined(SIGPROF) || !defined(MR_HAVE_SETITIMER)
 #error "Time profiling not supported on this system"
 #endif
 ], [mercury_cv_profiling=yes], [mercury_cv_profiling=no]))
diff --git a/library/time.m b/library/time.m
index 76ef2b6..1b36417 100644
--- a/library/time.m
+++ b/library/time.m
@@ -354,7 +354,7 @@ time.times(Tms, Result, !IO) :-
     CUt = (MR_Integer) t.tms_cutime;
     CSt = (MR_Integer) t.tms_cstime;
 #else
-  #ifdef MR_WIN32
+  #if defined(MR_WIN32) && defined(MR_CLOCK_TICKS_PER_SECOND)
     HANDLE hProcess;
     FILETIME ftCreation, ftExit, ftKernel, ftUser;
     timeKernel user, kernel;
diff --git a/runtime/mercury_timing.h b/runtime/mercury_timing.h
index f2a4dbc..c32da0e 100644
--- a/runtime/mercury_timing.h
+++ b/runtime/mercury_timing.h
@@ -29,12 +29,15 @@
 ** `HZ' is the number of clock ticks per second.
 ** It is used when converting a clock_t value to a time in seconds.
 ** It may be defined by <sys/time.h>, but if it is not defined there,
-** we may be able to use `sysconf(_SC_CLK_TCK)' or CLK_TCK instead.
+** we may be able to use `sysconf(_SC_CLK_TCK)' or CLOCKS_PER_SEC or
+** CLK_TCK instead.
 */
 #ifdef HZ
   #define MR_CLOCK_TICKS_PER_SECOND	HZ
 #elif defined(MR_HAVE_SYSCONF) && defined(_SC_CLK_TCK)
   #define MR_CLOCK_TICKS_PER_SECOND	((int) sysconf(_SC_CLK_TCK))
+#elif defined(CLOCKS_PER_SEC)
+  #define MR_CLOCK_TICKS_PER_SECOND	CLOCKS_PER_SEC
 #elif defined(CLK_TCK)
   #define MR_CLOCK_TICKS_PER_SECOND	CLK_TCK
 #else
-- 
2.1.2



More information about the reviews mailing list