Mesa (main): util/queue: use simple_mtx_t for finish_lock

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Oct 6 00:12:41 UTC 2021


Module: Mesa
Branch: main
Commit: b4afe25ebf8376ef0dd1ffbf4ca0dec3dc9dd0b3
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b4afe25ebf8376ef0dd1ffbf4ca0dec3dc9dd0b3

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Fri Oct  1 15:40:48 2021 -0400

util/queue: use simple_mtx_t for finish_lock

Acked-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Reviewed-by: Timothy Arceri <tarceri at itsqueeze.com>
Reviewed-by: Kristian H. Kristensen <hoegsberg at google.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13152>

---

 src/util/u_queue.c | 24 ++++++++++++------------
 src/util/u_queue.h |  3 ++-
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/src/util/u_queue.c b/src/util/u_queue.c
index 7356ffbd670..f0eb7895594 100644
--- a/src/util/u_queue.c
+++ b/src/util/u_queue.c
@@ -374,17 +374,17 @@ util_queue_adjust_num_threads(struct util_queue *queue, unsigned num_threads)
    num_threads = MIN2(num_threads, queue->max_threads);
    num_threads = MAX2(num_threads, 1);
 
-   mtx_lock(&queue->finish_lock);
+   simple_mtx_lock(&queue->finish_lock);
    unsigned old_num_threads = queue->num_threads;
 
    if (num_threads == old_num_threads) {
-      mtx_unlock(&queue->finish_lock);
+      simple_mtx_unlock(&queue->finish_lock);
       return;
    }
 
    if (num_threads < old_num_threads) {
       util_queue_kill_threads(queue, num_threads, true);
-      mtx_unlock(&queue->finish_lock);
+      simple_mtx_unlock(&queue->finish_lock);
       return;
    }
 
@@ -398,7 +398,7 @@ util_queue_adjust_num_threads(struct util_queue *queue, unsigned num_threads)
       if (!util_queue_create_thread(queue, i))
          break;
    }
-   mtx_unlock(&queue->finish_lock);
+   simple_mtx_unlock(&queue->finish_lock);
 }
 
 bool
@@ -446,7 +446,7 @@ util_queue_init(struct util_queue *queue,
    queue->global_data = global_data;
 
    (void) mtx_init(&queue->lock, mtx_plain);
-   (void) mtx_init(&queue->finish_lock, mtx_plain);
+   (void) simple_mtx_init(&queue->finish_lock, mtx_plain);
 
    queue->num_queued = 0;
    cnd_init(&queue->has_queued_cond);
@@ -500,10 +500,10 @@ util_queue_kill_threads(struct util_queue *queue, unsigned keep_num_threads,
 
    /* Signal all threads to terminate. */
    if (!finish_locked)
-      mtx_lock(&queue->finish_lock);
+      simple_mtx_lock(&queue->finish_lock);
 
    if (keep_num_threads >= queue->num_threads) {
-      mtx_unlock(&queue->finish_lock);
+      simple_mtx_unlock(&queue->finish_lock);
       return;
    }
 
@@ -520,7 +520,7 @@ util_queue_kill_threads(struct util_queue *queue, unsigned keep_num_threads,
       thrd_join(queue->threads[i], NULL);
 
    if (!finish_locked)
-      mtx_unlock(&queue->finish_lock);
+      simple_mtx_unlock(&queue->finish_lock);
 }
 
 static void
@@ -541,7 +541,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);
+   simple_mtx_destroy(&queue->finish_lock);
    mtx_destroy(&queue->lock);
    free(queue->jobs);
    free(queue->threads);
@@ -682,11 +682,11 @@ util_queue_finish(struct util_queue *queue)
     * a deadlock would happen, because 1 barrier requires that all threads
     * wait for it exclusively.
     */
-   mtx_lock(&queue->finish_lock);
+   simple_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);
+      simple_mtx_unlock(&queue->finish_lock);
       return;
    }
 
@@ -703,7 +703,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);
+   simple_mtx_unlock(&queue->finish_lock);
 
    util_barrier_destroy(&barrier);
 
diff --git a/src/util/u_queue.h b/src/util/u_queue.h
index 793120a3270..2da74c5b19b 100644
--- a/src/util/u_queue.h
+++ b/src/util/u_queue.h
@@ -35,6 +35,7 @@
 
 #include <string.h>
 
+#include "simple_mtx.h"
 #include "util/futex.h"
 #include "util/list.h"
 #include "util/macros.h"
@@ -204,7 +205,7 @@ struct util_queue_job {
 /* Put this into your context. */
 struct util_queue {
    char name[14]; /* 13 characters = the thread name without the index */
-   mtx_t finish_lock; /* for util_queue_finish and protects threads/num_threads */
+   simple_mtx_t finish_lock; /* for util_queue_finish and protects threads/num_threads */
    mtx_t lock;
    cnd_t has_queued_cond;
    cnd_t has_space_cond;



More information about the mesa-commit mailing list