aboutsummaryrefslogtreecommitdiffstats
path: root/java/direct_bt/tinyb/DBTAdapter.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-09-30 11:07:13 +0200
committerSven Gothel <[email protected]>2020-09-30 11:07:13 +0200
commitbda1e0d415257544c94ebfff87af8424166dd316 (patch)
tree4c88f6b0b1897b0bb3eccb012109cd6705032882 /java/direct_bt/tinyb/DBTAdapter.java
parent95f4fec352f679ebab32b80b15d14cfa0042f15b (diff)
DBT[Adapter|Device].close(): Utilize own AtomicBoolean synchronization avoiding reentry; DBTAdapter.removeStatusListener(): Avoid @ within isClosing (warning on failure)
Diffstat (limited to 'java/direct_bt/tinyb/DBTAdapter.java')
-rw-r--r--java/direct_bt/tinyb/DBTAdapter.java16
1 files changed, 14 insertions, 2 deletions
diff --git a/java/direct_bt/tinyb/DBTAdapter.java b/java/direct_bt/tinyb/DBTAdapter.java
index d3e42fab..645f93a1 100644
--- a/java/direct_bt/tinyb/DBTAdapter.java
+++ b/java/direct_bt/tinyb/DBTAdapter.java
@@ -65,6 +65,8 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter
private final Object discoveredDevicesLock = new Object();
private final Object userCallbackLock = new Object();
+ private final AtomicBoolean isClosing = new AtomicBoolean(false);
+
private final AtomicBoolean isPowered = new AtomicBoolean(false); // AdapterSettings
private BluetoothNotification<Boolean> userPairableNotificationCB = null;
private final AtomicBoolean isDiscoverable = new AtomicBoolean(false); // AdapterSettings
@@ -89,10 +91,13 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter
public final BluetoothManager getManager() { return DBTManager.getManager(); }
@Override
- public synchronized void close() {
+ public void close() {
if( !isValid() ) {
return;
}
+ if( !isClosing.compareAndSet(false, true) ) {
+ return;
+ }
// mute all listener first
removeAllStatusListener();
disableDiscoverableNotifications();
@@ -386,7 +391,14 @@ public class DBTAdapter extends DBTObject implements BluetoothAdapter
public native boolean addStatusListener(final AdapterStatusListener l, final BluetoothDevice deviceMatch);
@Override
- public native boolean removeStatusListener(final AdapterStatusListener l);
+ public boolean removeStatusListener(final AdapterStatusListener l) {
+ if( !isClosing.get() ) {
+ return removeStatusListenerImpl(l);
+ }
+ return false;
+ }
+
+ private native boolean removeStatusListenerImpl(final AdapterStatusListener l);
@Override
public native int removeAllStatusListener();