#include "pipe/p_compiler.h"
-#ifdef __cplusplus
+#ifdef __cplusplus
extern "C" {
#endif
/*
* Get the current time in microseconds from an unknown base.
*/
-static INLINE int64_t
-os_time_get(void) {
- return os_time_get_nano() * 1000;
+static inline int64_t
+os_time_get(void)
+{
+ return os_time_get_nano() / 1000;
}
*
* Returns true if the current time has elapsed beyond the specified interval.
*/
-static INLINE boolean
+static inline boolean
os_time_timeout(int64_t start,
int64_t end,
int64_t curr)
{
- if(start <= end)
+ if (start <= end)
return !(start <= curr && curr < end);
else
return !((start <= curr) || (curr < end));
}
-#ifdef __cplusplus
+/**
+ * Convert a relative timeout in nanoseconds into an absolute timeout,
+ * in other words, it returns current time + timeout.
+ * os_time_get_nano() must be monotonic.
+ * PIPE_TIMEOUT_INFINITE is passed through unchanged. If the calculation
+ * overflows, PIPE_TIMEOUT_INFINITE is returned.
+ */
+int64_t
+os_time_get_absolute_timeout(uint64_t timeout);
+
+
+/**
+ * Wait until the variable at the given memory location is zero.
+ *
+ * \param var variable
+ * \param timeout timeout in ns, can be anything from 0 (no wait) to
+ * PIPE_TIME_INFINITE (wait forever)
+ * \return true if the variable is zero
+ */
+bool
+os_wait_until_zero(volatile int *var, uint64_t timeout);
+
+
+/**
+ * Wait until the variable at the given memory location is zero.
+ * The timeout is the absolute time when the waiting should stop. If it is
+ * less than or equal to the current time, it only returns the status and
+ * doesn't wait. PIPE_TIME_INFINITE waits forever. This requires that
+ * os_time_get_nano is monotonic.
+ *
+ * \param var variable
+ * \param timeout the time in ns when the waiting should stop
+ * \return true if the variable is zero
+ */
+bool
+os_wait_until_zero_abs_timeout(volatile int *var, int64_t timeout);
+
+#ifdef __cplusplus
}
#endif