]> granicus.if.org Git - check/commitdiff
change check for valid clockid
authorbrarcher <brarcher@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Thu, 24 Oct 2013 02:14:55 +0000 (02:14 +0000)
committerbrarcher <brarcher@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Thu, 24 Oct 2013 02:14:55 +0000 (02:14 +0000)
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

src/check.c

index 76e6c5eaa7bb5dc1d261861d98e28688eb931ca7..d7806d705fafdfa5dabe0c3bf3170295cc2077c3 100644 (file)
@@ -473,15 +473,27 @@ clockid_t check_get_clockid()
 
        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;