katie_check_function(getgrgid_r "grp.h")
katie_check_function(nl_langinfo "langinfo.h")
katie_check_function(getaddrinfo "netdb.h")
+katie_check_function(clock_gettime "time.h")
# XSI/POSIX.1-2001
katie_check_function(strerror_r "string.h")
# SUSv2
static qint64 getticks()
{
-#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0)
- clockid_t clockId;
-
-#ifndef _POSIX_THREAD_CPUTIME
- clockId = CLOCK_REALTIME;
-#elif (_POSIX_THREAD_CPUTIME-0 <= 0)
- // if we don't have CLOCK_THREAD_CPUTIME_ID, we have to just use elapsed realtime instead
- clockId = CLOCK_REALTIME;
+#ifdef QT_HAVE_CLOCK_GETTIME
+#ifdef CLOCK_REALTIME_COARSE // Linux specific
+ clockid_t clockId = CLOCK_REALTIME_COARSE;
+#else
+ clockid_t clockId = CLOCK_REALTIME;
+#endif
-# if (_POSIX_THREAD_CPUTIME-0 == 0)
+#if defined(_SC_THREAD_CPUTIME) && defined(CLOCK_THREAD_CPUTIME_ID)
// detect availablility of CLOCK_THREAD_CPUTIME_ID,
// sysconf() will return either -1 or _POSIX_VERSION (don't care about thread races here)
static long useThreadCpuTime = sysconf(_SC_THREAD_CPUTIME);
if (useThreadCpuTime != -1)
clockId = CLOCK_THREAD_CPUTIME_ID;
-# endif
-#else
- clockId = CLOCK_THREAD_CPUTIME_ID;
#endif
struct timespec ts;
- if (clock_gettime(clockId, &ts) == -1)
+ if (::clock_gettime(clockId, &ts) == -1)
return 0;
return (ts.tv_sec * 1000000000) + ts.tv_nsec;
#else
-
// no clock_gettime(), fall back to wall time
struct timeval tv;
- gettimeofday(&tv, Q_NULLPTR);
+ ::gettimeofday(&tv, Q_NULLPTR);
return (tv.tv_sec * 1000000) + tv.tv_usec;
-
-#endif
+#endif // QT_HAVE_CLOCK_GETTIME
}
static inline double elapsed(qint64 after, qint64 before)
#cmakedefine QT_NO_CAST_FROM_BYTEARRAY
#cmakedefine QT_NO_CAST_TO_ASCII
#cmakedefine QT_NO_CLIPBOARD
-#cmakedefine QT_NO_CLOCK_MONOTONIC
#cmakedefine QT_NO_CODEC_FOR_C_STRINGS
#cmakedefine QT_NO_COLORDIALOG
#cmakedefine QT_NO_COLORNAMES
QT_BEGIN_NAMESPACE
-#ifndef QT_NO_CLOCK_MONOTONIC
-# if defined(_SC_MONOTONIC_CLOCK)
+#if defined(QT_HAVE_CLOCK_GETTIME) && defined(_SC_MONOTONIC_CLOCK)
static const bool monotonicClockAvailable = (sysconf(_SC_MONOTONIC_CLOCK) >= 200112L);
-# elif (_POSIX_MONOTONIC_CLOCK-0 != 0)
+#elif defined(QT_HAVE_CLOCK_GETTIME)
static const bool monotonicClockAvailable = (_POSIX_MONOTONIC_CLOCK > 0);
-# else
-# define QT_NO_CLOCK_MONOTONIC
-# endif
#endif
static inline qint64 fractionAdjustment()
{
-#ifndef QT_NO_CLOCK_MONOTONIC
+#ifdef QT_HAVE_CLOCK_GETTIME
if (Q_LIKELY(monotonicClockAvailable)) {
// the monotonic timer is measured in nanoseconds
// 1 ms = 1000000 ns
bool QElapsedTimer::isMonotonic()
{
-#ifndef QT_NO_CLOCK_MONOTONIC
+#ifdef QT_HAVE_CLOCK_GETTIME
return monotonicClockAvailable;
#else
return false;
QElapsedTimer::ClockType QElapsedTimer::clockType()
{
-#ifndef QT_NO_CLOCK_MONOTONIC
+#ifdef QT_HAVE_CLOCK_GETTIME
if (Q_LIKELY(monotonicClockAvailable)) {
return QElapsedTimer::MonotonicClock;
}
static inline void do_gettime(qint64 *sec, qint64 *frac)
{
-#ifndef QT_NO_CLOCK_MONOTONIC
+#ifdef QT_HAVE_CLOCK_GETTIME
if (Q_LIKELY(monotonicClockAvailable)) {
timespec ts;
#ifdef CLOCK_MONOTONIC_COARSE // Linux specific
- clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
+ ::clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
#else
- clock_gettime(CLOCK_MONOTONIC, &ts);
+ ::clock_gettime(CLOCK_MONOTONIC, &ts);
#endif
*sec = ts.tv_sec;
*frac = ts.tv_nsec;
timeval tv;
tv.tv_sec = sec;
-#ifndef QT_NO_CLOCK_MONOTONIC
+#ifdef QT_HAVE_CLOCK_GETTIME
if (Q_LIKELY(monotonicClockAvailable))
tv.tv_usec = frac / 1000;
else
do_gettime(&sec, &frac);
sec = sec - t1;
frac = frac - t2;
-#ifndef QT_NO_CLOCK_MONOTONIC
+#ifdef QT_HAVE_CLOCK_GETTIME
if (Q_UNLIKELY(!monotonicClockAvailable))
frac *= 1000;
#endif