[Mesa-dev] [PATCH] vulkan/wsi: handle UINT64_MAX timeout correctly.

Dave Airlie airlied at gmail.com
Tue Aug 1 23:14:16 UTC 2017


From: Dave Airlie <airlied at redhat.com>

The spec says
"If timeout is UINT64_MAX, the function will not return until an image is acquired from the presentation engine."

Now I know UINT64_MAX is probably heat death of the universe,
but this changes the code to avoid calculating things in that
case and uses the pthread_cond_wait interface instead.

(just noticed in passing).
Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 src/vulkan/wsi/wsi_common_queue.h | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/src/vulkan/wsi/wsi_common_queue.h b/src/vulkan/wsi/wsi_common_queue.h
index 6d489cb..21b2cb0 100644
--- a/src/vulkan/wsi/wsi_common_queue.h
+++ b/src/vulkan/wsi/wsi_common_queue.h
@@ -113,23 +113,30 @@ wsi_queue_pull(struct wsi_queue *queue, uint32_t *index, uint64_t timeout)
 
    pthread_mutex_lock(&queue->mutex);
 
-   struct timespec now;
-   clock_gettime(CLOCK_MONOTONIC, &now);
-
-   uint32_t abs_nsec = now.tv_nsec + timeout % NSEC_PER_SEC;
-   uint64_t abs_sec = now.tv_sec + (abs_nsec / NSEC_PER_SEC) +
-                      (timeout / NSEC_PER_SEC);
-   abs_nsec %= NSEC_PER_SEC;
-
-   /* Avoid roll-over in tv_sec on 32-bit systems if the user provided timeout
-    * is UINT64_MAX
-    */
-   struct timespec abstime;
-   abstime.tv_nsec = abs_nsec;
-   abstime.tv_sec = MIN2(abs_sec, INT_TYPE_MAX(abstime.tv_sec));
+   struct timespec abstime = {0};
+   bool block = false;
+   if (timeout != UINT64_MAX) {
+      struct timespec now;
+      clock_gettime(CLOCK_MONOTONIC, &now);
+
+      uint32_t abs_nsec = now.tv_nsec + timeout % NSEC_PER_SEC;
+      uint64_t abs_sec = now.tv_sec + (abs_nsec / NSEC_PER_SEC) +
+         (timeout / NSEC_PER_SEC);
+      abs_nsec %= NSEC_PER_SEC;
+
+      /* Avoid roll-over in tv_sec on 32-bit systems if the user provided timeout
+       * is UINT64_MAX
+       */
+      abstime.tv_nsec = abs_nsec;
+      abstime.tv_sec = MIN2(abs_sec, INT_TYPE_MAX(abstime.tv_sec));
+   } else
+      block = true;
 
    while (u_vector_length(&queue->vector) == 0) {
-      ret = pthread_cond_timedwait(&queue->cond, &queue->mutex, &abstime);
+      if (block)
+         ret = pthread_cond_wait(&queue->cond, &queue->mutex);
+      else
+         ret = pthread_cond_timedwait(&queue->cond, &queue->mutex, &abstime);
       if (ret == 0) {
          continue;
       } else if (ret == ETIMEDOUT) {
-- 
2.9.4



More information about the mesa-dev mailing list