This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix to EventQueue 2/7 [REPOST]


I noticed that they did not reset the event queue after transfering it.
So I've added this piece.

P.S.: I did not reuse the EventQueue after poping it. The only reason I am fixing this is because there isn't anything in the documentation that says it Can't be reused (for instance if we decide to create a pool of EventQueues).

2004-01-13 Fernando Nasser <fnasser@redhat.com>

        * java/awt/EventDispatchThread.java (run): Stop running when
        interrupted.
        * java/awt/EventQueue.java (pop): Stop dispatch thread when done.
	Reset the queue after transfering its contents.
        (push): Start a new dispatch thread if none is running.
Index: java/awt/EventDispatchThread.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/EventDispatchThread.java,v
retrieving revision 1.4
diff -u -p -r1.4 EventDispatchThread.java
--- java/awt/EventDispatchThread.java	22 Jan 2002 22:40:04 -0000	1.4
+++ java/awt/EventDispatchThread.java	13 Jan 2004 23:19:20 -0000
@@ -62,7 +62,17 @@ class EventDispatchThread extends Thread
         try
 	{
 	  AWTEvent evt = queue.getNextEvent();
+	  if (isInterrupted ())
+	    {
+	      // We are interrupted when we should finish executing
+	      return;
+	    }
 	  queue.dispatchEvent(evt);
+	}
+	catch (InterruptedException ie)
+	{
+	  // We are interrupted when we should finish executing
+	  return;
 	}
 	catch (Throwable x)
 	{
Index: java/awt/EventQueue.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/awt/EventQueue.java,v
retrieving revision 1.12
diff -u -p -r1.12 EventQueue.java
--- java/awt/EventQueue.java	13 Jan 2004 22:51:26 -0000	1.12
+++ java/awt/EventQueue.java	14 Jan 2004 14:53:20 -0000
@@ -301,8 +301,8 @@ public class EventQueue
   /**
    * Allows a custom EventQueue implementation to replace this one. 
    * All pending events are transferred to the new queue. Calls to postEvent,
-   * getNextEvent, and peekEvent are forwarded to the pushed queue until it
-   * is removed with a pop().
+   * getNextEvent, and peekEvent and others are forwarded to the pushed queue
+   * until it is removed with a pop().
    *
    * @exception NullPointerException if newEventQueue is null.
    */
@@ -320,6 +320,10 @@ public class EventQueue
         return;
       }
 
+    /* Make sure we have a live dispatch thread to drive the queue */
+    if (dispatchThread == null)
+      dispatchThread = new EventDispatchThread(this);
+
     int i = next_out;
     while (i != next_in)
       {
@@ -361,6 +365,13 @@ public class EventQueue
             if (++i == queue.length)
               i = 0;
           }
+	// Empt the queue so it can be reused
+	next_in = 0;
+	next_out = 0;
+
+        // Tell our EventDispatchThread that it can end execution
+        dispatchThread.interrupt ();
+	dispatchThread = null;
       }
   }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]