aboutsummaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2018-08-06 20:15:43 -0400
committerMarek Olšák <[email protected]>2019-04-01 12:37:52 -0400
commitd99cdc9d5902da8437eabbd2f6981d01e4f7b78f (patch)
tree85d9249d66df4e0c0935f1a5afe4eeb1ac73071c /src/util
parente871cbd625953c3767d53a858ab6478cd5ebc24d (diff)
util/queue: move thread creation into a separate function
Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/u_queue.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/src/util/u_queue.c b/src/util/u_queue.c
index 3812c824b6d..48c5c79552d 100644
--- a/src/util/u_queue.c
+++ b/src/util/u_queue.c
@@ -305,6 +305,37 @@ util_queue_thread_func(void *input)
return 0;
}
+static bool
+util_queue_create_thread(struct util_queue *queue, unsigned index)
+{
+ struct thread_input *input =
+ (struct thread_input *) malloc(sizeof(struct thread_input));
+ input->queue = queue;
+ input->thread_index = index;
+
+ queue->threads[index] = u_thread_create(util_queue_thread_func, input);
+
+ if (!queue->threads[index]) {
+ free(input);
+ return false;
+ }
+
+ if (queue->flags & UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY) {
+#if defined(__linux__) && defined(SCHED_IDLE)
+ 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[index], SCHED_IDLE, &sched_param);
+#endif
+ }
+ return true;
+}
+
bool
util_queue_init(struct util_queue *queue,
const char *name,
@@ -364,16 +395,7 @@ util_queue_init(struct util_queue *queue,
/* start threads */
for (i = 0; i < num_threads; i++) {
- struct thread_input *input =
- (struct thread_input *) malloc(sizeof(struct thread_input));
- input->queue = queue;
- input->thread_index = i;
-
- queue->threads[i] = u_thread_create(util_queue_thread_func, input);
-
- if (!queue->threads[i]) {
- free(input);
-
+ if (!util_queue_create_thread(queue, i)) {
if (i == 0) {
/* no threads created, fail */
goto fail;
@@ -383,20 +405,6 @@ util_queue_init(struct util_queue *queue,
break;
}
}
-
- if (flags & UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY) {
- #if defined(__linux__) && defined(SCHED_IDLE)
- 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);