src/share/classes/sun/awt/SunToolkit.java

Print this page

        

@@ -2094,30 +2094,42 @@
 class PostEventQueue {
     private EventQueueItem queueHead = null;
     private EventQueueItem queueTail = null;
     private final EventQueue eventQueue;
 
+    // For the case when queue is cleared but events are not posted
+    private boolean isPending = false;
+
     PostEventQueue(EventQueue eq) {
         eventQueue = eq;
     }
 
     public synchronized boolean noEvents() {
-        return queueHead == null;
+        return queueHead == null && !isPending;
     }
 
     /*
      * Continually post pending AWTEvents to the Java EventQueue. The method
      * is synchronized to ensure the flush is completed before a new event
      * can be posted to this queue.
+     *
+     * 7177040: The method couldn't be wholly synchronized because of calls
+     * of EventQueue.postEvent() that uses pushPopLock, otherwise it could
+     * potentially lead to deadlock
      */
-    public synchronized void flush() {
-        EventQueueItem tempQueue = queueHead;
+    public void flush() {
+        EventQueueItem tempQueue;
+        synchronized (this) {
+            tempQueue = queueHead;
         queueHead = queueTail = null;
+            isPending = true;
+        }
         while (tempQueue != null) {
             eventQueue.postEvent(tempQueue.event);
             tempQueue = tempQueue.next;
         }
+        isPending = false;
     }
 
     /*
      * Enqueue an AWTEvent to be posted to the Java EventQueue.
      */