[Mesa-dev] [PATCH 4/7] u_queue: add util_queue_fence_reset
Nicolai Hähnle
nhaehnle at gmail.com
Sun Oct 22 18:33:41 UTC 2017
From: Nicolai Hähnle <nicolai.haehnle at amd.com>
---
src/util/u_queue.c | 4 +---
src/util/u_queue.h | 13 +++++++++++++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/src/util/u_queue.c b/src/util/u_queue.c
index 33436e0749a..2272006042f 100644
--- a/src/util/u_queue.c
+++ b/src/util/u_queue.c
@@ -321,32 +321,30 @@ util_queue_destroy(struct util_queue *queue)
void
util_queue_add_job(struct util_queue *queue,
void *job,
struct util_queue_fence *fence,
util_queue_execute_func execute,
util_queue_execute_func cleanup)
{
struct util_queue_job *ptr;
- assert(fence->signalled);
-
mtx_lock(&queue->lock);
if (queue->kill_threads) {
mtx_unlock(&queue->lock);
/* well no good option here, but any leaks will be
* short-lived as things are shutting down..
*/
return;
}
- fence->signalled = false;
+ util_queue_fence_reset(fence);
assert(queue->num_queued >= 0 && queue->num_queued <= queue->max_jobs);
if (queue->num_queued == queue->max_jobs) {
if (queue->flags & UTIL_QUEUE_INIT_RESIZE_IF_FULL) {
/* If the queue is full, make it larger to avoid waiting for a free
* slot.
*/
unsigned new_max_jobs = queue->max_jobs + 8;
struct util_queue_job *jobs =
diff --git a/src/util/u_queue.h b/src/util/u_queue.h
index 5a546e53fdc..a3e12260e30 100644
--- a/src/util/u_queue.h
+++ b/src/util/u_queue.h
@@ -52,20 +52,33 @@ struct util_queue_fence {
mtx_t mutex;
cnd_t cond;
int signalled;
};
void util_queue_fence_init(struct util_queue_fence *fence);
void util_queue_fence_destroy(struct util_queue_fence *fence);
void util_queue_fence_wait(struct util_queue_fence *fence);
void util_queue_fence_signal(struct util_queue_fence *fence);
+/**
+ * Move \p fence back into unsignalled state.
+ *
+ * \warning The caller must ensure that no other thread may currently be
+ * waiting (or about to wait) on the fence.
+ */
+static inline void
+util_queue_fence_reset(struct util_queue_fence *fence)
+{
+ assert(fence->signalled);
+ fence->signalled = 0;
+}
+
static inline bool
util_queue_fence_is_signalled(struct util_queue_fence *fence)
{
return fence->signalled != 0;
}
typedef void (*util_queue_execute_func)(void *job, int thread_index);
struct util_queue_job {
void *job;
--
2.11.0
More information about the mesa-dev
mailing list