1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-31 12:55:40 +02:00

Instead of doing sleep () do wait()

This commit is contained in:
Alain Magloire 2003-08-07 15:05:58 +00:00
parent f89792d824
commit 36975e135f

View file

@ -37,7 +37,7 @@ public class MIInferior extends Process {
OutputStream out; OutputStream out;
InputStream in; InputStream in;
PipedOutputStream inPiped; PipedOutputStream inPiped;
PipedInputStream err; PipedInputStream err;
@ -46,7 +46,6 @@ public class MIInferior extends Process {
int inferiorPid; int inferiorPid;
MIInferior(MISession mi, PTY p) { MIInferior(MISession mi, PTY p) {
session = mi; session = mi;
pty = p; pty = p;
@ -111,11 +110,9 @@ public class MIInferior extends Process {
/** /**
* @see java.lang.Process#waitFor() * @see java.lang.Process#waitFor()
*/ */
public int waitFor() throws InterruptedException { public synchronized int waitFor() throws InterruptedException {
if (!isTerminated()) { while (state != TERMINATED) {
synchronized (this) { wait();
wait();
}
} }
return exitValue(); return exitValue();
} }
@ -152,8 +149,7 @@ public class MIInferior extends Process {
// - For Program session: // - For Program session:
// if the inferior was not terminated. // if the inferior was not terminated.
// - For PostMortem(Core): noop // - For PostMortem(Core): noop
if ((session.isAttachSession() && isConnected()) || if ((session.isAttachSession() && isConnected()) || (session.isProgramSession() && !isTerminated())) {
(session.isProgramSession() && !isTerminated())) {
CommandFactory factory = session.getCommandFactory(); CommandFactory factory = session.getCommandFactory();
MIExecAbort abort = factory.createMIExecAbort(); MIExecAbort abort = factory.createMIExecAbort();
@ -168,28 +164,32 @@ public class MIInferior extends Process {
} }
} }
public void interrupt() throws MIException { public synchronized void interrupt() throws MIException {
Process gdb = session.getGDBProcess(); Process gdb = session.getGDBProcess();
if (gdb instanceof Spawner) { if (gdb instanceof Spawner) {
Spawner gdbSpawner = (Spawner)gdb; Spawner gdbSpawner = (Spawner) gdb;
gdbSpawner.interrupt(); gdbSpawner.interrupt();
// Allow (5 secs) for the interrupt to propagate. // Allow (5 secs) for the interrupt to propagate.
for (int i = 0; isRunning() && i < 5; i++) { for (int i = 0;(state == RUNNING) && i < 5; i++) {
try { try {
java.lang.Thread.sleep(1000); wait(1000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
} }
} }
if (isRunning() && inferiorPid > 0) { if ((state == RUNNING) && inferiorPid > 0) {
// lets try something else. // lets try something else.
gdbSpawner.raise(inferiorPid, gdbSpawner.INT); gdbSpawner.raise(inferiorPid, gdbSpawner.INT);
} for (int i = 0;(state == RUNNING) && i < 5; i++) {
for (int i = 0; isRunning() && i < 5; i++) { try {
try { wait(1000);
java.lang.Thread.sleep(1000); } catch (InterruptedException e) {
} catch (InterruptedException e) { }
} }
} }
// If we've failed throw an exception up.
if (state == RUNNING) {
throw new MIException("Failed to interrupt");
}
} else { } else {
// Try the exec-interrupt; this will be for "gdb --async" // Try the exec-interrupt; this will be for "gdb --async"
// CommandFactory factory = session.getCommandFactory(); // CommandFactory factory = session.getCommandFactory();
@ -229,10 +229,12 @@ public class MIInferior extends Process {
public synchronized void setSuspended() { public synchronized void setSuspended() {
state = SUSPENDED; state = SUSPENDED;
notifyAll();
} }
public synchronized void setRunning() { public synchronized void setRunning() {
state = RUNNING; state = RUNNING;
notifyAll();
} }
public synchronized void setTerminated() { public synchronized void setTerminated() {