Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
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. More...
 
 ~TaskSource ()
 
void ShutDown ()
 Drops the pending tasks from both primary and secondary task heaps. More...
 
void RegisterTask (const DelayedTask &task)
 
void PopTask (TaskSourceGrade grade)
 Pops the task heap corresponding to the TaskSourceGrade. More...
 
size_t GetNumPendingTasks () const
 
bool IsEmpty () const
 Returns true if GetNumPendingTasks is zero. More...
 
TopTask Top () const
 
void PauseSecondary ()
 Pause providing tasks from secondary task heap. More...
 
void ResumeSecondary ()
 Resume providing tasks from secondary task heap. More...
 

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.
Definition: task_source.cc:18

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}
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13

◆ 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
Definition: task_source.cc:51

◆ 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}

◆ 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.

◆ 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}

◆ 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:103

◆ 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}

◆ 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.
Definition: task_source.cc:59
#define FML_CHECK(condition)
Definition: logging.h:85

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