cygwin does not support CLOCK_MONOTONIC. However, a call to
clock_gettime(CLOCK_MONOTONIC, ...) will pass, whereas
a timer_create(CLOCK_MONOTONIC, ...) will fail. Use the
timer_create() call for the check instead.
However, be careful to only make the check if librt is available,
otherwise it is a waste. Or worse, if librt and alarm() are
unavailable, a timer_delete() will result in an assert(0).
git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@847
64e312b2-a51f-0410-8e61-
82d0ca0eb02a
if(clockid == -1)
{
- struct timespec ts;
- if(clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
+/*
+ * Only check if we have librt available. Otherwise, the clockid
+ * will be ignored anyway, as the clock_gettime() and
+ * timer_create() functions will be re-implemented in libcompat.
+ * Worse, if librt and alarm() are unavailable, this check
+ * will result in an assert(0).
+ */
+#ifdef HAVE_LIBRT
+ timer_t timerid;
+ if(timer_create(CLOCK_MONOTONIC, NULL, &timerid) == 0)
{
+ timer_delete(timerid);
clockid = CLOCK_MONOTONIC;
}
else
{
clockid = CLOCK_REALTIME;
}
+#else
+ clockid = CLOCK_MONOTONIC;
+#endif
}
return clockid;