Skip to content

Commit a6c3c63

Browse files
reubenhwkgitster
authored andcommitted
configure.ac: check for clock_gettime and CLOCK_MONOTONIC
Set or clear Makefile variables HAVE_CLOCK_GETTIME and HAVE_CLOCK_MONOTONIC based upon results of the checks (overriding default values from config.mak.uname). CLOCK_MONOTONIC isn't available on RHEL3, but there are still RHEL3 systems being used in production. Signed-off-by: Reuben Hawkins <[email protected]> Reviewed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8bd2c97 commit a6c3c63

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ all::
343343
# return NULL when it receives a bogus time_t.
344344
#
345345
# Define HAVE_CLOCK_GETTIME if your platform has clock_gettime in librt.
346+
#
347+
# Define HAVE_CLOCK_MONOTONIC if your platform has CLOCK_MONOTONIC in librt.
346348

347349
GIT-VERSION-FILE: FORCE
348350
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1402,6 +1404,10 @@ ifdef HAVE_CLOCK_GETTIME
14021404
EXTLIBS += -lrt
14031405
endif
14041406

1407+
ifdef HAVE_CLOCK_MONOTONIC
1408+
BASIC_CFLAGS += -DHAVE_CLOCK_MONOTONIC
1409+
endif
1410+
14051411
ifeq ($(TCLTK_PATH),)
14061412
NO_TCLTK = NoThanks
14071413
endif

config.mak.uname

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ ifeq ($(uname_S),Linux)
3535
LIBC_CONTAINS_LIBINTL = YesPlease
3636
HAVE_DEV_TTY = YesPlease
3737
HAVE_CLOCK_GETTIME = YesPlease
38+
HAVE_CLOCK_MONOTONIC = YesPlease
3839
endif
3940
ifeq ($(uname_S),GNU/kFreeBSD)
4041
HAVE_ALLOCA_H = YesPlease

configure.ac

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,28 @@ AC_CHECK_LIB([iconv], [locale_charset],
947947
[CHARSET_LIB=-lcharset])])
948948
GIT_CONF_SUBST([CHARSET_LIB])
949949
#
950+
# Define HAVE_CLOCK_GETTIME=YesPlease if clock_gettime is available.
951+
GIT_CHECK_FUNC(clock_gettime,
952+
[HAVE_CLOCK_GETTIME=YesPlease],
953+
[HAVE_CLOCK_GETTIME=])
954+
GIT_CONF_SUBST([HAVE_CLOCK_GETTIME])
955+
956+
AC_DEFUN([CLOCK_MONOTONIC_SRC], [
957+
AC_LANG_PROGRAM([[
958+
#include <time.h>
959+
clockid_t id = CLOCK_MONOTONIC;
960+
]])])
961+
962+
#
963+
# Define HAVE_CLOCK_MONOTONIC=YesPlease if CLOCK_MONOTONIC is available.
964+
AC_MSG_CHECKING([for CLOCK_MONOTONIC])
965+
AC_COMPILE_IFELSE([CLOCK_MONOTONIC_SRC],
966+
[AC_MSG_RESULT([yes])
967+
HAVE_CLOCK_MONOTONIC=YesPlease],
968+
[AC_MSG_RESULT([no])
969+
HAVE_CLOCK_MONOTONIC=])
970+
GIT_CONF_SUBST([HAVE_CLOCK_MONOTONIC])
971+
#
950972
# Define NO_SETITIMER if you don't have setitimer.
951973
GIT_CHECK_FUNC(setitimer,
952974
[NO_SETITIMER=],

trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ int trace_want(struct trace_key *key)
322322
return !!get_trace_fd(key);
323323
}
324324

325-
#ifdef HAVE_CLOCK_GETTIME
325+
#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_CLOCK_MONOTONIC)
326326

327327
static inline uint64_t highres_nanos(void)
328328
{

0 commit comments

Comments
 (0)