]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
time: Allow using different clocks
authorTobias Brunner <tobias@strongswan.org>
Thu, 19 Mar 2020 13:19:22 +0000 (14:19 +0100)
committerTobias Brunner <tobias@strongswan.org>
Tue, 2 Jun 2020 11:57:37 +0000 (13:57 +0200)
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.

src/libstrongswan/threading/mutex.c
src/libstrongswan/utils/utils/time.c
src/libstrongswan/utils/utils/time.h

index 70db30f218c1481b596dc52ce12a37997b383a52..888f11df0797879b4033fd426b11442e97e0277c 100644 (file)
@@ -337,7 +337,7 @@ condvar_t *condvar_create(condvar_type_t type)
                                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);
index d96c918dacc33d04b816439c45ebf970d4476c9d..c1e055e912b7cd942567d3d1fea73d3476ea3bb4 100644 (file)
@@ -52,7 +52,7 @@ time_t time_monotonic(timeval_t *tv)
         * 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)
                {
index 2e210fbefd25ae2b243f0f3a1fc5a6b37b2d0a29..9fac77729a9071e3f875109b5d92b05bf80cfa2c 100644 (file)
  */
 #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.
  */