diff options
author | Marek Olšák <marek.olsak@amd.com> | 2018-04-24 17:01:35 -0400 |
---|---|---|
committer | Marek Olšák <marek.olsak@amd.com> | 2018-04-27 13:28:17 -0400 |
commit | 7083ac7290a0c37a45494437a45441112f3cc36c (patch) | |
tree | 3be67d858ff81749cdfa15937150456dab4712cd /src/util/u_queue.c | |
parent | 7772de5283cf30b06e75f9e4914a75f54ca37564 (diff) | |
download | mesa-7083ac7290a0c37a45494437a45441112f3cc36c.tar.gz mesa-7083ac7290a0c37a45494437a45441112f3cc36c.tar.bz2 mesa-7083ac7290a0c37a45494437a45441112f3cc36c.zip |
util/u_queue: fix a deadlock in util_queue_finish
Cc: 18.0 18.1 <mesa-stable@lists.freedesktop.org>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Diffstat (limited to 'src/util/u_queue.c')
-rw-r--r-- | src/util/u_queue.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/util/u_queue.c b/src/util/u_queue.c index dba23f96456..da513fd9cc5 100644 --- a/src/util/u_queue.c +++ b/src/util/u_queue.c @@ -311,6 +311,7 @@ util_queue_init(struct util_queue *queue, goto fail; (void) mtx_init(&queue->lock, mtx_plain); + (void) mtx_init(&queue->finish_lock, mtx_plain); queue->num_queued = 0; cnd_init(&queue->has_queued_cond); @@ -398,6 +399,7 @@ util_queue_destroy(struct util_queue *queue) cnd_destroy(&queue->has_space_cond); cnd_destroy(&queue->has_queued_cond); + mtx_destroy(&queue->finish_lock); mtx_destroy(&queue->lock); free(queue->jobs); free(queue->threads); @@ -529,6 +531,12 @@ util_queue_finish(struct util_queue *queue) util_barrier_init(&barrier, queue->num_threads); + /* 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); + 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); @@ -538,6 +546,7 @@ util_queue_finish(struct util_queue *queue) util_queue_fence_wait(&fences[i]); util_queue_fence_destroy(&fences[i]); } + mtx_unlock(&queue->finish_lock); util_barrier_destroy(&barrier); |