From 57e858a9929949e029404eff9adcd303fc0ce69f Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Tue, 13 Oct 2009 06:53:16 +0000 Subject: [PATCH] Avoid installing emission hook more than once. It was possible for an app using a timer, but triggering no events, to accumulate an unbounded number of hooks, consuming large amounts of CPU time in processing the hook list. Fixes #11315. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@62397 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/app.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index 36a8dd6410..f6211634ff 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -149,9 +149,11 @@ extern "C" // One-shot emission hook for "event" signal, to install idle handler. // This will be called when the "event" signal is issued on any GtkWidget object. static gboolean -event_emission_hook(GSignalInvocationHint*, guint, const GValue*, gpointer) +event_emission_hook(GSignalInvocationHint*, guint, const GValue*, gpointer data) { wxapp_install_idle_handler(); + bool* hook_installed = (bool*)data; + *hook_installed = false; // remove hook return false; } @@ -159,12 +161,17 @@ event_emission_hook(GSignalInvocationHint*, guint, const GValue*, gpointer) // add emission hook for "event" signal, to re-install idle handler when needed static inline void wxAddEmissionHook() { + static bool hook_installed; GType widgetType = GTK_TYPE_WIDGET; - // if GtkWidget type is loaded - if (g_type_class_peek(widgetType) != NULL) + // if hook not installed and GtkWidget type is loaded + if (!hook_installed && g_type_class_peek(widgetType)) { - guint sig_id = g_signal_lookup("event", widgetType); - g_signal_add_emission_hook(sig_id, 0, event_emission_hook, NULL, NULL); + static guint sig_id; + if (sig_id == 0) + sig_id = g_signal_lookup("event", widgetType); + hook_installed = true; + g_signal_add_emission_hook( + sig_id, 0, event_emission_hook, &hook_installed, NULL); } }