Skip to content

Commit

Permalink
fix(core): fix ADRLoader multithread bug
Browse files Browse the repository at this point in the history
  • Loading branch information
etkmao committed Feb 19, 2024
1 parent 57cea30 commit b74ec68
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions android/sdk/src/main/jni/include/loader/adr_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,5 @@ class ADRLoader : public hippy::base::UriLoader {
std::shared_ptr<JavaRef> bridge_;
std::weak_ptr<WorkerTaskRunner> runner_;
std::unordered_map<int64_t, std::function<void(u8string)>> request_map_;
std::mutex mutex_;
};
2 changes: 2 additions & 0 deletions android/sdk/src/main/jni/src/loader/adr_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,13 @@ REGISTER_JNI("com/tencent/mtt/hippy/bridge/HippyBridgeImpl", // NOLINT(cert-err5
OnResourceReady)

std::function<void(u8string)> ADRLoader::GetRequestCB(int64_t request_id) {
std::lock_guard<std::mutex> lock(mutex_);
auto it = request_map_.find(request_id);
return it != request_map_.end() ? it->second : nullptr;
}

int64_t ADRLoader::SetRequestCB(const std::function<void(u8string)>& cb) {
std::lock_guard<std::mutex> lock(mutex_);
int64_t id = global_request_id.fetch_add(1);
request_map_.insert({id, cb});
return id;
Expand Down

0 comments on commit b74ec68

Please sign in to comment.