[Mesa-dev] [PATCH 5/7] util/queue: hold a lock when reading num_threads in util_queue_finish
Ian Romanick
idr at freedesktop.org
Thu Jan 3 20:04:24 UTC 2019
This patch is
Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
On 11/28/18 6:59 PM, Marek Olšák wrote:
> 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]);
> }
>
More information about the mesa-dev
mailing list