[file-roller: 7/8] Move fr_get_thread_count function into glib-utils as suggested in review.




commit 9477af59c08711f3c3984b0b53a65fec31e17f1b
Author: Julian Groß <firedefender1 googlemail com>
Date:   Mon Apr 5 22:52:57 2021 +0200

    Move fr_get_thread_count function into glib-utils as suggested in review.

 src/fr-archive-libarchive.c |  1 -
 src/fr-thread-count.c       | 36 ------------------------------------
 src/fr-thread-count.h       | 29 -----------------------------
 src/glib-utils.c            | 14 ++++++++++++++
 src/glib-utils.h            |  4 ++++
 src/meson.build             |  1 -
 6 files changed, 18 insertions(+), 67 deletions(-)
---
diff --git a/src/fr-archive-libarchive.c b/src/fr-archive-libarchive.c
index b8d87121..a987a29a 100644
--- a/src/fr-archive-libarchive.c
+++ b/src/fr-archive-libarchive.c
@@ -33,7 +33,6 @@
 #include "file-utils.h"
 #include "fr-error.h"
 #include "fr-archive-libarchive.h"
-#include "fr-thread-count.h"
 #include "gio-utils.h"
 #include "glib-utils.h"
 #include "typedefs.h"
diff --git a/src/glib-utils.c b/src/glib-utils.c
index 048ab425..b417ddd6 100644
--- a/src/glib-utils.c
+++ b/src/glib-utils.c
@@ -1552,6 +1552,20 @@ _g_line_get_prev_field (const char *line,
        return g_strndup (f_start + 1, f_end - f_start);
 }
 
+/* threading */
+
+gchar *
+fr_get_thread_count (void)
+{
+       gchar *cpus;
+       if (g_get_num_processors() >= 8)
+               cpus = g_strdup_printf("%u", g_get_num_processors() - 2);
+       else if (g_get_num_processors() >= 4)
+               cpus = g_strdup_printf("%u", g_get_num_processors() - 1);
+       else
+               cpus = g_strdup_printf("%u", g_get_num_processors());
+       return cpus;
+}
 
 /* debug */
 
diff --git a/src/glib-utils.h b/src/glib-utils.h
index 4d4bcad8..94893aa2 100644
--- a/src/glib-utils.h
+++ b/src/glib-utils.h
@@ -205,6 +205,10 @@ char*               _g_line_get_prev_field         (const char          *line,
                                                    int                  start_from,
                                                    int                  field_n);
 
+/* threading */
+
+gchar *           fr_get_thread_count             (void);
+
 /* debug */
 
 void                debug                          (const char          *file,
diff --git a/src/meson.build b/src/meson.build
index 7e3cdee3..8083aacc 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -44,7 +44,6 @@ source_files = files(
   'fr-location-bar.c',
   'fr-new-archive-dialog.c',
   'fr-process.c',
-  'fr-thread-count.c',
   'fr-window-actions-callbacks.c',
   'fr-window.c',
   'gio-utils.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]