From 9f433590bd7ef64bba8f3513f57df44501729823 Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Tue, 24 Aug 2021 10:28:21 +0100 Subject: [PATCH] Duplicates - option to limit thread use In Preferences/Advanced there is an option to set the thread limit for duplicates searches. --- doc/docbook/GuideOptionsAdvanced.xml | 13 ++++++++++--- src/dupe.c | 2 +- src/options.c | 2 ++ src/options.h | 5 +++++ src/preferences.c | 23 +++++++++++++++++++++-- src/rcfile.c | 7 +++++++ 6 files changed, 46 insertions(+), 6 deletions(-) diff --git a/doc/docbook/GuideOptionsAdvanced.xml b/doc/docbook/GuideOptionsAdvanced.xml index e02a5623..53c392c8 100644 --- a/doc/docbook/GuideOptionsAdvanced.xml +++ b/doc/docbook/GuideOptionsAdvanced.xml @@ -1,7 +1,9 @@ -
- External preview extraction - +
+Advanced +
+ External preview extraction + The intention of this feature is to give the user the possibility to display image previews of files that the standard libraries cannot decode. @@ -86,3 +88,8 @@
+
+ Thread Pools + This option will limit the number of threads (cores) that are used when performing a duplicate image search. A value of 0 means use all available threads. This will give the fastest processing time, but will slow other processes including user input response time. +
+
diff --git a/src/dupe.c b/src/dupe.c index d76452a2..f051dcbe 100644 --- a/src/dupe.c +++ b/src/dupe.c @@ -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; } diff --git a/src/options.c b/src/options.c index 09cc2728..8f9cb7cb 100644 --- a/src/options.c +++ b/src/options.c @@ -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"); diff --git a/src/options.h b/src/options.h index 3db05f71..5ba51dd4 100644 --- a/src/options.h +++ b/src/options.h @@ -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 */ diff --git a/src/preferences.c b/src/preferences.c index f09aa63b..4546b1dc 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -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 */ diff --git a/src/rcfile.c b/src/rcfile.c index 3e04027d..feaca6ef 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -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; -- 2.20.1