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
9 changes: 5 additions & 4 deletions engine/src/flutter/shell/platform/windows/task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ std::chrono::nanoseconds TaskRunner::ProcessTasks() {
// Calculate duration to sleep for on next iteration.
{
std::lock_guard<std::mutex> lock(task_queue_mutex_);
const auto next_wake = task_queue_.empty() ? TaskTimePoint::max()
: task_queue_.top().fire_time;

return std::min(next_wake - now, std::chrono::nanoseconds::max());
if (task_queue_.empty()) {
return std::chrono::nanoseconds::max();
} else {
return task_queue_.top().fire_time - now;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ class TestTaskRunnerWindow : public TaskRunnerWindow {
TestTaskRunnerWindow() : TaskRunnerWindow() {}
};

TEST(TaskRunnerTest, EmptyTaskRunnerReturnsNanoSecondsMax) {
TaskRunner runner(MockGetCurrentTime, [](const FlutterTask*) {});
auto res = runner.ProcessTasks();
EXPECT_EQ(res, std::chrono::nanoseconds::max());
}

TEST(TaskRunnerTest, TaskRunnerWindowCoalescesWakeUpMessages) {
class Delegate : public TaskRunnerWindow::Delegate {
public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,11 @@ void TaskRunnerWindow::ProcessTasks() {
}

void TaskRunnerWindow::SetTimer(std::chrono::nanoseconds when) {
if (when == std::chrono::nanoseconds::max()) {
timer_thread_.ScheduleAt(
std::chrono::time_point<std::chrono::high_resolution_clock>::max());
} else {
timer_thread_.ScheduleAt(std::chrono::high_resolution_clock::now() + when);
}
auto now = std::chrono::high_resolution_clock::now();
auto remaining_to_max =
std::chrono::nanoseconds::max() - now.time_since_epoch();
when = std::min(when, remaining_to_max);
timer_thread_.ScheduleAt(now + when);
}

WNDCLASS TaskRunnerWindow::RegisterWindowClass() {
Expand Down