From e43651e57e9aa08c6a101ebd1d73c051b9003703 Mon Sep 17 00:00:00 2001 From: James Cotton Date: Sun, 12 Aug 2012 17:21:40 -0500 Subject: [PATCH] AndroidGCS: Add back a few synchronize blocks in telemetry to avoid removing elements twice. --- .../src/org/openpilot/uavtalk/Telemetry.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/androidgcs/src/org/openpilot/uavtalk/Telemetry.java b/androidgcs/src/org/openpilot/uavtalk/Telemetry.java index 21525ea14..f130c33eb 100644 --- a/androidgcs/src/org/openpilot/uavtalk/Telemetry.java +++ b/androidgcs/src/org/openpilot/uavtalk/Telemetry.java @@ -551,17 +551,22 @@ public class Telemetry { // Get object information from queue (first the priority and then the regular queue) ObjectQueueInfo objInfo; - if ( !objPriorityQueue.isEmpty() ) - { - objInfo = objPriorityQueue.remove(); - } - else if ( !objQueue.isEmpty() ) - { - objInfo = objQueue.remove(); - } - else - { - return; + synchronized (objPriorityQueue) { + if ( !objPriorityQueue.isEmpty() ) + { + objInfo = objPriorityQueue.remove(); + } else { + synchronized (objQueue) { + if ( !objQueue.isEmpty() ) + { + objInfo = objQueue.remove(); + } + else + { + return; + } + } + } } // Check if a connection has been established, only process GCSTelemetryStats updates