diff options
author | Marek Olšák <[email protected]> | 2017-06-07 23:13:35 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2017-06-07 23:19:30 +0200 |
commit | e93a141f64dc59a686e1815a34fad31dcc8545e3 (patch) | |
tree | 0e9c0bfaf70d08c691b9b170a18a98525ff3fc40 /src | |
parent | 19f6cc3cbadfc89b7eba2f9d0b70bafac5b847e3 (diff) |
util/u_queue: fix a use-before-initialization race for queue->threads
Reviewed-by: Samuel Pitoiset <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/util/u_queue.c | 30 | ||||
-rw-r--r-- | src/util/u_queue.h | 1 |
2 files changed, 14 insertions, 17 deletions
diff --git a/src/util/u_queue.c b/src/util/u_queue.c index 94fe2202a2c..cb5903014e7 100644 --- a/src/util/u_queue.c +++ b/src/util/u_queue.c @@ -147,21 +147,6 @@ 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; @@ -220,7 +205,6 @@ util_queue_init(struct util_queue *queue, 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*) @@ -259,6 +243,20 @@ util_queue_init(struct util_queue *queue, break; } } + + if (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[i], SCHED_IDLE, &sched_param); + #endif + } } add_to_atexit_list(queue); diff --git a/src/util/u_queue.h b/src/util/u_queue.h index 916802c96d1..8ec959814b0 100644 --- a/src/util/u_queue.h +++ b/src/util/u_queue.h @@ -71,7 +71,6 @@ struct util_queue { thrd_t *threads; int num_queued; unsigned num_threads; - unsigned flags; int kill_threads; int max_jobs; int write_idx, read_idx; /* ring buffer pointers */ |