[Mesa-dev] [PATCH] gallium/u_queue: add optional cleanup callback

Rob Clark robdclark at gmail.com
Wed Jul 13 16:28:05 UTC 2016


Adds a second optional cleanup callback, called after the fence is
signaled.  This is needed if, for example, the queue has the last
reference to the object that embeds the util_queue_fence.  In this
case we cannot drop the ref in the main callback, since that would
result in the fence being destroyed before it is signaled.

Signed-off-by: Rob Clark <robdclark at gmail.com>
---
Maybe adding util_queue_add_job2() is a bit overkill.. although I
think Marek has some in-flight stuff using u_queue, so maybe this
approach is less conflicty?

 src/gallium/auxiliary/util/u_queue.c | 12 ++++++++----
 src/gallium/auxiliary/util/u_queue.h | 21 +++++++++++++++++----
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/src/gallium/auxiliary/util/u_queue.c b/src/gallium/auxiliary/util/u_queue.c
index ac3afa1..74f6a67 100644
--- a/src/gallium/auxiliary/util/u_queue.c
+++ b/src/gallium/auxiliary/util/u_queue.c
@@ -91,6 +91,8 @@ static PIPE_THREAD_ROUTINE(util_queue_thread_func, input)
       if (job.job) {
          job.execute(job.job, thread_index);
          util_queue_fence_signal(job.fence);
+         if (job.cleanup)
+            job.cleanup(job.job, thread_index);
       }
    }
 
@@ -210,10 +212,11 @@ util_queue_fence_destroy(struct util_queue_fence *fence)
 }
 
 void
-util_queue_add_job(struct util_queue *queue,
-                   void *job,
-                   struct util_queue_fence *fence,
-                   util_queue_execute_func execute)
+util_queue_add_job2(struct util_queue *queue,
+                    void *job,
+                    struct util_queue_fence *fence,
+                    util_queue_execute_func execute,
+                    util_queue_execute_func cleanup)
 {
    struct util_queue_job *ptr;
 
@@ -232,6 +235,7 @@ util_queue_add_job(struct util_queue *queue,
    ptr->job = job;
    ptr->fence = fence;
    ptr->execute = execute;
+   ptr->cleanup = cleanup;
    queue->write_idx = (queue->write_idx + 1) % queue->max_jobs;
 
    queue->num_queued++;
diff --git a/src/gallium/auxiliary/util/u_queue.h b/src/gallium/auxiliary/util/u_queue.h
index f70d646..ec9d21b 100644
--- a/src/gallium/auxiliary/util/u_queue.h
+++ b/src/gallium/auxiliary/util/u_queue.h
@@ -50,6 +50,7 @@ struct util_queue_job {
    void *job;
    struct util_queue_fence *fence;
    util_queue_execute_func execute;
+   util_queue_execute_func cleanup;
 };
 
 /* Put this into your context. */
@@ -75,10 +76,22 @@ void util_queue_destroy(struct util_queue *queue);
 void util_queue_fence_init(struct util_queue_fence *fence);
 void util_queue_fence_destroy(struct util_queue_fence *fence);
 
-void util_queue_add_job(struct util_queue *queue,
-                        void *job,
-                        struct util_queue_fence *fence,
-                        util_queue_execute_func execute);
+/* optional cleanup callback is called after fence is signaled: */
+void util_queue_add_job2(struct util_queue *queue,
+                         void *job,
+                         struct util_queue_fence *fence,
+                         util_queue_execute_func execute,
+                         util_queue_execute_func cleanup);
+
+static inline void
+util_queue_add_job(struct util_queue *queue,
+                   void *job,
+                   struct util_queue_fence *fence,
+                   util_queue_execute_func execute)
+{
+   util_queue_add_job2(queue, job, fence, execute, NULL);
+}
+
 void util_queue_job_wait(struct util_queue_fence *fence);
 
 /* util_queue needs to be cleared to zeroes for this to work */
-- 
2.7.4



More information about the mesa-dev mailing list