[Mesa-dev] [PATCH 5/7] util/queue: hold a lock when reading num_threads in util_queue_finish
Marek Olšák
maraeo at gmail.com
Thu Nov 29 02:59:28 UTC 2018
From: Marek Olšák <marek.olsak at amd.com>
---
src/util/u_queue.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/util/u_queue.c b/src/util/u_queue.c
index 5aaf60ae78e..612ad5e83c6 100644
--- a/src/util/u_queue.c
+++ b/src/util/u_queue.c
@@ -582,29 +582,29 @@ util_queue_finish_execute(void *data, int num_thread)
util_barrier_wait(barrier);
}
/**
* Wait until all previously added jobs have completed.
*/
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]);
util_queue_add_job(queue, &barrier, &fences[i], util_queue_finish_execute, NULL);
}
for (unsigned i = 0; i < queue->num_threads; ++i) {
util_queue_fence_wait(&fences[i]);
util_queue_fence_destroy(&fences[i]);
}
--
2.17.1
More information about the mesa-dev
mailing list