diff options
author | Marek Olšák <[email protected]> | 2016-06-11 17:28:52 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2016-06-24 12:24:40 +0200 |
commit | cbb5adb90893a7c03f96f72f0665766a4007affd (patch) | |
tree | 3391dfaf4e7929f214fa9a739c64f94abb9f5393 /src/gallium/auxiliary/util | |
parent | 4a06786efd42abfdb0babf65ed4ac59ae58fe4b5 (diff) |
gallium/u_queue: allow the execute function to differ per job
so that independent types of jobs can use the same queue.
Reviewed-by: Nicolai Hähnle <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r-- | src/gallium/auxiliary/util/u_queue.c | 12 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_queue.h | 10 |
2 files changed, 12 insertions, 10 deletions
diff --git a/src/gallium/auxiliary/util/u_queue.c b/src/gallium/auxiliary/util/u_queue.c index 775cb73de43..627c08a524a 100644 --- a/src/gallium/auxiliary/util/u_queue.c +++ b/src/gallium/auxiliary/util/u_queue.c @@ -84,7 +84,7 @@ static PIPE_THREAD_ROUTINE(util_queue_thread_func, input) } job = queue->jobs[queue->read_idx]; - queue->jobs[queue->read_idx].job = NULL; + memset(&queue->jobs[queue->read_idx], 0, sizeof(struct util_queue_job)); queue->read_idx = (queue->read_idx + 1) % queue->max_jobs; queue->num_queued--; @@ -92,7 +92,7 @@ static PIPE_THREAD_ROUTINE(util_queue_thread_func, input) pipe_mutex_unlock(queue->lock); if (job.job) { - queue->execute_job(job.job, thread_index); + job.execute(job.job, thread_index); util_queue_fence_signal(job.fence); } } @@ -113,8 +113,7 @@ bool util_queue_init(struct util_queue *queue, const char *name, unsigned max_jobs, - unsigned num_threads, - void (*execute_job)(void *, int)) + unsigned num_threads) { unsigned i; @@ -128,7 +127,6 @@ util_queue_init(struct util_queue *queue, if (!queue->jobs) goto fail; - queue->execute_job = execute_job; pipe_mutex_init(queue->lock); queue->num_queued = 0; @@ -216,7 +214,8 @@ util_queue_fence_destroy(struct util_queue_fence *fence) void util_queue_add_job(struct util_queue *queue, void *job, - struct util_queue_fence *fence) + struct util_queue_fence *fence, + util_queue_execute_func execute) { struct util_queue_job *ptr; @@ -234,6 +233,7 @@ util_queue_add_job(struct util_queue *queue, assert(ptr->job == NULL); ptr->job = job; ptr->fence = fence; + ptr->execute = execute; queue->write_idx = (queue->write_idx + 1) % queue->max_jobs; queue->num_queued++; diff --git a/src/gallium/auxiliary/util/u_queue.h b/src/gallium/auxiliary/util/u_queue.h index 750327e0279..f70d6466887 100644 --- a/src/gallium/auxiliary/util/u_queue.h +++ b/src/gallium/auxiliary/util/u_queue.h @@ -44,9 +44,12 @@ struct util_queue_fence { int signalled; }; +typedef void (*util_queue_execute_func)(void *job, int thread_index); + struct util_queue_job { void *job; struct util_queue_fence *fence; + util_queue_execute_func execute; }; /* Put this into your context. */ @@ -62,21 +65,20 @@ struct util_queue { int max_jobs; int write_idx, read_idx; /* ring buffer pointers */ struct util_queue_job *jobs; - void (*execute_job)(void *job, int thread_index); }; bool util_queue_init(struct util_queue *queue, const char *name, unsigned max_jobs, - unsigned num_threads, - void (*execute_job)(void *, int)); + unsigned num_threads); void util_queue_destroy(struct util_queue *queue); void util_queue_fence_init(struct util_queue_fence *fence); void util_queue_fence_destroy(struct util_queue_fence *fence); void util_queue_add_job(struct util_queue *queue, void *job, - struct util_queue_fence *fence); + struct util_queue_fence *fence, + util_queue_execute_func execute); void util_queue_job_wait(struct util_queue_fence *fence); /* util_queue needs to be cleared to zeroes for this to work */ |