diff options
author | Silenio Quarti <silenio> | 2007-04-23 21:56:41 +0000 |
---|---|---|
committer | Silenio Quarti <silenio> | 2007-04-23 21:56:41 +0000 |
commit | 61e93ffeef869fe08ad54c059aecd52c9da29b71 (patch) | |
tree | 7b5b1a4c62099a46f0965260f4bae212b41d86ed | |
parent | 45bd6882b89a28418cf82b050cd85ff9c325f6c8 (diff) | |
download | eclipse.platform.swt-61e93ffeef869fe08ad54c059aecd52c9da29b71.tar.gz eclipse.platform.swt-61e93ffeef869fe08ad54c059aecd52c9da29b71.tar.xz eclipse.platform.swt-61e93ffeef869fe08ad54c059aecd52c9da29b71.zip |
176491 MessageBox consumes 100% CPU on Linux/GTK
7 files changed, 72 insertions, 26 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Printing/gtk/org/eclipse/swt/printing/PrintDialog.java b/bundles/org.eclipse.swt/Eclipse SWT Printing/gtk/org/eclipse/swt/printing/PrintDialog.java index 4f581a8c05..bacce111cf 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Printing/gtk/org/eclipse/swt/printing/PrintDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Printing/gtk/org/eclipse/swt/printing/PrintDialog.java @@ -33,6 +33,9 @@ public class PrintDialog extends Dialog { int /*long*/ handle; int index; byte [] settingsData; + + static final String ADD_IDLE_PROC_KEY = "org.eclipse.swt.internal.gtk2.addIdleProc"; + static final String REMOVE_IDLE_PROC_KEY = "org.eclipse.swt.internal.gtk2.removeIdleProc"; /** * Constructs a new instance of this class given only its parent. @@ -249,9 +252,7 @@ public PrinterData open() { PrinterData data = null; //TODO: Handle 'Print Preview' (GTK_RESPONSE_APPLY). Display display = getParent() != null ? getParent().getDisplay (): Display.getCurrent (); - String key = "org.eclipse.swt.internal.gtk2.idleProc"; - LONG idleProc = (LONG) display.getData (key); - int idleHandle = OS.g_idle_add (idleProc.value, 0); + display.setData (ADD_IDLE_PROC_KEY, null); if (OS.gtk_dialog_run (handle) == OS.GTK_RESPONSE_OK) { int /*long*/ printer = OS.gtk_print_unix_dialog_get_selected_printer(handle); if (printer != 0) { @@ -332,7 +333,7 @@ public PrinterData open() { OS.g_object_unref(settings); } } - OS.g_source_remove (idleHandle); + display.setData (REMOVE_IDLE_PROC_KEY, null); OS.gtk_widget_destroy (handle); return data; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java index 05d5a586c3..0e324d5a09 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java @@ -131,7 +131,7 @@ public RGB open () { } OS.gtk_color_selection_set_has_palette (dialog.colorsel, true); Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - int idleHandle = OS.g_idle_add (display.idleProc, 0); + display.addIdleProc (); int response = OS.gtk_dialog_run (handle); boolean success = response == OS.GTK_RESPONSE_OK; if (success) { @@ -141,7 +141,7 @@ public RGB open () { int blue = (color.blue >> 8) & 0xFF; rgb = new RGB (red, green, blue); } - OS.g_source_remove (idleHandle); + display.removeIdleProc (); OS.gtk_widget_destroy (handle); if (!success) return null; return rgb; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java index 99d67d6b44..2e5d5d6559 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java @@ -157,7 +157,7 @@ String openChooserDialog () { } String answer = null; Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - int idleHandle = OS.g_idle_add (display.idleProc, 0); + display.addIdleProc (); int response = OS.gtk_dialog_run (handle); if (response == OS.GTK_RESPONSE_OK) { int /*long*/ path = OS.gtk_file_chooser_get_filename (handle); @@ -179,7 +179,7 @@ String openChooserDialog () { } } } - OS.g_source_remove (idleHandle); + display.removeIdleProc (); OS.gtk_widget_destroy (handle); return answer; } @@ -227,7 +227,7 @@ String openClassicDialog () { OS.gtk_widget_show (labelHandle); } Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - int idleHandle = OS.g_idle_add (display.idleProc, 0); + display.addIdleProc (); int response = OS.gtk_dialog_run (handle); if (response == OS.GTK_RESPONSE_OK) { int /*long*/ fileNamePtr = OS.gtk_file_selection_get_filename (handle); @@ -252,7 +252,7 @@ String openClassicDialog () { OS.g_free (utf8Ptr); } } - OS.g_source_remove (idleHandle); + display.removeIdleProc (); OS.gtk_widget_destroy (handle); return answer; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java index 648e9c5d98..594b75b29e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java @@ -192,9 +192,13 @@ public class Display extends Device { /* Idle proc callback */ int /*long*/ idleProc; + int idleHandle; Callback idleCallback; - static final String IDLE_PROC_KEY = "org.eclipse.swt.internal.gtk2.idleProc"; - + static final String ADD_IDLE_PROC_KEY = "org.eclipse.swt.internal.gtk2.addIdleProc"; + static final String REMOVE_IDLE_PROC_KEY = "org.eclipse.swt.internal.gtk2.removeIdleProc"; + Object idleLock = new Object(); + boolean idleNeeded; + /* GtkTreeView callbacks */ int[] treeSelection; int treeSelectionLength; @@ -539,6 +543,15 @@ void addGdkEvent (int /*long*/ event) { gdkEventCount++; } +void addIdleProc() { + synchronized (idleLock){ + this.idleNeeded = true; + if (idleHandle == 0) { + idleHandle = OS.g_idle_add (idleProc, 0); + } + } +} + /** * Adds the listener to the collection of listeners who will * be notified when an event of the given type occurs. The event @@ -650,6 +663,12 @@ void addWidget (int /*long*/ handle, Widget widget) { */ public void asyncExec (Runnable runnable) { if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); + synchronized (idleLock) { + if (idleNeeded && idleHandle == 0) { + //NOTE: calling unlocked function in OS + idleHandle = OS._g_idle_add (idleProc, 0); + } + } synchronizer.asyncExec (runnable); } @@ -1502,9 +1521,6 @@ public Object getData (String key) { if (key.equals (DISPATCH_EVENT_KEY)) { return dispatchEvents; } - if (key.equals (IDLE_PROC_KEY)) { - return new LONG (idleProc); - } if (keys == null) return null; for (int i=0; i<keys.length; i++) { if (keys [i].equals (key)) return values [i]; @@ -2212,8 +2228,13 @@ Widget getWidget (int /*long*/ handle) { } int /*long*/ idleProc (int /*long*/ data) { - runAsyncMessages (false); - return 1; + boolean result = runAsyncMessages (false); + if (!result) { + synchronized (idleLock) { + idleHandle = 0; + } + } + return result ? 1 : 0; } /** @@ -3046,7 +3067,9 @@ void releaseDisplay () { /* Dispose the run async messages callback */ idleCallback.dispose (); idleCallback = null; idleProc = 0; - + if (idleHandle != 0) OS.g_source_remove (idleHandle); + idleHandle = 0; + /* Dispose GtkTreeView callbacks */ treeSelectionCallback.dispose (); treeSelectionCallback = null; treeSelectionProc = 0; @@ -3199,6 +3222,13 @@ int /*long*/ removeGdkEvent () { return event; } +void removeIdleProc () { + synchronized(idleLock) { + if (idleHandle != 0) OS.g_source_remove (idleHandle); + idleNeeded = false; + idleHandle = 0; + } +} /** * Removes the listener from the collection of listeners who will * be notified when an event of the given type occurs. The event type @@ -3438,6 +3468,15 @@ public void setData (String key, Object value) { removeWidget (handle); } } + + if (key.equals (ADD_IDLE_PROC_KEY)) { + addIdleProc (); + return; + } + if (key.equals (REMOVE_IDLE_PROC_KEY)) { + removeIdleProc (); + return; + } /* Remove the key/value pair */ if (value == null) { @@ -3846,6 +3885,12 @@ int /*long*/ styleSetProc (int /*long*/ gobject, int /*long*/ arg1, int /*long*/ */ public void syncExec (Runnable runnable) { if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); + synchronized (idleLock) { + if (idleNeeded && idleHandle == 0) { + //NOTE: calling unlocked function in OS + idleHandle = OS._g_idle_add (idleProc, 0); + } + } synchronizer.syncExec (runnable); } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java index a50bbbf62f..f4e062d20c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java @@ -322,12 +322,12 @@ String openChooserDialog () { } presetChooserDialog (); Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - int idleHandle = OS.g_idle_add (display.idleProc, 0); + display.addIdleProc (); String answer = null; if (OS.gtk_dialog_run (handle) == OS.GTK_RESPONSE_OK) { answer = computeResultChooserDialog (); } - OS.g_source_remove (idleHandle); + display.removeIdleProc (); OS.gtk_widget_destroy (handle); return answer; } @@ -345,12 +345,12 @@ String openClassicDialog () { } presetClassicDialog (); Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - int idleHandle = OS.g_idle_add (display.idleProc, 0); + display.addIdleProc (); String answer = null; if (OS.gtk_dialog_run (handle) == OS.GTK_RESPONSE_OK) { answer = computeResultClassicDialog (); } - OS.g_source_remove (idleHandle); + display.removeIdleProc (); OS.gtk_widget_destroy (handle); return answer; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java index a410f9561a..fd1ad31aee 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java @@ -155,7 +155,7 @@ public FontData open () { OS.gtk_font_selection_dialog_set_font_name (handle, buffer); } Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - int idleHandle = OS.g_idle_add (display.idleProc, 0); + display.addIdleProc (); int response = OS.gtk_dialog_run(handle); boolean success = response == OS.GTK_RESPONSE_OK; if (success) { @@ -169,7 +169,7 @@ public FontData open () { fontData = font.getFontData () [0]; OS.pango_font_description_free (fontDesc); } - OS.g_source_remove (idleHandle); + display.removeIdleProc (); OS.gtk_widget_destroy(handle); if (!success) return null; return fontData; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java index 2285279893..48aafc07cd 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java @@ -148,9 +148,9 @@ public int open () { buffer = Converter.wcsToMbcs(null, title, true); OS.gtk_window_set_title(handle,buffer); Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - int idleHandle = OS.g_idle_add (display.idleProc, 0); + display.addIdleProc (); int result = OS.gtk_dialog_run (handle); - OS.g_source_remove (idleHandle); + display.removeIdleProc (); OS.gtk_widget_destroy (handle); return result; } |