summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2014-10-24 21:21:19 -0700
committerKeith Packard <keithp@keithp.com>2014-10-24 21:24:31 -0700
commit88df7cd314269fa1debe226b49b7e4e9dc238d8e (patch)
treedd82a4d0b17aa622eaf61a196088182b87b8c7e4
parent221824b038bf18ca43a38c82d18b0ae9586ba565 (diff)
altoslib: synchronize access to serial debug output list
This list is access by both the receiver and the monitor task, so it needs to be locked to prevent collisions. Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r--altoslib/AltosLink.java17
1 files changed, 11 insertions, 6 deletions
diff --git a/altoslib/AltosLink.java b/altoslib/AltosLink.java
index 62bd82b9..c0031cad 100644
--- a/altoslib/AltosLink.java
+++ b/altoslib/AltosLink.java
@@ -55,8 +55,11 @@ public abstract class AltosLink implements Runnable {
public void printf(String format, Object ... arguments) {
String line = String.format(format, arguments);
- if (debug)
- pending_output.add(line);
+ if (debug) {
+ synchronized (pending_output) {
+ pending_output.add(line);
+ }
+ }
try {
print(line);
} catch (InterruptedException ie) {
@@ -286,12 +289,14 @@ public abstract class AltosLink implements Runnable {
binary_queue.put(dup);
}
- public void flush_output() {
+ public synchronized void flush_output() {
if (pending_output == null)
return;
- for (String s : pending_output)
- System.out.print(s);
- pending_output.clear();
+ synchronized (pending_output) {
+ for (String s : pending_output)
+ System.out.print(s);
+ pending_output.clear();
+ }
}
public void flush_input(int timeout) throws InterruptedException {