plug-ins/help: fix thread unnecessarily waiting when locale_parse failed

If `gimp_help_locale_parse` failed due to a locale not having a
manual available, we always waited for a 10 seconds timeout because
we depended on the value of success to decide if we should exit
the thread.

When the call finishes we should always stop, so add a `done` parameter
and depend on that to decide if we can exit instead of using success.
This commit is contained in:
Jacob Boerema 2025-03-06 13:53:13 -05:00
parent 4075add5b4
commit fd0ccfa16c

View file

@ -45,6 +45,7 @@
typedef struct
{
gboolean *success;
gboolean *done;
GimpHelpLocale *locale;
const gchar *uri;
@ -242,20 +243,19 @@ gimp_help_domain_map (GimpHelpDomain *domain,
/* private functions */
G_LOCK_DEFINE (success);
G_LOCK_DEFINE (done);
static gboolean
parse_thread_func (HelpThreadData *data)
{
gboolean success = FALSE;
success = gimp_help_locale_parse (data->locale, data->uri, data->domain,
data->progress, data->cancellable, data->error);
G_LOCK (success);
*data->success = success;
G_UNLOCK (success);
*data->success = gimp_help_locale_parse (data->locale, data->uri, data->domain,
data->progress, data->cancellable, data->error);
G_LOCK (done);
*data->done = TRUE;
G_UNLOCK (done);
return success;
return *data->success;
}
static gboolean
@ -269,6 +269,7 @@ domain_locale_parse (GimpHelpDomain *domain,
GThread *thread;
GTimer *timer;
gboolean success = FALSE;
gboolean done = FALSE;
HelpThreadData data;
g_return_val_if_fail (domain != NULL, FALSE);
@ -280,6 +281,7 @@ domain_locale_parse (GimpHelpDomain *domain,
timer = g_timer_new ();
cancellable = g_cancellable_new ();
data.done = &done;
data.success = &success;
data.locale = locale;
data.uri = uri;
@ -293,9 +295,9 @@ domain_locale_parse (GimpHelpDomain *domain,
{
gboolean exit;
G_LOCK (success);
exit = success;
G_UNLOCK (success);
G_LOCK (done);
exit = *data.done;
G_UNLOCK (done);
if (! exit && g_timer_elapsed (timer, NULL) > 10.0)
{