diff options
author | Sven Gothel <[email protected]> | 2020-09-30 11:07:13 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-09-30 11:07:13 +0200 |
commit | bda1e0d415257544c94ebfff87af8424166dd316 (patch) | |
tree | 4c88f6b0b1897b0bb3eccb012109cd6705032882 /java/direct_bt/tinyb/DBTAdapter.java | |
parent | 95f4fec352f679ebab32b80b15d14cfa0042f15b (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.java | 16 |
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(); |