Skip to content

Commit

Permalink
fix(core): fix mutex crash
Browse files Browse the repository at this point in the history
(cherry picked from commit 62fc9cf)
  • Loading branch information
churchill-zhang authored and zoomchan-cxj committed May 16, 2022
1 parent 486246b commit de3dad1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion core/include/core/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Engine {

void TerminateRunner();
inline std::shared_ptr<JavaScriptTaskRunner> GetJSRunner() {
std::lock_guard<std::mutex> lock(js_runner_mutex_);
return js_runner_;
}
inline std::shared_ptr<WorkerTaskRunner> GetWorkerTaskRunner() {
Expand All @@ -73,6 +74,6 @@ class Engine {
std::shared_ptr<VM> vm_;
std::unique_ptr<RegisterMap> map_;
std::mutex cnt_mutex_;
std::mutex runner_mutex_;
std::mutex js_runner_mutex_;
uint32_t scope_cnt_;
};
11 changes: 7 additions & 4 deletions core/src/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ Engine::~Engine() {

void Engine::TerminateRunner() {
TDF_BASE_DLOG(INFO) << "~TerminateRunner";
std::lock_guard<std::mutex> lock(runner_mutex_);
if (js_runner_) {
js_runner_->Terminate();
js_runner_ = nullptr;
{
std::lock_guard<std::mutex> lock(js_runner_mutex_);
if (js_runner_) {
js_runner_->Terminate();
js_runner_ = nullptr;
}
}

if (worker_task_runner_) {
worker_task_runner_->Terminate();
worker_task_runner_ = nullptr;
Expand Down
5 changes: 4 additions & 1 deletion core/src/modules/contextify_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ void ContextifyModule::LoadUntrustedContent(const CallbackInfo& info) {
RemoveCBFunc(uri);
}
};
scope->GetTaskRunner()->PostTask(js_task);
auto runner = scope->GetTaskRunner();
if (runner) {
runner->PostTask(js_task);
}
};
loader->RequestUntrustedContent(uri, cb);
info.GetReturnValue()->SetUndefined();
Expand Down

0 comments on commit de3dad1

Please sign in to comment.