forked from OSchip/llvm-project
[libc++] Check _LIBCPP_USE_CLOCK_GETTIME before using clock_gettime
The clock_gettime function is available when _POSIX_TIMERS is defined. We check for this and set _LIBCPP_USE_CLOCK_GETTIME accordingly since59b3102739
. But check for _LIBCPP_USE_CLOCK_GETTIME was removed inbabd3aefc9
. As a result, code is now trying to use clock_gettime even on platforms where it is not available and it is causing build failure with newlib. This patch restores the checks to fix this. Differential Revision: https://reviews.llvm.org/D88825
This commit is contained in:
parent
53bf28b80c
commit
f78bb4d84e
|
@ -16,6 +16,10 @@
|
|||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#if __has_include(<sys/time.h>)
|
||||
# include <sys/time.h> // for gettimeofday and timeval
|
||||
#endif
|
||||
|
||||
#if !defined(__APPLE__) && _POSIX_TIMERS > 0
|
||||
# define _LIBCPP_USE_CLOCK_GETTIME
|
||||
#endif
|
||||
|
@ -27,10 +31,6 @@
|
|||
# if _WIN32_WINNT >= _WIN32_WINNT_WIN8
|
||||
# include <winapifamily.h>
|
||||
# endif
|
||||
#else
|
||||
# if !defined(CLOCK_REALTIME)
|
||||
# include <sys/time.h> // for gettimeofday and timeval
|
||||
# endif // !defined(CLOCK_REALTIME)
|
||||
#endif // defined(_LIBCPP_WIN32API)
|
||||
|
||||
#if defined(__ELF__) && defined(_LIBCPP_LINK_RT_LIB)
|
||||
|
@ -74,7 +74,7 @@ system_clock::now() _NOEXCEPT
|
|||
static_cast<__int64>(ft.dwLowDateTime)};
|
||||
return time_point(duration_cast<duration>(d - nt_to_unix_epoch));
|
||||
#else
|
||||
#if defined(CLOCK_REALTIME)
|
||||
#if defined(CLOCK_REALTIME) && defined(_LIBCPP_USE_CLOCK_GETTIME)
|
||||
struct timespec tp;
|
||||
if (0 != clock_gettime(CLOCK_REALTIME, &tp))
|
||||
__throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
|
||||
|
@ -83,7 +83,7 @@ system_clock::now() _NOEXCEPT
|
|||
timeval tv;
|
||||
gettimeofday(&tv, 0);
|
||||
return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec));
|
||||
#endif // CLOCK_REALTIME
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue