Flutter Engine
 
Loading...
Searching...
No Matches
fml::TaskSource Class Reference

#include <task_source.h>

Classes

struct  TopTask
 

Public Member Functions

 TaskSource (TaskQueueId task_queue_id)
 Construts a TaskSource with the given task_queue_id.
 
 ~TaskSource ()
 
void ShutDown ()
 Drops the pending tasks from both primary and secondary task heaps.
 
void RegisterTask (const DelayedTask &task)
 
void PopTask (TaskSourceGrade grade)
 Pops the task heap corresponding to the TaskSourceGrade.
 
size_t GetNumPendingTasks () const
 
bool IsEmpty () const
 Returns true if GetNumPendingTasks is zero.
 
TopTask Top () const
 
void PauseSecondary ()
 Pause providing tasks from secondary task heap.
 
void ResumeSecondary ()
 Resume providing tasks from secondary task heap.
 

Detailed Description

A Source of tasks for the MessageLoopTaskQueues task dispatcher. This is a wrapper around a primary and secondary task heap with the difference between them being that the secondary task heap can be paused and resumed by the task dispatcher. TaskSourceGrade determines what task heap the task is assigned to.

Registering Tasks

The task dispatcher associates a task source with each TaskQueueID. When the user of the task dispatcher registers a task, the task is in-turn registered with the TaskSource corresponding to the TaskQueueID.

Processing Tasks

Task dispatcher provides the event loop a way to acquire tasks to run via GetNextTaskToRun. Task dispatcher asks the underlying TaskSource for the next task.

Definition at line 35 of file task_source.h.

Constructor & Destructor Documentation

◆ TaskSource()

fml::TaskSource::TaskSource ( TaskQueueId  task_queue_id)
explicit

Construts a TaskSource with the given task_queue_id.

Definition at line 11 of file task_source.cc.

12 : task_queue_id_(task_queue_id) {}

◆ ~TaskSource()

fml::TaskSource::~TaskSource ( )

Definition at line 14 of file task_source.cc.

14 {
15 ShutDown();
16}
void ShutDown()
Drops the pending tasks from both primary and secondary task heaps.

References ShutDown().

Member Function Documentation

◆ GetNumPendingTasks()

size_t fml::TaskSource::GetNumPendingTasks ( ) const

Returns the number of pending tasks. Excludes the tasks from the secondary heap if it's paused.

Definition at line 51 of file task_source.cc.

51 {
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}
it will be possible to load the file into Perfetto s trace viewer use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size

Referenced by IsEmpty(), fml::testing::TEST(), and fml::testing::TEST().

◆ IsEmpty()

bool fml::TaskSource::IsEmpty ( ) const

Returns true if GetNumPendingTasks is zero.

Definition at line 59 of file task_source.cc.

59 {
60 return GetNumPendingTasks() == 0;
61}
size_t GetNumPendingTasks() const

References GetNumPendingTasks().

Referenced by fml::testing::TEST(), and Top().

◆ PauseSecondary()

void fml::TaskSource::PauseSecondary ( )

Pause providing tasks from secondary task heap.

Definition at line 94 of file task_source.cc.

94 {
95 secondary_pause_requests_++;
96}

Referenced by fml::testing::TEST().

◆ PopTask()

void fml::TaskSource::PopTask ( TaskSourceGrade  grade)

Pops the task heap corresponding to the TaskSourceGrade.

Definition at line 37 of file task_source.cc.

37 {
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}
@ kUnspecified
The absence of a specialized TaskSourceGrade.

References fml::kDartEventLoop, fml::kUnspecified, and fml::kUserInteraction.

Referenced by fml::testing::TEST(), fml::testing::TEST(), and fml::testing::TEST().

◆ RegisterTask()

void fml::TaskSource::RegisterTask ( const DelayedTask task)

Adds a task to the corresponding task heap as dictated by the TaskSourceGrade of the DelayedTask.

Definition at line 23 of file task_source.cc.

23 {
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}

References fml::DelayedTask::GetTaskSourceGrade(), fml::kDartEventLoop, fml::kUnspecified, and fml::kUserInteraction.

Referenced by fml::testing::TEST(), fml::testing::TEST(), fml::testing::TEST(), fml::testing::TEST(), and fml::testing::TEST().

◆ ResumeSecondary()

void fml::TaskSource::ResumeSecondary ( )

Resume providing tasks from secondary task heap.

Definition at line 98 of file task_source.cc.

98 {
99 secondary_pause_requests_--;
100 FML_DCHECK(secondary_pause_requests_ >= 0);
101}
#define FML_DCHECK(condition)
Definition logging.h:122

References FML_DCHECK.

Referenced by fml::testing::TEST().

◆ ShutDown()

void fml::TaskSource::ShutDown ( )

Drops the pending tasks from both primary and secondary task heaps.

Definition at line 18 of file task_source.cc.

18 {
19 primary_task_queue_ = {};
20 secondary_task_queue_ = {};
21}

Referenced by ~TaskSource().

◆ Top()

TaskSource::TopTask fml::TaskSource::Top ( ) const

Returns the top task based on scheduled time, taking into account whether the secondary heap has been paused or not.

Definition at line 63 of file task_source.cc.

63 {
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}
bool IsEmpty() const
Returns true if GetNumPendingTasks is zero.
#define FML_CHECK(condition)
Definition logging.h:104

References FML_CHECK, and IsEmpty().

Referenced by fml::testing::TEST(), fml::testing::TEST(), and fml::testing::TEST().


The documentation for this class was generated from the following files: