|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
| 17 | +#include "admob/src/android/banner_view_internal_android.h" |
| 18 | + |
17 | 19 | #include <assert.h>
|
18 | 20 | #include <jni.h>
|
19 | 21 |
|
|
23 | 25 | #include "admob/admob_resources.h"
|
24 | 26 | #include "admob/src/android/ad_request_converter.h"
|
25 | 27 | #include "admob/src/android/admob_android.h"
|
26 |
| -#include "admob/src/android/banner_view_internal_android.h" |
27 | 28 | #include "admob/src/common/admob_common.h"
|
28 | 29 | #include "admob/src/include/firebase/admob.h"
|
29 | 30 | #include "admob/src/include/firebase/admob/banner_view.h"
|
30 | 31 | #include "admob/src/include/firebase/admob/types.h"
|
31 | 32 | #include "app/src/assert.h"
|
32 | 33 | #include "app/src/mutex.h"
|
| 34 | +#include "app/src/semaphore.h" |
33 | 35 | #include "app/src/util_android.h"
|
34 | 36 |
|
35 | 37 | namespace firebase {
|
@@ -59,21 +61,13 @@ BannerViewInternalAndroid::BannerViewInternalAndroid(BannerView* base)
|
59 | 61 | BannerViewInternalAndroid::~BannerViewInternalAndroid() {
|
60 | 62 | JNIEnv* env = ::firebase::admob::GetJNI();
|
61 | 63 |
|
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 |
| - } |
| 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 | + |
77 | 71 | env->DeleteGlobalRef(helper_);
|
78 | 72 | helper_ = nullptr;
|
79 | 73 | }
|
@@ -131,8 +125,7 @@ Future<void> BannerViewInternalAndroid::Resume() {
|
131 | 125 | }
|
132 | 126 |
|
133 | 127 | Future<void> BannerViewInternalAndroid::Destroy() {
|
134 |
| - // The bounding box is zeroed on destroy. |
135 |
| - bounding_box_ = {}; |
| 128 | + DestroyInternalData(); |
136 | 129 | return InvokeNullary(kBannerViewFnDestroy, banner_view_helper::kDestroy);
|
137 | 130 | }
|
138 | 131 |
|
@@ -214,6 +207,12 @@ Future<void> BannerViewInternalAndroid::InvokeNullary(
|
214 | 207 | return GetLastResult(fn);
|
215 | 208 | }
|
216 | 209 |
|
| 210 | +void BannerViewInternalAndroid::DestroyInternalData() { |
| 211 | + // The bounding box is zeroed on destroy. |
| 212 | + bounding_box_ = {}; |
| 213 | +} |
| 214 | + |
| 215 | + |
217 | 216 | } // namespace internal
|
218 | 217 | } // namespace admob
|
219 | 218 | } // namespace firebase
|
0 commit comments