On some systems it might be preferable to use e.g. CLOCK_BOOTTIME
instead of CLOCK_MONOTONIC, which is also not affected by time
adjustments but includes times when the system was suspended.
pthread_condattr_t condattr;
pthread_condattr_init(&condattr);
#ifdef HAVE_CONDATTR_CLOCK_MONOTONIC
- pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC);
+ pthread_condattr_setclock(&condattr, TIME_CLOCK_ID);
#endif
pthread_cond_init(&this->condvar, &condattr);
pthread_condattr_destroy(&condattr);
* monotonic time source only if it is also supported by pthread. */
timespec_t ts;
- if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0)
+ if (clock_gettime(TIME_CLOCK_ID, &ts) == 0)
{
if (tv)
{
*/
#define TIME_32_BIT_SIGNED_MAX 0x7fffffff
+/**
+ * The clock that should be used for time_monotonic() and conditional variables
+ */
+#ifdef HAVE_CLOCK_GETTIME
+#ifdef HAVE_CONDATTR_CLOCK_MONOTONIC
+/* only can use different clocks if we can set it via attribute */
+#ifndef TIME_CLOCK_ID
+#define TIME_CLOCK_ID CLOCK_MONOTONIC
+#endif
+#else
+#define TIME_CLOCK_ID CLOCK_MONOTONIC
+#endif
+#endif
+
/**
* Handle struct timeval like an own type.
*/