From b7317b6ce0943076a786e7151c561e22412f892c Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Mon, 6 Aug 2018 20:34:24 -0400 Subject: util/queue: hold a lock when reading num_threads in util_queue_finish Reviewed-by: Ian Romanick --- src/util/u_queue.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/util') diff --git a/src/util/u_queue.c b/src/util/u_queue.c index cfd2a08e3c8..5e0c1095569 100644 --- a/src/util/u_queue.c +++ b/src/util/u_queue.c @@ -592,15 +592,15 @@ void util_queue_finish(struct util_queue *queue) { util_barrier barrier; - struct util_queue_fence *fences = malloc(queue->num_threads * sizeof(*fences)); - - util_barrier_init(&barrier, queue->num_threads); + struct util_queue_fence *fences; /* If 2 threads were adding jobs for 2 different barries at the same time, * a deadlock would happen, because 1 barrier requires that all threads * wait for it exclusively. */ mtx_lock(&queue->finish_lock); + fences = malloc(queue->num_threads * sizeof(*fences)); + util_barrier_init(&barrier, queue->num_threads); for (unsigned i = 0; i < queue->num_threads; ++i) { util_queue_fence_init(&fences[i]); -- cgit v1.2.3