Mesa (master): util/queue: move thread creation into a separate function

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Apr 1 16:43:54 UTC 2019


Module: Mesa
Branch: master
Commit: d99cdc9d5902da8437eabbd2f6981d01e4f7b78f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d99cdc9d5902da8437eabbd2f6981d01e4f7b78f

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Mon Aug  6 20:15:43 2018 -0400

util/queue: move thread creation into a separate function

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

---

 src/util/u_queue.c | 56 +++++++++++++++++++++++++++++++-----------------------
 1 file 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);




More information about the mesa-commit mailing list