util/queue: use simple_mtx_t for finish_lock
Acked-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com> Reviewed-by: Kristian H. Kristensen <hoegsberg@google.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13152>
This commit is contained in:
parent
28bde89556
commit
b4afe25ebf
|
@ -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 = MIN2(num_threads, queue->max_threads);
|
||||||
num_threads = MAX2(num_threads, 1);
|
num_threads = MAX2(num_threads, 1);
|
||||||
|
|
||||||
mtx_lock(&queue->finish_lock);
|
simple_mtx_lock(&queue->finish_lock);
|
||||||
unsigned old_num_threads = queue->num_threads;
|
unsigned old_num_threads = queue->num_threads;
|
||||||
|
|
||||||
if (num_threads == old_num_threads) {
|
if (num_threads == old_num_threads) {
|
||||||
mtx_unlock(&queue->finish_lock);
|
simple_mtx_unlock(&queue->finish_lock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_threads < old_num_threads) {
|
if (num_threads < old_num_threads) {
|
||||||
util_queue_kill_threads(queue, num_threads, true);
|
util_queue_kill_threads(queue, num_threads, true);
|
||||||
mtx_unlock(&queue->finish_lock);
|
simple_mtx_unlock(&queue->finish_lock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,7 +398,7 @@ util_queue_adjust_num_threads(struct util_queue *queue, unsigned num_threads)
|
||||||
if (!util_queue_create_thread(queue, i))
|
if (!util_queue_create_thread(queue, i))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mtx_unlock(&queue->finish_lock);
|
simple_mtx_unlock(&queue->finish_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -446,7 +446,7 @@ util_queue_init(struct util_queue *queue,
|
||||||
queue->global_data = global_data;
|
queue->global_data = global_data;
|
||||||
|
|
||||||
(void) mtx_init(&queue->lock, mtx_plain);
|
(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;
|
queue->num_queued = 0;
|
||||||
cnd_init(&queue->has_queued_cond);
|
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. */
|
/* Signal all threads to terminate. */
|
||||||
if (!finish_locked)
|
if (!finish_locked)
|
||||||
mtx_lock(&queue->finish_lock);
|
simple_mtx_lock(&queue->finish_lock);
|
||||||
|
|
||||||
if (keep_num_threads >= queue->num_threads) {
|
if (keep_num_threads >= queue->num_threads) {
|
||||||
mtx_unlock(&queue->finish_lock);
|
simple_mtx_unlock(&queue->finish_lock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,7 +520,7 @@ util_queue_kill_threads(struct util_queue *queue, unsigned keep_num_threads,
|
||||||
thrd_join(queue->threads[i], NULL);
|
thrd_join(queue->threads[i], NULL);
|
||||||
|
|
||||||
if (!finish_locked)
|
if (!finish_locked)
|
||||||
mtx_unlock(&queue->finish_lock);
|
simple_mtx_unlock(&queue->finish_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -541,7 +541,7 @@ util_queue_destroy(struct util_queue *queue)
|
||||||
|
|
||||||
cnd_destroy(&queue->has_space_cond);
|
cnd_destroy(&queue->has_space_cond);
|
||||||
cnd_destroy(&queue->has_queued_cond);
|
cnd_destroy(&queue->has_queued_cond);
|
||||||
mtx_destroy(&queue->finish_lock);
|
simple_mtx_destroy(&queue->finish_lock);
|
||||||
mtx_destroy(&queue->lock);
|
mtx_destroy(&queue->lock);
|
||||||
free(queue->jobs);
|
free(queue->jobs);
|
||||||
free(queue->threads);
|
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
|
* a deadlock would happen, because 1 barrier requires that all threads
|
||||||
* wait for it exclusively.
|
* 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. */
|
/* The number of threads can be changed to 0, e.g. by the atexit handler. */
|
||||||
if (!queue->num_threads) {
|
if (!queue->num_threads) {
|
||||||
mtx_unlock(&queue->finish_lock);
|
simple_mtx_unlock(&queue->finish_lock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -703,7 +703,7 @@ util_queue_finish(struct util_queue *queue)
|
||||||
util_queue_fence_wait(&fences[i]);
|
util_queue_fence_wait(&fences[i]);
|
||||||
util_queue_fence_destroy(&fences[i]);
|
util_queue_fence_destroy(&fences[i]);
|
||||||
}
|
}
|
||||||
mtx_unlock(&queue->finish_lock);
|
simple_mtx_unlock(&queue->finish_lock);
|
||||||
|
|
||||||
util_barrier_destroy(&barrier);
|
util_barrier_destroy(&barrier);
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "simple_mtx.h"
|
||||||
#include "util/futex.h"
|
#include "util/futex.h"
|
||||||
#include "util/list.h"
|
#include "util/list.h"
|
||||||
#include "util/macros.h"
|
#include "util/macros.h"
|
||||||
|
@ -204,7 +205,7 @@ struct util_queue_job {
|
||||||
/* Put this into your context. */
|
/* Put this into your context. */
|
||||||
struct util_queue {
|
struct util_queue {
|
||||||
char name[14]; /* 13 characters = the thread name without the index */
|
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;
|
mtx_t lock;
|
||||||
cnd_t has_queued_cond;
|
cnd_t has_queued_cond;
|
||||||
cnd_t has_space_cond;
|
cnd_t has_space_cond;
|
||||||
|
|
Loading…
Reference in New Issue