提交 c7209913 编写于 作者: B bagiras

2228674: Fix failed for CR 7162144

Reviewed-by: art, anthony
上级 eb3eb786
/* /*
* Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,19 +25,11 @@ ...@@ -25,19 +25,11 @@
package java.awt; package java.awt;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.lang.reflect.Method;
import java.security.AccessController;
import sun.security.action.GetPropertyAction;
import sun.awt.AWTAutoShutdown;
import sun.awt.SunToolkit;
import sun.awt.AppContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
import sun.awt.dnd.SunDragSourceContextPeer; import sun.awt.dnd.SunDragSourceContextPeer;
...@@ -67,8 +59,7 @@ class EventDispatchThread extends Thread { ...@@ -67,8 +59,7 @@ class EventDispatchThread extends Thread {
private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.EventDispatchThread"); private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.EventDispatchThread");
private EventQueue theQueue; private EventQueue theQueue;
private boolean doDispatch = true; private volatile boolean doDispatch = true;
private volatile boolean shutdown = false;
private static final int ANY_EVENT = -1; private static final int ANY_EVENT = -1;
...@@ -86,24 +77,15 @@ class EventDispatchThread extends Thread { ...@@ -86,24 +77,15 @@ class EventDispatchThread extends Thread {
doDispatch = false; doDispatch = false;
} }
public void interrupt() {
shutdown = true;
super.interrupt();
}
public void run() { public void run() {
while (true) { try {
try { pumpEvents(new Conditional() {
pumpEvents(new Conditional() { public boolean evaluate() {
public boolean evaluate() { return true;
return true;
}
});
} finally {
if(getEventQueue().detachDispatchThread(this, shutdown)) {
break;
} }
} });
} finally {
getEventQueue().detachDispatchThread(this);
} }
} }
...@@ -130,8 +112,7 @@ class EventDispatchThread extends Thread { ...@@ -130,8 +112,7 @@ class EventDispatchThread extends Thread {
void pumpEventsForFilter(int id, Conditional cond, EventFilter filter) { void pumpEventsForFilter(int id, Conditional cond, EventFilter filter) {
addEventFilter(filter); addEventFilter(filter);
doDispatch = true; doDispatch = true;
shutdown |= isInterrupted(); while (doDispatch && !isInterrupted() && cond.evaluate()) {
while (doDispatch && !shutdown && cond.evaluate()) {
pumpOneEventForFilters(id); pumpOneEventForFilters(id);
} }
removeEventFilter(filter); removeEventFilter(filter);
...@@ -223,12 +204,12 @@ class EventDispatchThread extends Thread { ...@@ -223,12 +204,12 @@ class EventDispatchThread extends Thread {
} }
} }
catch (ThreadDeath death) { catch (ThreadDeath death) {
shutdown = true; doDispatch = false;
throw death; throw death;
} }
catch (InterruptedException interruptedException) { catch (InterruptedException interruptedException) {
shutdown = true; // AppContext.dispose() interrupts all doDispatch = false; // AppContext.dispose() interrupts all
// Threads in the AppContext // Threads in the AppContext
} }
catch (Throwable e) { catch (Throwable e) {
processException(e); processException(e);
......
/* /*
* Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -1074,7 +1074,7 @@ public class EventQueue { ...@@ -1074,7 +1074,7 @@ public class EventQueue {
} }
} }
final boolean detachDispatchThread(EventDispatchThread edt, boolean forceDetach) { final void detachDispatchThread(EventDispatchThread edt) {
/* /*
* Minimize discard possibility for non-posted events * Minimize discard possibility for non-posted events
*/ */
...@@ -1090,17 +1090,9 @@ public class EventQueue { ...@@ -1090,17 +1090,9 @@ public class EventQueue {
pushPopLock.lock(); pushPopLock.lock();
try { try {
if (edt == dispatchThread) { if (edt == dispatchThread) {
/*
* Don't detach the thread if any events are pending. Not
* sure if it's a possible scenario, though.
*/
if (!forceDetach && (peekEvent() != null)) {
return false;
}
dispatchThread = null; dispatchThread = null;
} }
AWTAutoShutdown.getInstance().notifyThreadFree(edt); AWTAutoShutdown.getInstance().notifyThreadFree(edt);
return true;
} finally { } finally {
pushPopLock.unlock(); pushPopLock.unlock();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册