mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
debugger event queue: more robust command cancellation when queue is closed
This commit is contained in:
@@ -73,22 +73,20 @@ public class DebuggerManagerThreadImpl extends InvokeAndWaitThread<DebuggerComma
|
||||
}
|
||||
}
|
||||
|
||||
public void pushBack(DebuggerCommandImpl managerCommand) {
|
||||
if(myEvents.isClosed()) {
|
||||
public boolean pushBack(DebuggerCommandImpl managerCommand) {
|
||||
final boolean pushed = super.pushBack(managerCommand);
|
||||
if (!pushed) {
|
||||
managerCommand.notifyCancelled();
|
||||
}
|
||||
else {
|
||||
super.pushBack(managerCommand);
|
||||
}
|
||||
return pushed;
|
||||
}
|
||||
|
||||
public void schedule(DebuggerCommandImpl managerCommand) {
|
||||
if(myEvents.isClosed()) {
|
||||
public boolean schedule(DebuggerCommandImpl managerCommand) {
|
||||
final boolean scheduled = super.schedule(managerCommand);
|
||||
if (!scheduled) {
|
||||
managerCommand.notifyCancelled();
|
||||
}
|
||||
else {
|
||||
super.schedule(managerCommand);
|
||||
}
|
||||
return scheduled;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,36 +45,42 @@ public class EventQueue<E> {
|
||||
}
|
||||
}
|
||||
|
||||
public void pushBack(@NotNull E event, int priority) {
|
||||
public boolean pushBack(@NotNull E event, int priority) {
|
||||
if(LOG.isDebugEnabled()) {
|
||||
LOG.debug("pushBack event " + event);
|
||||
}
|
||||
|
||||
myLock.lock();
|
||||
try {
|
||||
assertOpen();
|
||||
if (isClosed()) {
|
||||
return false;
|
||||
}
|
||||
getEventsList(priority).addFirst(event);
|
||||
myEventsAvailable.signalAll();
|
||||
}
|
||||
finally {
|
||||
myLock.unlock();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void put(@NotNull E event, int priority) {
|
||||
public boolean put(@NotNull E event, int priority) {
|
||||
if(LOG.isDebugEnabled()) {
|
||||
LOG.debug("put event " + event);
|
||||
}
|
||||
|
||||
myLock.lock();
|
||||
try {
|
||||
assertOpen();
|
||||
if (isClosed()) {
|
||||
return false;
|
||||
}
|
||||
getEventsList(priority).offer(event);
|
||||
myEventsAvailable.signalAll();
|
||||
}
|
||||
finally {
|
||||
myLock.unlock();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private LinkedList<E> getEventsList(final int priority) {
|
||||
@@ -84,7 +90,6 @@ public class EventQueue<E> {
|
||||
public void close(){
|
||||
myLock.lock();
|
||||
try {
|
||||
assertOpen();
|
||||
myIsClosed = true;
|
||||
myEventsAvailable.signalAll();
|
||||
}
|
||||
@@ -93,10 +98,6 @@ public class EventQueue<E> {
|
||||
}
|
||||
}
|
||||
|
||||
private void assertOpen() {
|
||||
if (myIsClosed) throw new AssertionError("Already closed");
|
||||
}
|
||||
|
||||
private E getEvent() throws EventQueueClosedException {
|
||||
myLock.lock();
|
||||
try {
|
||||
|
||||
@@ -19,4 +19,8 @@ package com.intellij.debugger.impl;
|
||||
* @author lex
|
||||
*/
|
||||
public class EventQueueClosedException extends Exception {
|
||||
@Override
|
||||
public Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,12 +28,12 @@ public abstract class InvokeAndWaitThread<E extends DebuggerTask> extends Invoke
|
||||
* !!! Do not remove this code !!!
|
||||
* Otherwise it will be impossible to override schedule method
|
||||
*/
|
||||
public void schedule(E e) {
|
||||
super.schedule(e);
|
||||
public boolean schedule(E e) {
|
||||
return super.schedule(e);
|
||||
}
|
||||
|
||||
public void pushBack(E e) {
|
||||
super.pushBack(e);
|
||||
public boolean pushBack(E e) {
|
||||
return super.pushBack(e);
|
||||
}
|
||||
|
||||
public void invokeAndWait(final E runnable) {
|
||||
|
||||
@@ -172,18 +172,18 @@ public abstract class InvokeThread<E extends PrioritizedTask> {
|
||||
return request != null? request.getOwner() : null;
|
||||
}
|
||||
|
||||
public void schedule(E r) {
|
||||
public boolean schedule(E r) {
|
||||
if(LOG.isDebugEnabled()) {
|
||||
LOG.debug("schedule " + r + " in " + this);
|
||||
}
|
||||
myEvents.put(r, r.getPriority().ordinal());
|
||||
return myEvents.put(r, r.getPriority().ordinal());
|
||||
}
|
||||
|
||||
public void pushBack(E r) {
|
||||
public boolean pushBack(E r) {
|
||||
if(LOG.isDebugEnabled()) {
|
||||
LOG.debug("pushBack " + r + " in " + this);
|
||||
}
|
||||
myEvents.pushBack(r, r.getPriority().ordinal());
|
||||
return myEvents.pushBack(r, r.getPriority().ordinal());
|
||||
}
|
||||
|
||||
protected void switchToRequest(WorkerThreadRequest newWorkerThread) {
|
||||
|
||||
Reference in New Issue
Block a user