Flutter Engine
The Flutter Engine
task_source.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#define FML_USED_ON_EMBEDDER
6
7#include "flutter/fml/task_source.h"
8
9namespace fml {
10
12 : task_queue_id_(task_queue_id) {}
13
15 ShutDown();
16}
17
19 primary_task_queue_ = {};
20 secondary_task_queue_ = {};
21}
22
24 switch (task.GetTaskSourceGrade()) {
26 primary_task_queue_.push(task);
27 break;
29 primary_task_queue_.push(task);
30 break;
32 secondary_task_queue_.push(task);
33 break;
34 }
35}
36
38 switch (grade) {
40 primary_task_queue_.pop();
41 break;
43 primary_task_queue_.pop();
44 break;
46 secondary_task_queue_.pop();
47 break;
48 }
49}
50
52 size_t size = primary_task_queue_.size();
53 if (secondary_pause_requests_ == 0) {
54 size += secondary_task_queue_.size();
55 }
56 return size;
57}
58
59bool TaskSource::IsEmpty() const {
60 return GetNumPendingTasks() == 0;
61}
62
65 if (secondary_pause_requests_ > 0 || secondary_task_queue_.empty()) {
66 const auto& primary_top = primary_task_queue_.top();
67 return {
68 .task_queue_id = task_queue_id_,
69 .task = primary_top,
70 };
71 } else if (primary_task_queue_.empty()) {
72 const auto& secondary_top = secondary_task_queue_.top();
73 return {
74 .task_queue_id = task_queue_id_,
75 .task = secondary_top,
76 };
77 } else {
78 const auto& primary_top = primary_task_queue_.top();
79 const auto& secondary_top = secondary_task_queue_.top();
80 if (primary_top > secondary_top) {
81 return {
82 .task_queue_id = task_queue_id_,
83 .task = secondary_top,
84 };
85 } else {
86 return {
87 .task_queue_id = task_queue_id_,
88 .task = primary_top,
89 };
90 }
91 }
92}
93
95 secondary_pause_requests_++;
96}
97
99 secondary_pause_requests_--;
100 FML_DCHECK(secondary_pause_requests_ >= 0);
101}
102
103} // namespace fml
fml::TaskSourceGrade GetTaskSourceGrade() const
Definition: delayed_task.cc:32
void ShutDown()
Drops the pending tasks from both primary and secondary task heaps.
Definition: task_source.cc:18
bool IsEmpty() const
Returns true if GetNumPendingTasks is zero.
Definition: task_source.cc:59
void RegisterTask(const DelayedTask &task)
Definition: task_source.cc:23
void ResumeSecondary()
Resume providing tasks from secondary task heap.
Definition: task_source.cc:98
TaskSource(TaskQueueId task_queue_id)
Construts a TaskSource with the given task_queue_id.
Definition: task_source.cc:11
void PauseSecondary()
Pause providing tasks from secondary task heap.
Definition: task_source.cc:94
void PopTask(TaskSourceGrade grade)
Pops the task heap corresponding to the TaskSourceGrade.
Definition: task_source.cc:37
size_t GetNumPendingTasks() const
Definition: task_source.cc:51
TopTask Top() const
Definition: task_source.cc:63
#define FML_CHECK(condition)
Definition: logging.h:85
#define FML_DCHECK(condition)
Definition: logging.h:103
Definition: ascii_trie.cc:9
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
@ kUnspecified
The absence of a specialized TaskSourceGrade.