Merge pull request #1995 from nghttp2/check-clock-monotonic

Check whether CLOCK_MONOTONIC is declared
This commit is contained in:
Tatsuhiro Tsujikawa
2023-11-06 19:39:06 +09:00
committed by GitHub
4 changed files with 15 additions and 3 deletions

View File

@@ -334,6 +334,8 @@ if(NOT HAVE_DECL_INITGROUPS AND HAVE_UNISTD_H)
endif()
endif()
check_symbol_exists(CLOCK_MONOTONIC "time.h" HAVE_DECL_CLOCK_MONOTONIC)
set(WARNCFLAGS)
set(WARNCXXFLAGS)
if(CMAKE_C_COMPILER_ID MATCHES "MSVC")

View File

@@ -43,6 +43,9 @@
/* Define to 1 if you have the `initgroups` function. */
#cmakedefine01 HAVE_DECL_INITGROUPS
/* Define to 1 if you have the `CLOCK_MONOTONIC` defined. */
#cmakedefine01 HAVE_DECL_CLOCK_MONOTONIC
/* Define to 1 to enable debug output. */
#cmakedefine DEBUGBUILD 1

View File

@@ -985,6 +985,10 @@ AC_CHECK_DECLS([initgroups], [], [], [[
#include <grp.h>
]])
AC_CHECK_DECLS([CLOCK_MONOTONIC], [], [], [[
#include <time.h>
]])
save_CFLAGS=$CFLAGS
save_CXXFLAGS=$CXXFLAGS

View File

@@ -46,7 +46,8 @@ static uint64_t time_now_sec(void) {
#if defined(HAVE_GETTICKCOUNT64) && !defined(__CYGWIN__)
uint64_t nghttp2_time_now_sec(void) { return GetTickCount64() / 1000; }
#elif defined(HAVE_CLOCK_GETTIME)
#elif defined(HAVE_CLOCK_GETTIME) && defined(HAVE_DECL_CLOCK_MONOTONIC) && \
HAVE_DECL_CLOCK_MONOTONIC
uint64_t nghttp2_time_now_sec(void) {
struct timespec tp;
int rv = clock_gettime(CLOCK_MONOTONIC, &tp);
@@ -57,6 +58,8 @@ uint64_t nghttp2_time_now_sec(void) {
return (uint64_t)tp.tv_sec;
}
#else /* (!HAVE_CLOCK_GETTIME || __CYGWIN__) && !HAVE_GETTICKCOUNT64 */
#else /* (!HAVE_CLOCK_GETTIME || !HAVE_DECL_CLOCK_MONOTONIC) && \
(!HAVE_GETTICKCOUNT64 || __CYGWIN__)) */
uint64_t nghttp2_time_now_sec(void) { return time_now_sec(); }
#endif /* (!HAVE_CLOCK_GETTIME || __CYGWIN__) && !HAVE_GETTICKCOUNT64 */
#endif /* (!HAVE_CLOCK_GETTIME || !HAVE_DECL_CLOCK_MONOTONIC) && \
(!HAVE_GETTICKCOUNT64 || __CYGWIN__)) */