Index: libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java |
diff --git a/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java b/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java |
index 41592ace84661ace8e97c007e5a9caec66dc8e37..4f4929e64574a5ab784cddf685a6db4d9d451dea 100644 |
--- a/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java |
+++ b/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/AdblockHelper.java |
@@ -239,11 +239,16 @@ public class AdblockHelper |
* @param asynchronous If `true` engines will be created in background thread without locking of |
* current thread. Use waitForReady() before getEngine() later. |
* If `false` locks current thread. |
+ * @return if a new instance is allocated |
*/ |
- public synchronized void retain(boolean asynchronous) |
+ public synchronized boolean retain(boolean asynchronous) |
{ |
+ boolean firstInstance = false; |
+ |
if (referenceCounter.getAndIncrement() == 0) |
{ |
+ firstInstance = true; |
+ |
if (!asynchronous) |
{ |
createAdblock(); |
@@ -266,15 +271,21 @@ public class AdblockHelper |
}).start(); |
} |
} |
+ return firstInstance; |
} |
/** |
* Unregister AdblockHelper engine client |
+ * @return `true` if the last instance is destroyed |
*/ |
- public synchronized void release() |
+ public synchronized boolean release() |
{ |
+ boolean lastInstance = false; |
+ |
if (referenceCounter.decrementAndGet() == 0) |
{ |
+ lastInstance = true; |
+ |
if (engineCreated != null) |
{ |
// retained asynchronously |
@@ -290,5 +301,6 @@ public class AdblockHelper |
disposeAdblock(); |
} |
} |
+ return lastInstance; |
} |
} |