From 3a5eb0237b6f8e5a129ca6054f4a2704f89431ec Mon Sep 17 00:00:00 2001 From: Konstantin Ritt Date: Fri, 13 Mar 2020 14:27:47 +0300 Subject: Android: Re-use `pendingJob` storage introduced by 962f282d21e62b8d to make the code less error prone Change-Id: I429bf367c9d44f24356f4ee70c0f6045b0557604 Reviewed-by: Oliver Wolff Reviewed-by: Alex Blasche --- .../qt5/android/bluetooth/QtBluetoothLE.java | 30 ++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java index 13b97c8c..e9717a1d 100644 --- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java +++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java @@ -296,7 +296,7 @@ public class QtBluetoothLE { //unlock the queue for next item synchronized (readWriteQueue) { - ioJobPending = false; + pendingJob = null; } performNextIO(); @@ -309,7 +309,7 @@ public class QtBluetoothLE { if (requestTimedOut) { Log.w(TAG, "Late char read reply after timeout was hit for handle " + foundHandle); // Timeout has hit before this response -> ignore the response - // no need to unlock ioJobPending -> the timeout has done that already + // no need to unlock pendingJob -> the timeout has done that already return; } @@ -349,7 +349,7 @@ public class QtBluetoothLE { //unlock the queue for next item synchronized (readWriteQueue) { - ioJobPending = false; + pendingJob = null; } performNextIO(); @@ -373,7 +373,7 @@ public class QtBluetoothLE { if (requestTimedOut) { Log.w(TAG, "Late char write reply after timeout was hit for handle " + handle); // Timeout has hit before this response -> ignore the response - // no need to unlock ioJobPending -> the timeout has done that already + // no need to unlock pendingJob -> the timeout has done that already return; } @@ -389,7 +389,7 @@ public class QtBluetoothLE { byte[] value; synchronized (readWriteQueue) { value = pendingJob.newValue; - ioJobPending = false; + pendingJob = null; } leCharacteristicWritten(qtObject, handle+1, value, errorCode); performNextIO(); @@ -420,7 +420,7 @@ public class QtBluetoothLE { //unlock the queue for next item synchronized (readWriteQueue) { - ioJobPending = false; + pendingJob = null; } performNextIO(); return; @@ -433,7 +433,7 @@ public class QtBluetoothLE { Log.w(TAG, "Late descriptor read reply after timeout was hit for handle " + foundHandle); // Timeout has hit before this response -> ignore the response - // no need to unlock ioJobPending -> the timeout has done that already + // no need to unlock pendingJob -> the timeout has done that already return; } @@ -492,7 +492,7 @@ public class QtBluetoothLE { //unlock the queue for next item synchronized (readWriteQueue) { - ioJobPending = false; + pendingJob = null; } performNextIO(); @@ -513,7 +513,7 @@ public class QtBluetoothLE { Log.w(TAG, "Late descriptor write reply after timeout was hit for handle " + handle); // Timeout has hit before this response -> ignore the response - // no need to unlock ioJobPending -> the timeout has done that already + // no need to unlock pendingJob -> the timeout has done that already return; } @@ -527,7 +527,7 @@ public class QtBluetoothLE { } synchronized (readWriteQueue) { - ioJobPending = false; + pendingJob = null; } leDescriptorWritten(qtObject, handle+1, descriptor.getValue(), errorCode); @@ -560,12 +560,12 @@ public class QtBluetoothLE { if (requestTimedOut) { Log.w(TAG, "Late mtu reply after timeout was hit"); // Timeout has hit before this response -> ignore the response - // no need to unlock ioJobPending -> the timeout has done that already + // no need to unlock pendingJob -> the timeout has done that already return; } synchronized (readWriteQueue) { - ioJobPending = false; + pendingJob = null; } performNextIO(); @@ -725,7 +725,6 @@ public class QtBluetoothLE { private final LinkedList readWriteQueue = new LinkedList(); - private boolean ioJobPending; private ReadWriteJob pendingJob; /* @@ -1248,7 +1247,7 @@ public class QtBluetoothLE { { //unlock the queue for next item synchronized (readWriteQueue) { - ioJobPending = false; + pendingJob = null; } performNextIOThreaded(); @@ -1309,7 +1308,7 @@ public class QtBluetoothLE { int handle = HANDLE_FOR_RESET; synchronized (readWriteQueue) { - if (readWriteQueue.isEmpty() || ioJobPending) + if (readWriteQueue.isEmpty() || pendingJob != null) return; nextJob = readWriteQueue.remove(); @@ -1353,7 +1352,6 @@ public class QtBluetoothLE { if (skip) { handleForTimeout.set(HANDLE_FOR_RESET); // not a pending call -> release atomic } else { - ioJobPending = true; pendingJob = nextJob; timeoutHandler.postDelayed(new TimeoutRunnable( modifiedReadWriteHandle(handle, nextJob.jobType)), RUNNABLE_TIMEOUT); -- cgit v1.2.3