镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
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
14 changes: 9 additions & 5 deletions src/node_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ class WorkerThreadsTaskRunner::DelayedTaskScheduler {

// ScheduleTasks (start a timer that pops the task into the worker queue)
// in posting order, then, once Stop() was called, the StopTask.
for (std::unique_ptr<Task>& task : scheduler->tasks_.Lock().PopAll()) {
std::vector<std::unique_ptr<Task>> tasks =
scheduler->tasks_.Lock().PopAll();
for (std::unique_ptr<Task>& task : tasks) {
task->Run();
}
}
Expand Down Expand Up @@ -605,8 +607,9 @@ void NodePlatform::DrainTasks(Isolate* isolate) {
bool PerIsolatePlatformData::FlushForegroundTasksInternal() {
bool did_work = false;

for (std::unique_ptr<DelayedTask>& delayed :
foreground_delayed_tasks_.Lock().PopAll()) {
std::vector<std::unique_ptr<DelayedTask>> delayed_tasks =
foreground_delayed_tasks_.Lock().PopAll();
for (std::unique_ptr<DelayedTask>& delayed : delayed_tasks) {
did_work = true;
uint64_t delay_millis = llround(delayed->timeout * 1000);

Expand All @@ -629,8 +632,9 @@ bool PerIsolatePlatformData::FlushForegroundTasksInternal() {
});
}

for (std::unique_ptr<TaskQueueEntry>& entry :
foreground_tasks_.Lock().PopAll()) {
std::vector<std::unique_ptr<TaskQueueEntry>> tasks =
foreground_tasks_.Lock().PopAll();
for (std::unique_ptr<TaskQueueEntry>& entry : tasks) {
did_work = true;
RunForegroundTask(std::move(entry->task));
}
Expand Down
4 changes: 3 additions & 1 deletion src/node_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class TaskQueue {
void NotifyOfOutstandingCompletion();
void BlockingDrain();
void Stop();
// All queued tasks, in the order Pop() would have returned them.
// All queued tasks, in the order Pop() would have returned them. Store the
// result before iterating it: used directly as a range-for initializer,
// `Lock().PopAll()` keeps the lock held for the whole loop from C++23 on.
std::vector<std::unique_ptr<T>> PopAll();

private:
Expand Down
Loading