};
/**
- * struct timeabs - an absolue time.
+ * struct timeabs - an absolute time.
* @ts: the actual timespec value.
*
* For example, Midnight UTC January 1st, 1970: ts.tv_sec = 0, ts.tv_nsec = 0
*/
#if HAVE_CLOCK_GETTIME && defined(CLOCK_MONOTONIC)
#define TIME_HAVE_MONOTONIC 1
+#else
+#define TIME_HAVE_MONOTONIC 0
#endif
struct timespec time_check_(struct timespec in, const char *abortstr);
return time_greater_(a.ts, b.ts);
}
+/**
+ * timemono_after - is a after b?
+ * @a: one monotonic time.
+ * @b: another monotonic time.
+ *
+ * Example:
+ * static bool timed_out(const struct timemono *start)
+ * {
+ * #define TIMEOUT time_from_msec(1000)
+ * return timemono_after(time_mono(), timemono_add(*start, TIMEOUT));
+ * }
+ */
+static inline bool timemono_after(struct timemono a, struct timemono b)
+{
+ return time_greater_(a.ts, b.ts);
+}
+
static inline bool time_less_(struct timespec a, struct timespec b)
{
if (TIME_CHECK(a).tv_sec < TIME_CHECK(b).tv_sec)
return time_less_(a.ts, b.ts);
}
+/**
+ * timemono_before - is a before b?
+ * @a: one monotonic time.
+ * @b: another monotonic time.
+ *
+ * Example:
+ * static bool still_valid(const struct timemono *start)
+ * {
+ * #define TIMEOUT time_from_msec(1000)
+ * return timemono_before(time_mono(), timemono_add(*start, TIMEOUT));
+ * }
+ */
+static inline bool timemono_before(struct timemono a, struct timemono b)
+{
+ return time_less_(a.ts, b.ts);
+}
+
/**
* time_less - is a before b?
* @a: one relative time.
return t;
}
+/**
+ * timemono_sub - subtract a relative time from a monotonic time
+ * @mono: the monotonic time.
+ * @rel: the relative time.
+ *
+ * This returns a well formed struct timemono of @mono - @rel.
+ *
+ * Example:
+ * // We do one every second.
+ * static struct timemono previous_time(void)
+ * {
+ * return timemono_sub(time_mono(), time_from_msec(1000));
+ * }
+ */
+static inline struct timemono timemono_sub(struct timemono mono, struct timerel rel)
+{
+ struct timemono t;
+
+ t.ts = time_sub_(mono.ts, rel.ts);
+ return t;
+}
+
+
static inline struct timespec time_add_(struct timespec a, struct timespec b)
{
struct timespec sum;
* @div: number to divide it by.
*
* Example:
+ * #include <sys/wait.h>
+ *
* // How long does it take to do a fork?
* static struct timerel forking_time(void)
* {