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) |
sergei
2017/09/28 08:29:03
Could you please point to where and how it's actua
anton
2017/09/28 09:08:39
Java's `synchronized` token excludes mutiple threa
sergei
2017/09/28 09:33:05
BTW, I plan to add an asynchronous version of crea
|
{ |
+ 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; |
} |
} |