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 {
@@ -56,24 +58,25 @@ BannerViewInternalAndroid::BannerViewInternalAndroid(BannerView* base)
56
58
env->DeleteLocalRef (helper_ref);
57
59
}
58
60
61
+
62
+ void DestroyOnDeleteCallback (const Future<void >& result,
63
+ void * sem_data) {
64
+ if (sem_data != nullptr ) {
65
+ Semaphore* semaphore = static_cast <Semaphore*>(sem_data);
66
+ semaphore->Post ();
67
+ }
68
+ }
69
+
59
70
BannerViewInternalAndroid::~BannerViewInternalAndroid () {
60
71
JNIEnv* env = ::firebase::admob::GetJNI ();
61
72
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
- }
73
+ DestroyInternalData ();
74
+
75
+ Semaphore semaphore (0 );
76
+ InvokeNullary (kBannerViewFnDestroyOnDelete , banner_view_helper::kDestroy )
77
+ .OnCompletion (DestroyOnDeleteCallback, &semaphore);
78
+
79
+ semaphore.Wait ();
77
80
env->DeleteGlobalRef (helper_);
78
81
helper_ = nullptr ;
79
82
}
@@ -131,8 +134,7 @@ Future<void> BannerViewInternalAndroid::Resume() {
131
134
}
132
135
133
136
Future<void > BannerViewInternalAndroid::Destroy () {
134
- // The bounding box is zeroed on destroy.
135
- bounding_box_ = {};
137
+ DestroyInternalData ();
136
138
return InvokeNullary (kBannerViewFnDestroy , banner_view_helper::kDestroy );
137
139
}
138
140
@@ -214,6 +216,11 @@ Future<void> BannerViewInternalAndroid::InvokeNullary(
214
216
return GetLastResult (fn);
215
217
}
216
218
219
+ void BannerViewInternalAndroid::DestroyInternalData () {
220
+ // The bounding box is zeroed on destroy.
221
+ bounding_box_ = {};
222
+ }
223
+
217
224
} // namespace internal
218
225
} // namespace admob
219
226
} // namespace firebase
0 commit comments