summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2011-08-09 18:27:19 -0700
committerKeith Packard <keithp@keithp.com>2011-08-09 18:27:19 -0700
commita680ce61bdcffeacb7f0e4dcef71a03cb7cfe07d (patch)
treecf56c0f5e67c51d55e0d4159264ef6013bb6a324
parent12bfa6cc42e3689f09abae2bd2584cbacf2aa2e0 (diff)
altosui: Ensure serial code tracks reply nesting correctly
Trap any exceptional return conditions from 'get_reply' to make sure in_reply gets decremented. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--altosui/AltosSerial.java49
1 files changed, 28 insertions, 21 deletions
diff --git a/altosui/AltosSerial.java b/altosui/AltosSerial.java
index 5e496d7f..b089c9c4 100644
--- a/altosui/AltosSerial.java
+++ b/altosui/AltosSerial.java
@@ -213,31 +213,38 @@ public class AltosSerial implements Runnable {
public String get_reply(int timeout) throws InterruptedException {
boolean can_cancel = true;
- ++in_reply;
+ String reply = null;
- if (SwingUtilities.isEventDispatchThread()) {
- can_cancel = false;
- if (remote)
- System.out.printf("Uh-oh, reading remote serial device from swing thread\n");
- }
- flush_output();
- if (remote && can_cancel) {
- timeout = 500;
- }
- abort = false;
- timeout_started = false;
- for (;;) {
- AltosLine line = reply_queue.poll(timeout, TimeUnit.MILLISECONDS);
- if (line != null) {
- stop_timeout_dialog();
- --in_reply;
- return line.line;
+ try {
+ ++in_reply;
+
+ if (SwingUtilities.isEventDispatchThread()) {
+ can_cancel = false;
+ if (remote)
+ System.out.printf("Uh-oh, reading remote serial device from swing thread\n");
}
- if (!remote || !can_cancel || check_timeout()) {
- --in_reply;
- return null;
+ flush_output();
+ if (remote && can_cancel) {
+ timeout = 500;
}
+ abort = false;
+ timeout_started = false;
+ for (;;) {
+ AltosLine line = reply_queue.poll(timeout, TimeUnit.MILLISECONDS);
+ if (line != null) {
+ stop_timeout_dialog();
+ reply = line.line;
+ break;
+ }
+ if (!remote || !can_cancel || check_timeout()) {
+ reply = null;
+ break;
+ }
+ }
+ } finally {
+ --in_reply;
}
+ return reply;
}
public String get_reply() throws InterruptedException {