Skip to content
Snippets Groups Projects
Commit 4d18f05b authored by Brad King's avatar Brad King Committed by Kitware Robot
Browse files

Merge topic 'monotonic-time'


749b7506 ProcessUNIX: Use monotonic clock in kwsysProcessTimeGetCurrent() for POSIX

Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !57
parents 239bc737 749b7506
No related branches found
No related tags found
No related merge requests found
......@@ -445,8 +445,13 @@ KWSYS_PLATFORM_C_TEST(KWSYS_C_HAS_PTRDIFF_T
"Checking whether C compiler has ptrdiff_t in stddef.h" DIRECT)
KWSYS_PLATFORM_C_TEST(KWSYS_C_HAS_SSIZE_T
"Checking whether C compiler has ssize_t in unistd.h" DIRECT)
IF(KWSYS_USE_Process)
KWSYS_PLATFORM_C_TEST(KWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC
"Checking whether C compiler has clock_gettime" DIRECT)
ENDIF()
SET_SOURCE_FILES_PROPERTIES(ProcessUNIX.c System.c PROPERTIES
COMPILE_FLAGS "-DKWSYS_C_HAS_PTRDIFF_T=${KWSYS_C_HAS_PTRDIFF_T} -DKWSYS_C_HAS_SSIZE_T=${KWSYS_C_HAS_SSIZE_T}"
COMPILE_FLAGS "-DKWSYS_C_HAS_PTRDIFF_T=${KWSYS_C_HAS_PTRDIFF_T} -DKWSYS_C_HAS_SSIZE_T=${KWSYS_C_HAS_SSIZE_T} -DKWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC=${KWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC}"
)
IF(DEFINED KWSYS_PROCESS_USE_SELECT)
......
......@@ -2026,7 +2026,15 @@ static kwsysProcessTime kwsysProcessTimeGetCurrent(void)
{
kwsysProcessTime current;
kwsysProcessTimeNative current_native;
#if KWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC
struct timespec current_timespec;
clock_gettime(CLOCK_MONOTONIC, &current_timespec);
current_native.tv_sec = current_timespec.tv_sec;
current_native.tv_usec = current_timespec.tv_nsec / 1000;
#else
gettimeofday(&current_native, 0);
#endif
current.tv_sec = (long)current_native.tv_sec;
current.tv_usec = (long)current_native.tv_usec;
return current;
......
......@@ -55,6 +55,21 @@ int KWSYS_PLATFORM_TEST_C_MAIN()
}
#endif
#ifdef TEST_KWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC
#if defined(__APPLE__)
#include <AvailabilityMacros.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101200
#error "clock_gettime not available on macOS < 10.12"
#endif
#endif
#include <time.h>
int KWSYS_PLATFORM_TEST_C_MAIN()
{
struct timespec ts;
return clock_gettime(CLOCK_MONOTONIC, &ts);
}
#endif
#ifdef TEST_KWSYS_C_TYPE_MACROS
char* info_macros =
#if defined(__SIZEOF_SHORT__)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment