Fix bug in progress update from rendering thread which results in the creation of multipe idel callbacks at the same time.

This commit is contained in:
Mario Hüttel 2019-08-22 19:31:47 +02:00
parent 7aa7a0c773
commit c908a8be47
2 changed files with 14 additions and 8 deletions

View File

@ -293,13 +293,15 @@ static void async_rendering_finished_callback(GdsOutputRenderer *renderer, gpoin
g_object_unref(renderer); g_object_unref(renderer);
} }
static void async_rendering_status_update_callback(GdsOutputRenderer *renderer, const char *status_message, gpointer data) static void async_rendering_status_update_callback(GdsOutputRenderer *renderer, char *status_message, gpointer data)
{ {
GdsRenderGui *gui; GdsRenderGui *gui;
(void)renderer; (void)renderer;
gui = RENDERER_GUI(data); gui = RENDERER_GUI(data);
activity_bar_set_busy(gui->activity_status_bar, status_message); activity_bar_set_busy(gui->activity_status_bar, status_message);
g_free(status_message);
} }
/** /**

View File

@ -402,7 +402,7 @@ static gboolean idle_event_processor_callback(gpointer user_data)
priv = gds_output_renderer_get_instance_private(renderer); priv = gds_output_renderer_get_instance_private(renderer);
if (g_mutex_trylock(&priv->idle_function_parameters.message_lock)) { if (g_mutex_trylock(&priv->idle_function_parameters.message_lock)) {
status_message = priv->idle_function_parameters.status_message; status_message = g_strdup(priv->idle_function_parameters.status_message);
g_signal_emit(renderer, gds_output_renderer_signals[ASYNC_PROGRESS_CHANGED], 0, status_message); g_signal_emit(renderer, gds_output_renderer_signals[ASYNC_PROGRESS_CHANGED], 0, status_message);
g_free(priv->idle_function_parameters.status_message); g_free(priv->idle_function_parameters.status_message);
priv->idle_function_parameters.status_message = NULL; priv->idle_function_parameters.status_message = NULL;
@ -418,6 +418,7 @@ void gds_output_renderer_update_gui_status_from_async(GdsOutputRenderer *rendere
{ {
GSource *idle_event_processor; GSource *idle_event_processor;
GdsOutputRendererPrivate *priv; GdsOutputRendererPrivate *priv;
gboolean skip_source = FALSE;
g_return_if_fail(GDS_RENDER_IS_OUTPUT_RENDERER(renderer)); g_return_if_fail(GDS_RENDER_IS_OUTPUT_RENDERER(renderer));
if (!status) if (!status)
@ -430,17 +431,20 @@ void gds_output_renderer_update_gui_status_from_async(GdsOutputRenderer *rendere
return; return;
g_mutex_lock(&priv->idle_function_parameters.message_lock); g_mutex_lock(&priv->idle_function_parameters.message_lock);
if (priv->idle_function_parameters.status_message) {
if (priv->idle_function_parameters.status_message)
g_free(priv->idle_function_parameters.status_message); g_free(priv->idle_function_parameters.status_message);
/* Skip adding new idle source because there's already an active one */
skip_source = TRUE;
}
priv->idle_function_parameters.status_message = g_strdup(status); priv->idle_function_parameters.status_message = g_strdup(status);
g_mutex_unlock(&priv->idle_function_parameters.message_lock); g_mutex_unlock(&priv->idle_function_parameters.message_lock);
idle_event_processor = g_idle_source_new(); if (!skip_source) {
g_source_set_callback(idle_event_processor, idle_event_processor_callback, (gpointer)renderer, NULL); idle_event_processor = g_idle_source_new();
g_source_attach(idle_event_processor, priv->main_context); g_source_set_callback(idle_event_processor, idle_event_processor_callback, (gpointer)renderer, NULL);
g_source_attach(idle_event_processor, priv->main_context);
}
} }
/** @} */ /** @} */