Duplicates - option to limit thread use
authorColin Clark <colin.clark@cclark.uk>
Tue, 24 Aug 2021 09:28:21 +0000 (10:28 +0100)
committerColin Clark <colin.clark@cclark.uk>
Tue, 24 Aug 2021 09:28:21 +0000 (10:28 +0100)
In Preferences/Advanced there is an option to set the thread limit for
duplicates searches.

doc/docbook/GuideOptionsAdvanced.xml
src/dupe.c
src/options.c
src/options.h
src/preferences.c
src/rcfile.c

index e02a562..53c392c 100644 (file)
@@ -1,7 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>\r
-<section id="GuideOptionsAdvanced">\r
-  <title>External preview extraction</title>\r
-  <para>\r
+  <section id="GuideOptionsAdvanced">\r
+<title>Advanced</title>\r
+  <section id="ExternalPreviewExtraction">\r
+     <title>External preview extraction</title>\r
+ <para>\r
     The intention of this feature is to give the user the possibility to display image previews of files\r
     that the standard libraries cannot decode.\r
     <para />\r
@@ -86,3 +88,8 @@
     </pre>\r
   </para>\r
 </section>\r
+<section id="ThreadPools">\r
+    <title>Thread Pools</title>\r
+    <para>This option will limit the number of threads (cores) that are used when performing a duplicate image search. A value of <code>0</code> means use all available threads. This will give the fastest processing time, but will slow other processes including user input response time.</para> \r
+</section>\r
+</section>\r
index d76452a..f051dcb 100644 (file)
@@ -4837,7 +4837,7 @@ DupeWindow *dupe_window_new()
 
        g_mutex_init(&dw->thread_count_mutex);
        g_mutex_init(&dw->search_matches_mutex);
-       dw->dupe_comparison_thread_pool = g_thread_pool_new(dupe_comparison_func, dw, -1, FALSE, NULL);
+       dw->dupe_comparison_thread_pool = g_thread_pool_new(dupe_comparison_func, dw, options->threads.duplicates, FALSE, NULL);
 
        return dw;
 }
index 09cc272..8f9cb7c 100644 (file)
@@ -214,6 +214,8 @@ ConfOptions *init_options(ConfOptions *options)
        options->printer.image_text_position = 1;
        options->printer.page_text_position = 3;
 
+       options->threads.duplicates = -1;
+
        options->disabled_plugins = NULL;
 
        options->mouse_button_8 = g_strdup("Back");
index 3db05f7..5ba51dd 100644 (file)
@@ -352,6 +352,11 @@ struct _ConfOptions
                gchar *template_string;
        } printer;
 
+       /* Threads */
+       struct {
+               gint duplicates;
+       } threads;
+
        gchar *mouse_button_8; /**< user-definable mouse buttons */
        gchar *mouse_button_9; /**< user-definable mouse buttons */
 
index f09aa63..4546b1d 100644 (file)
@@ -39,6 +39,7 @@
 #include "layout_config.h"
 #include "layout_util.h"
 #include "metadata.h"
+#include "misc.h"
 #include "osd.h"
 #include "pixbuf_util.h"
 #include "rcfile.h"
@@ -445,6 +446,9 @@ static void config_window_apply(void)
 
        options->star_rating.star = c_options->star_rating.star;
        options->star_rating.rejected = c_options->star_rating.rejected;
+
+       options->threads.duplicates = c_options->threads.duplicates > 0 ? c_options->threads.duplicates : -1;
+
 #ifdef DEBUG
        set_debug_level(debug_c);
 #endif
@@ -3675,6 +3679,9 @@ static void config_tab_advanced(GtkWidget *notebook)
        GdkPixbufFormat *fm;
        gint i;
        GString *types_string = g_string_new(NULL);
+       GtkWidget *types_string_label;
+       GtkWidget *threads_string_label;
+       GtkWidget *dupes_threads_spin;
 
        vbox = scrolled_notebook_page(notebook, _("Advanced"));
        group = pref_group_new(vbox, FALSE, _("External preview extraction"), GTK_ORIENTATION_VERTICAL);
@@ -3717,8 +3724,7 @@ static void config_tab_advanced(GtkWidget *notebook)
                }
 
        types_string = g_string_prepend(types_string, _("Usable file types:\n"));
-       pref_label_new(group, types_string->str);
-       GtkWidget *types_string_label = gtk_label_new(types_string->str);
+       types_string_label = pref_label_new(group, types_string->str);
        gtk_label_set_line_wrap(GTK_LABEL(types_string_label), TRUE);
 
        pref_spacer(group, PREF_PAD_GROUP);
@@ -3742,6 +3748,19 @@ static void config_tab_advanced(GtkWidget *notebook)
        g_slist_free(formats_list);
        string_list_free(extensions_list);
        g_string_free(types_string, TRUE);
+
+       pref_spacer(group, PREF_PAD_GROUP);
+
+       pref_line(vbox, PREF_PAD_SPACE);
+       group = pref_group_new(vbox, FALSE, _("Thread pool limits"), GTK_ORIENTATION_VERTICAL);
+
+       threads_string_label = pref_label_new(group, "This option limits the number of threads (or cpu cores)\nthat Geeqie will use when running duplicate checks. The default value is 0, which means all avaialble cores will be used.");
+       gtk_label_set_line_wrap(GTK_LABEL(threads_string_label), TRUE);
+
+       pref_spacer(vbox, PREF_PAD_GROUP);
+
+       dupes_threads_spin = pref_spin_new_int(vbox, _("Duplicate check:"), _("max. threads"), 0, get_cpu_cores(), 1, options->threads.duplicates, &c_options->threads.duplicates);
+       gtk_widget_set_tooltip_markup(dupes_threads_spin, _("Set to 0 for unlimited"));
 }
 
 /* stereo tab */
index 3e04027..feaca6e 100644 (file)
@@ -520,6 +520,10 @@ static void write_global_attributes(GString *outstr, gint indent)
        WRITE_NL(); WRITE_BOOL(*options, printer.show_page_text);
        WRITE_SEPARATOR();
 
+       /* Threads */
+       WRITE_NL(); WRITE_INT(*options, threads.duplicates);
+       WRITE_SEPARATOR();
+
        /* user-definable mouse buttons */
        WRITE_NL(); WRITE_CHAR(*options, mouse_button_8);
        WRITE_NL(); WRITE_CHAR(*options, mouse_button_9);
@@ -1004,6 +1008,9 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar **
                if (READ_BOOL(*options, printer.show_image_text)) continue;
                if (READ_BOOL(*options, printer.show_page_text)) continue;
 
+               /* Threads */
+               if (READ_INT(*options, threads.duplicates)) continue;
+
                /* user-definable mouse buttons */
                if (READ_CHAR(*options, mouse_button_8)) continue;
                if (READ_CHAR(*options, mouse_button_9)) continue;