gallivm: Remove NULL check of pointer that can't be NULL.
[mesa.git] / src / gallium / auxiliary / util / u_time.h
index 35d97d16c739758674fd3f18eeb0224e5a8fecb4..15899c2c884064d09ce801b59a38bb3301a42259 100644 (file)
 
 #include "pipe/p_config.h"
 
-#if defined(PIPE_OS_LINUX)
-#include <time.h> /* timeval */
-#include <unistd.h> /* usleep */
-#endif
+#include "os/os_time.h"
 
 #include "pipe/p_compiler.h"
 
@@ -58,43 +55,92 @@ extern "C" {
  */
 struct util_time 
 {
-#if defined(PIPE_OS_LINUX)
-   struct timeval tv;
-#else
    int64_t counter;
-#endif
 };
    
 
-void 
-util_time_get(struct util_time *t);
+PIPE_DEPRECATED
+static INLINE void
+util_time_get(struct util_time *t)
+{
+   t->counter = os_time_get();
+}
+
 
-void 
+/**
+ * Return t2 = t1 + usecs
+ */
+PIPE_DEPRECATED
+static INLINE void
 util_time_add(const struct util_time *t1,
               int64_t usecs,
-              struct util_time *t2);
+              struct util_time *t2)
+{
+   t2->counter = t1->counter + usecs;
+}
 
-uint64_t
-util_time_micros( void );
 
-int64_t
+/**
+ * Return difference between times, in microseconds
+ */
+PIPE_DEPRECATED
+static INLINE int64_t
 util_time_diff(const struct util_time *t1, 
-               const struct util_time *t2);
+               const struct util_time *t2)
+{
+   return t2->counter - t1->counter;
+}
+
+
+/**
+ * Compare two time values.
+ *
+ * Not publicly available because it does not take in account wrap-arounds.
+ * Use util_time_timeout instead.
+ */
+static INLINE int
+_util_time_compare(const struct util_time *t1,
+                   const struct util_time *t2)
+{
+   if (t1->counter < t2->counter)
+      return -1;
+   else if(t1->counter > t2->counter)
+      return 1;
+   else
+      return 0;
+}
+
 
 /**
  * Returns non-zero when the timeout expires.
  */
-boolean 
+PIPE_DEPRECATED
+static INLINE boolean
 util_time_timeout(const struct util_time *start, 
                   const struct util_time *end,
-                  const struct util_time *curr);
+                  const struct util_time *curr)
+{
+   return os_time_timeout(start->counter, end->counter, curr->counter);
+}
 
-#if defined(PIPE_OS_LINUX)
-#define util_time_sleep usleep
-#else
-void
-util_time_sleep(unsigned usecs);
-#endif
+
+/**
+ * Return current time in microseconds
+ */
+PIPE_DEPRECATED
+static INLINE int64_t
+util_time_micros(void)
+{
+   return os_time_get();
+}
+
+
+PIPE_DEPRECATED
+static INLINE void
+util_time_sleep(int64_t usecs)
+{
+   os_time_sleep(usecs);
+}
 
 
 #ifdef __cplusplus