|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -#include "admob/src/android/banner_view_internal_android.h" |
18 |
| - |
19 | 17 | #include <assert.h>
|
20 | 18 | #include <jni.h>
|
21 | 19 |
|
|
25 | 23 | #include "admob/admob_resources.h"
|
26 | 24 | #include "admob/src/android/ad_request_converter.h"
|
27 | 25 | #include "admob/src/android/admob_android.h"
|
| 26 | +#include "admob/src/android/banner_view_internal_android.h" |
28 | 27 | #include "admob/src/common/admob_common.h"
|
29 | 28 | #include "admob/src/include/firebase/admob.h"
|
30 | 29 | #include "admob/src/include/firebase/admob/banner_view.h"
|
31 | 30 | #include "admob/src/include/firebase/admob/types.h"
|
32 | 31 | #include "app/src/assert.h"
|
33 | 32 | #include "app/src/mutex.h"
|
34 |
| -#include "app/src/semaphore.h" |
35 | 33 | #include "app/src/util_android.h"
|
36 | 34 |
|
37 | 35 | namespace firebase {
|
@@ -61,13 +59,21 @@ BannerViewInternalAndroid::BannerViewInternalAndroid(BannerView* base)
|
61 | 59 | BannerViewInternalAndroid::~BannerViewInternalAndroid() {
|
62 | 60 | JNIEnv* env = ::firebase::admob::GetJNI();
|
63 | 61 |
|
64 |
| - DestroyInternalData(); |
65 |
| - |
66 |
| - Semaphore semaphore(0); |
67 |
| - InvokeNullary(kBannerViewFnDestroyOnDelete, banner_view_helper::kDestroy) |
68 |
| - .OnCompletion([&semaphore](const Future<void>&) { semaphore.Post(); }); |
69 |
| - semaphore.Wait(); |
70 |
| - |
| 62 | + // Destroy the banner view so all pending futures / callbacks complete. |
| 63 | + { |
| 64 | + Mutex mutex(Mutex::kModeNonRecursive); |
| 65 | + mutex.Acquire(); |
| 66 | + Destroy().OnCompletion( |
| 67 | + [](const Future<void>&, void* mutex) { |
| 68 | + reinterpret_cast<Mutex*>(mutex)->Release(); |
| 69 | + }, |
| 70 | + &mutex); |
| 71 | + // Acquire a second Mutex lock to block until the Future for the last call |
| 72 | + // to Destroy() completes at which point the lambda function in OnCompletion |
| 73 | + // is called and the Mutex lock is released. |
| 74 | + mutex.Acquire(); |
| 75 | + mutex.Release(); |
| 76 | + } |
71 | 77 | env->DeleteGlobalRef(helper_);
|
72 | 78 | helper_ = nullptr;
|
73 | 79 | }
|
@@ -125,7 +131,8 @@ Future<void> BannerViewInternalAndroid::Resume() {
|
125 | 131 | }
|
126 | 132 |
|
127 | 133 | Future<void> BannerViewInternalAndroid::Destroy() {
|
128 |
| - DestroyInternalData(); |
| 134 | + // The bounding box is zeroed on destroy. |
| 135 | + bounding_box_ = {}; |
129 | 136 | return InvokeNullary(kBannerViewFnDestroy, banner_view_helper::kDestroy);
|
130 | 137 | }
|
131 | 138 |
|
@@ -207,12 +214,6 @@ Future<void> BannerViewInternalAndroid::InvokeNullary(
|
207 | 214 | return GetLastResult(fn);
|
208 | 215 | }
|
209 | 216 |
|
210 |
| -void BannerViewInternalAndroid::DestroyInternalData() { |
211 |
| - // The bounding box is zeroed on destroy. |
212 |
| - bounding_box_ = {}; |
213 |
| -} |
214 |
| - |
215 |
| - |
216 | 217 | } // namespace internal
|
217 | 218 | } // namespace admob
|
218 | 219 | } // namespace firebase
|
0 commit comments