Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/node_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,12 @@ void NodePlatform::AddIsolateFinishedCallback(Isolate* isolate,
void NodePlatform::Shutdown() {
if (has_shut_down_) return;
has_shut_down_ = true;

// V8 background tasks may be parked waiting for foreground GC work before
// they can return from the worker thread task.
while (FlushForegroundTasksForAllIsolates()) {
}

worker_thread_task_runner_->Shutdown();

{
Expand Down Expand Up @@ -717,6 +723,25 @@ bool NodePlatform::FlushForegroundTasks(Isolate* isolate) {
return per_isolate->FlushForegroundTasksInternal();
}

bool NodePlatform::FlushForegroundTasksForAllIsolates() {
std::vector<std::shared_ptr<PerIsolatePlatformData>> per_isolates;
{
Mutex::ScopedLock lock(per_isolate_mutex_);
per_isolates.reserve(per_isolate_.size());
for (const auto& entry : per_isolate_) {
if (entry.second.second) {
per_isolates.push_back(entry.second.second);
}
}
}

bool did_work = false;
for (const auto& per_isolate : per_isolates) {
did_work |= per_isolate->FlushForegroundTasksInternal();
}
return did_work;
}

std::unique_ptr<v8::JobHandle> NodePlatform::CreateJobImpl(
v8::TaskPriority priority,
std::unique_ptr<v8::JobTask> job_task,
Expand Down
1 change: 1 addition & 0 deletions src/node_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class NodePlatform : public MultiIsolatePlatform {
private:
IsolatePlatformDelegate* ForIsolate(v8::Isolate* isolate);
std::shared_ptr<PerIsolatePlatformData> ForNodeIsolate(v8::Isolate* isolate);
bool FlushForegroundTasksForAllIsolates();

Mutex per_isolate_mutex_;
using DelegatePair = std::pair<IsolatePlatformDelegate*,
Expand Down
Loading