Skip to content

Commit

Permalink
Ensure loop is woken up at the right time (flutter#20721)
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel Garcia authored Aug 24, 2020
1 parent f8d2d7b commit 8107b36
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
3 changes: 1 addition & 2 deletions fml/message_loop_task_queues.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ void MessageLoopTaskQueues::RegisterTask(TaskQueueId queue_id,
if (queue_entry->subsumed_by != _kUnmerged) {
loop_to_wake = queue_entry->subsumed_by;
}
WakeUpUnlocked(loop_to_wake,
queue_entry->delayed_tasks.top().GetTargetTime());
WakeUpUnlocked(loop_to_wake, GetNextWakeTimeUnlocked(loop_to_wake));
}

bool MessageLoopTaskQueues::HasPendingTasks(TaskQueueId queue_id) const {
Expand Down
39 changes: 39 additions & 0 deletions fml/message_loop_task_queues_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,42 @@ TEST(MessageLoopTaskQueue, DISABLED_ConcurrentQueueAndTaskCreatingCounts) {
creation_1.join();
creation_2.join();
}

TEST(MessageLoopTaskQueue, RegisterTaskWakesUpOwnerQueue) {
auto task_queue = fml::MessageLoopTaskQueues::GetInstance();
auto platform_queue = task_queue->CreateTaskQueue();
auto raster_queue = task_queue->CreateTaskQueue();

std::vector<fml::TimePoint> wakes;

task_queue->SetWakeable(platform_queue,
new TestWakeable([&wakes](fml::TimePoint wake_time) {
wakes.push_back(wake_time);
}));

task_queue->SetWakeable(raster_queue,
new TestWakeable([](fml::TimePoint wake_time) {
// The raster queue is owned by the platform queue.
ASSERT_FALSE(true);
}));

auto time1 = fml::TimePoint::Now() + fml::TimeDelta::FromMilliseconds(1);
auto time2 = fml::TimePoint::Now() + fml::TimeDelta::FromMilliseconds(2);

ASSERT_EQ(0UL, wakes.size());

task_queue->RegisterTask(
platform_queue, []() {}, time1);

ASSERT_EQ(1UL, wakes.size());
ASSERT_EQ(time1, wakes[0]);

task_queue->Merge(platform_queue, raster_queue);

task_queue->RegisterTask(
raster_queue, []() {}, time2);

ASSERT_EQ(3UL, wakes.size());
ASSERT_EQ(time1, wakes[1]);
ASSERT_EQ(time1, wakes[2]);
}

0 comments on commit 8107b36

Please sign in to comment.