diff --git a/android/sdk/src/main/jni/include/loader/adr_loader.h b/android/sdk/src/main/jni/include/loader/adr_loader.h index 79e0df3d8f9..8090d66ee4b 100644 --- a/android/sdk/src/main/jni/include/loader/adr_loader.h +++ b/android/sdk/src/main/jni/include/loader/adr_loader.h @@ -108,4 +108,5 @@ class ADRLoader : public hippy::base::UriLoader { std::shared_ptr bridge_; std::weak_ptr runner_; std::unordered_map> request_map_; + std::mutex mutex_; }; diff --git a/android/sdk/src/main/jni/src/loader/adr_loader.cc b/android/sdk/src/main/jni/src/loader/adr_loader.cc index 553a267e8dc..ad677d1c1ce 100644 --- a/android/sdk/src/main/jni/src/loader/adr_loader.cc +++ b/android/sdk/src/main/jni/src/loader/adr_loader.cc @@ -255,11 +255,13 @@ REGISTER_JNI("com/tencent/mtt/hippy/bridge/HippyBridgeImpl", // NOLINT(cert-err5 OnResourceReady) std::function ADRLoader::GetRequestCB(int64_t request_id) { + std::lock_guard lock(mutex_); auto it = request_map_.find(request_id); return it != request_map_.end() ? it->second : nullptr; } int64_t ADRLoader::SetRequestCB(const std::function& cb) { + std::lock_guard lock(mutex_); int64_t id = global_request_id.fetch_add(1); request_map_.insert({id, cb}); return id;