From 89b6c93ae3135a44b1aa2ce9285502a3898920bc Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Wed, 31 May 2017 22:04:29 +0200 Subject: util/u_queue: add an option to set the minimum thread priority MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Nicolai Hähnle --- src/util/u_queue.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/util/u_queue.c') diff --git a/src/util/u_queue.c b/src/util/u_queue.c index 01c3a96d5f3..94fe2202a2c 100644 --- a/src/util/u_queue.c +++ b/src/util/u_queue.c @@ -147,6 +147,21 @@ util_queue_thread_func(void *input) u_thread_setname(name); } + if (queue->flags & UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY) { +#if defined(__linux__) + struct sched_param sched_param = {0}; + + /* The nice() function can only set a maximum of 19. + * SCHED_IDLE is the same as nice = 20. + * + * Note that Linux only allows decreasing the priority. The original + * priority can't be restored. + */ + pthread_setschedparam(queue->threads[thread_index], SCHED_IDLE, + &sched_param); +#endif + } + while (1) { struct util_queue_job job; @@ -197,13 +212,15 @@ bool util_queue_init(struct util_queue *queue, const char *name, unsigned max_jobs, - unsigned num_threads) + unsigned num_threads, + unsigned flags) { unsigned i; memset(queue, 0, sizeof(*queue)); queue->name = name; queue->num_threads = num_threads; + queue->flags = flags; queue->max_jobs = max_jobs; queue->jobs = (struct util_queue_job*) -- cgit v1.2.3