util/u_queue: skip util_queue_finish if num_threads is 0
authorMarek Olšák <marek.olsak@amd.com>
Thu, 24 Oct 2019 01:01:38 +0000 (21:01 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 24 Oct 2019 01:11:17 +0000 (21:11 -0400)
This fixes a deadlock in pthread_barrier_destroy.

Cc: 19.1 19.2 <mesa-stable@lists.freedesktop.org>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/util/u_queue.c

index ca72968053a1fba7ff1f502d60dbe24755d70344..47b8dcd407c0f747be2486b699091a1be7aa0857 100644 (file)
@@ -647,6 +647,13 @@ util_queue_finish(struct util_queue *queue)
     * wait for it exclusively.
     */
    mtx_lock(&queue->finish_lock);
+
+   /* The number of threads can be changed to 0, e.g. by the atexit handler. */
+   if (!queue->num_threads) {
+      mtx_unlock(&queue->finish_lock);
+      return;
+   }
+
    fences = malloc(queue->num_threads * sizeof(*fences));
    util_barrier_init(&barrier, queue->num_threads);