Module: Mesa
Branch: master
Commit: addfe49fdde0402055b5b9d6f2846cb2f37954af
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=addfe49fdde0402055b5b9d6f2846cb2f37954af

Author: James Park <[email protected]>
Date:   Thu Nov 12 23:08:17 2020 -0800

radv: Fix radv_queue_init failure handling

Do not destroy pending_mutex or thread_mutex if uninitialized.

Do not use or destroy thread_cond if uninitialized.

Reviewed-by: Samuel Pitoiset <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7599>

---

 src/amd/vulkan/radv_device.c  | 27 +++++++++++++++------------
 src/amd/vulkan/radv_private.h |  1 +
 2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index 8643367b953..ebe85e28207 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -2353,7 +2353,6 @@ radv_queue_init(struct radv_device *device, struct 
radv_queue *queue,
        queue->queue_idx = idx;
        queue->priority = radv_get_queue_global_priority(global_priority);
        queue->flags = flags;
-       queue->hw_ctx = NULL;
 
        VkResult result = device->ws->ctx_create(device->ws, queue->priority, 
&queue->hw_ctx);
        if (result != VK_SUCCESS)
@@ -2363,11 +2362,10 @@ radv_queue_init(struct radv_device *device, struct 
radv_queue *queue,
        pthread_mutex_init(&queue->pending_mutex, NULL);
 
        pthread_mutex_init(&queue->thread_mutex, NULL);
-       queue->thread_submission = NULL;
-       queue->thread_running = queue->thread_exit = false;
        result = radv_create_pthread_cond(&queue->thread_cond);
        if (result != VK_SUCCESS)
                return vk_error(device->instance, result);
+       queue->cond_created = true;
 
        return VK_SUCCESS;
 }
@@ -2375,17 +2373,22 @@ radv_queue_init(struct radv_device *device, struct 
radv_queue *queue,
 static void
 radv_queue_finish(struct radv_queue *queue)
 {
-       if (queue->thread_running) {
-               p_atomic_set(&queue->thread_exit, true);
-               pthread_cond_broadcast(&queue->thread_cond);
-               pthread_join(queue->submission_thread, NULL);
-       }
-       pthread_cond_destroy(&queue->thread_cond);
-       pthread_mutex_destroy(&queue->pending_mutex);
-       pthread_mutex_destroy(&queue->thread_mutex);
+       if (queue->hw_ctx) {
+               if (queue->cond_created) {
+                       if (queue->thread_running) {
+                               p_atomic_set(&queue->thread_exit, true);
+                               pthread_cond_broadcast(&queue->thread_cond);
+                               pthread_join(queue->submission_thread, NULL);
+                       }
+
+                       pthread_cond_destroy(&queue->thread_cond);
+               }
+
+               pthread_mutex_destroy(&queue->pending_mutex);
+               pthread_mutex_destroy(&queue->thread_mutex);
 
-       if (queue->hw_ctx)
                queue->device->ws->ctx_destroy(queue->hw_ctx);
+       }
 
        if (queue->initial_full_flush_preamble_cs)
                
queue->device->ws->cs_destroy(queue->initial_full_flush_preamble_cs);
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index b13ef9609c4..44c9bf659e7 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -735,6 +735,7 @@ struct radv_queue {
        pthread_t submission_thread;
        bool thread_exit;
        bool thread_running;
+       bool cond_created;
 };
 
 struct radv_bo_list {

_______________________________________________
mesa-commit mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-commit

Reply via email to