Skip to content

Commit

Permalink
fix(core): avoid crash caused by lock in the destructor
Browse files Browse the repository at this point in the history
  • Loading branch information
churchill-zhang authored and zoomchan-cxj committed Mar 16, 2023
1 parent 6daf1f3 commit 87f8cd2
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 21 deletions.
4 changes: 0 additions & 4 deletions core/include/core/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class Engine: public std::enable_shared_from_this<Engine> {

void AsyncInit(const std::shared_ptr<VMInitParam>& param = nullptr,
std::unique_ptr<RegisterMap> map = std::make_unique<RegisterMap>());
void Enter();
void Exit();
std::shared_ptr<Scope> CreateScope(
const std::string& name = "",
std::unique_ptr<RegisterMap> map = std::unique_ptr<RegisterMap>());
Expand Down Expand Up @@ -84,8 +82,6 @@ class Engine: public std::enable_shared_from_this<Engine> {
std::shared_ptr<WorkerTaskRunner> worker_task_runner_;
std::shared_ptr<VM> vm_;
std::unique_ptr<RegisterMap> map_;
std::mutex cnt_mutex_;
uint32_t scope_cnt_;
#if defined(JS_V8) && !defined(V8_WITHOUT_INSPECTOR)
std::shared_ptr<hippy::inspector::V8InspectorClientImpl> inspector_client_;
#endif
Expand Down
16 changes: 1 addition & 15 deletions core/src/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@

constexpr uint32_t Engine::kDefaultWorkerPoolSize = 1;

Engine::Engine() : vm_(nullptr), scope_cnt_(0) {}
Engine::Engine() : vm_(nullptr) {}

Engine::~Engine() {
TDF_BASE_DLOG(INFO) << "~Engine";
std::lock_guard<std::mutex> lock(cnt_mutex_);
TDF_BASE_DCHECK(scope_cnt_ == 0) << "this engine is in use";
}

void Engine::TerminateRunner() {
Expand Down Expand Up @@ -99,15 +97,3 @@ void Engine::AsyncInit(const std::shared_ptr<VMInitParam>& param, std::unique_pt
};
js_runner_->PostTask(task);
}

void Engine::Enter() {
TDF_BASE_DLOG(INFO) << "Engine Enter";
std::lock_guard<std::mutex> lock(cnt_mutex_);
++scope_cnt_;
}

void Engine::Exit() {
TDF_BASE_DLOG(INFO) << "Engine Exit";
std::lock_guard<std::mutex> lock(cnt_mutex_);
--scope_cnt_;
}
2 changes: 0 additions & 2 deletions core/src/scope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Scope::Scope(Engine* engine,

Scope::~Scope() {
TDF_BASE_DLOG(INFO) << "~Scope";
engine_->Exit();
}

void Scope::WillExit() {
Expand Down Expand Up @@ -91,7 +90,6 @@ void Scope::WillExit() {

void Scope::Initialized() {
TDF_BASE_DLOG(INFO) << "Scope Initialized";
engine_->Enter();
context_ = engine_->GetVM()->CreateContext();
if (context_ == nullptr) {
TDF_BASE_DLOG(ERROR) << "CreateContext return nullptr";
Expand Down

0 comments on commit 87f8cd2

Please sign in to comment.