[gui][patch] change to single-threaded event loop
graydon hoare
graydon@redhat.com
Tue Jan 4 19:34:00 GMT 2005
hi,
this patch, which I just committed to the java-gui-branch, reduces the
number of threads needed to support the AWT event loop from 2 to 1. it
does this by having the dispatch thread move back and forth between
iterating the native event loop (on the native side of JNI) and
iterating the AWT event loop, up in java. events are transferred in
batches, so that the JNI traffic isn't too heavy.
in addition, I added support for the precise shutdown condition of AWT
applications. when all windows are destroyed, and both the native and
java event queues are empty, the (single) event dispatch thread exits,
allowing the program to terminate along with its main thread.
I tried to hack support for this scheme into the X toolkit as well, but
I'm not certain how successful I was -- it runs, but behaves oddly --
since much of the X toolkit seems broken at the moment.
-graydon
2005-01-04 Graydon Hoare <graydon@redhat.com>
* Makefile.am
(jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c)
(gnu/java/awt/peer/gtk/GtkMainThread.java) : Remove.
* Makefile.in: Regenerate.
* gnu/awt/xlib/XEventLoop.java: Fix to match thread model.
* gnu/awt/xlib/XFramePeer.java: Likewise.
* gnu/awt/xlib/XToolkit.java: Likewise.
* gnu/gcj/xlib/XAnyEvent.java: Likewise.
* gnu/gcj/xlib/natXAnyEvent.cc: Likewise.
* gnu/java/awt/ClasspathToolkit.java
(nativeQueueEmpty)
(wakeNativeQueue)
(iterateNativeQueue): New methods.
* gnu/java/awt/peer/gtk/GtkMainThread.java: Remove.
* gnu/java/awt/peer/gtk/GtkToolkit.java
(gtkInit): Absorb from defunct GtkMainThread class.
(static): Run gtkInit in static startup block.
(GtkToolkit): Remove construction of GtkMainThread and queue.
(getSystemEventQueueImpl): Construct queue when requested.
(nativeQueueEmpty)
(wakeNativeQueue)
(iterateNativeQueue): New methods.
* java/awt/Component.java (removeNotify): Remove race.
* java/awt/EventDispatchThread.java
(EventDispatchThread): Don't start on construction.
(run): Remove isInterrupted check.
* java/awt/EventQueue.java (shutdown): New flag.
(isShutdown): New method checking J2SE shutdown condition.
(setShutdown): New method.
(getNextEvent): Restructure to use ClasspathToolkit.
(postEvent): Activate new thread on posting, wake thread on
post of possible shutdown condition event.
* java/awt/Frame.java
(Frame): Call noteFrame in all constructors.
(fireDummyEvent): New helper method.
(addNotify): Fire a dummy event to wake up queue.
(removeNotify): Fire a dummy event to wake up queue.
(noteFrame): New method.
(weakFrames): New static field.
(getFrames): Implement.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkMainThread.c:
Remove.
* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c:
Move everything from GtkMainThread into this file
(Java_gnu_java_awt_peer_gtk_GtkToolkit_iterateNativeQueue)
(Java_gnu_java_awt_peer_gtk_GtkToolkit_wakeNativeQueue)
(Java_gnu_java_awt_peer_gtk_GtkToolkit_nativeQueueEmpty):
New functions to implement single-threaded queue semantics.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: java-gui-single-gtk-thread.patch
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20050104/7d6b27d2/attachment.ksh>
More information about the Java-patches
mailing list