Skip to content

Commit fa1639a

Browse files
committed
Bug 573110: Emulator can spin if Reader is ready but not available
The implementation of the read loop in the emulator can spin because it uses Reader.ready() to determine if there is more data to read. However the Reader contract does not specify that ready() means that read() will return a character, simply it means that read() won't block. As such, if a Reader won't block, but it has no characters, the inner read loop will spin constantly polling. The outer loop uses polling too - but it has a wait so that the CPU does not hit 100% and yields. Change-Id: Id9b2426c65e6c2a2c3ae817a78d2be435e568c1f
1 parent 035c419 commit fa1639a

File tree

1 file changed

+4
-3
lines changed
  • terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator

1 file changed

+4
-3
lines changed

terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100Emulator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,9 +1515,10 @@ private char getNextChar() throws IOException {
15151515
}
15161516

15171517
private boolean hasNextChar() throws IOException {
1518-
if (fNextChar >= 0)
1519-
return true;
1520-
return fReader.ready();
1518+
if (fNextChar < 0 && fReader.ready()) {
1519+
fNextChar = fReader.read();
1520+
}
1521+
return fNextChar >= 0;
15211522
}
15221523

15231524
/**

0 commit comments

Comments
 (0)