Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Member Functions | List of all members
flutter::EmbedderTaskRunner Class Referencefinal

#include <embedder_task_runner.h>

Inheritance diagram for flutter::EmbedderTaskRunner:
fml::TaskRunner fml::RefCountedThreadSafe< TaskRunner > fml::BasicTaskRunner fml::internal::RefCountedThreadSafeBase

Classes

struct  DispatchTable
 A. More...
 

Public Member Functions

 EmbedderTaskRunner (DispatchTable table, size_t embedder_identifier)
 Create a task runner with a dispatch table for delegation of task runner responsibility to the embedder. When embedders specify task runner dispatch tables that service tasks on the same thread, they also must ensure that their embedder_idetifiers match. This allows the engine to determine task runner equality without actually posting tasks to the task runner.
 
 ~EmbedderTaskRunner () override
 
size_t GetEmbedderIdentifier () const
 The unique identifier provided by the embedder for the task runner. Embedders whose dispatch tables service tasks on the same underlying OS thread must ensure that their identifiers match. This allows the engine to determine task runner equality without posting tasks on the thread.
 
bool PostTask (uint64_t baton)
 
- Public Member Functions inherited from fml::TaskRunner
virtual ~TaskRunner ()
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< TaskRunner >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 

Private Member Functions

void PostTask (const fml::closure &task) override
 
void PostTaskForTime (const fml::closure &task, fml::TimePoint target_time) override
 
void PostDelayedTask (const fml::closure &task, fml::TimeDelta delay) override
 
bool RunsTasksOnCurrentThread () override
 
fml::TaskQueueId GetTaskQueueId () override
 

Additional Inherited Members

- Static Public Member Functions inherited from fml::TaskRunner
static void RunNowOrPostTask (const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
 
- Protected Member Functions inherited from fml::TaskRunner
 TaskRunner (fml::RefPtr< MessageLoopImpl > loop)
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< TaskRunner >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 

Detailed Description

A task runner which delegates responsibility of task execution to an embedder. This is done by managing a dispatch table to the embedder.

Definition at line 20 of file embedder_task_runner.h.

Constructor & Destructor Documentation

◆ EmbedderTaskRunner()

flutter::EmbedderTaskRunner::EmbedderTaskRunner ( DispatchTable  table,
size_t  embedder_identifier 
)

Create a task runner with a dispatch table for delegation of task runner responsibility to the embedder. When embedders specify task runner dispatch tables that service tasks on the same thread, they also must ensure that their embedder_idetifiers match. This allows the engine to determine task runner equality without actually posting tasks to the task runner.

Parameters
[in]tableThe task runner dispatch table.
[in]embedder_identifierThe embedder identifier

Definition at line 12 of file embedder_task_runner.cc.

14 : TaskRunner(nullptr /* loop implemenation*/),
15 embedder_identifier_(embedder_identifier),
16 dispatch_table_(std::move(table)),
17 placeholder_id_(
18 fml::MessageLoopTaskQueues::GetInstance()->CreateTaskQueue()) {
19 FML_DCHECK(dispatch_table_.post_task_callback);
21}
SI F table(const skcms_Curve *curve, F v)
static MessageLoopTaskQueues * GetInstance()
TaskRunner(fml::RefPtr< MessageLoopImpl > loop)
#define FML_DCHECK(condition)
Definition logging.h:103
std::function< void(EmbedderTaskRunner *task_runner, uint64_t task_baton, fml::TimePoint target_time)> post_task_callback
std::function< bool(void)> runs_task_on_current_thread_callback

◆ ~EmbedderTaskRunner()

flutter::EmbedderTaskRunner::~EmbedderTaskRunner ( )
overridedefault

Member Function Documentation

◆ GetEmbedderIdentifier()

size_t flutter::EmbedderTaskRunner::GetEmbedderIdentifier ( ) const

The unique identifier provided by the embedder for the task runner. Embedders whose dispatch tables service tasks on the same underlying OS thread must ensure that their identifiers match. This allows the engine to determine task runner equality without posting tasks on the thread.

Returns
The embedder identifier.

Definition at line 25 of file embedder_task_runner.cc.

25 {
26 return embedder_identifier_;
27}

◆ GetTaskQueueId()

fml::TaskQueueId flutter::EmbedderTaskRunner::GetTaskQueueId ( )
overrideprivatevirtual

Returns the unique identifier associated with the TaskRunner.

See also
fml::MessageLoopTaskQueues

Reimplemented from fml::TaskRunner.

Definition at line 82 of file embedder_task_runner.cc.

82 {
83 return placeholder_id_;
84}

◆ PostDelayedTask()

void flutter::EmbedderTaskRunner::PostDelayedTask ( const fml::closure task,
fml::TimeDelta  delay 
)
overrideprivatevirtual

Schedules a task to be run on the MessageLoop after the time delay has passed.

Note
There is latency between when the task is schedule and actually executed so that the actual execution time is: now + delay + message_loop_latency, where message_loop_latency is undefined and could be tens of milliseconds.

Reimplemented from fml::TaskRunner.

Definition at line 51 of file embedder_task_runner.cc.

52 {
53 PostTaskForTime(task, fml::TimePoint::Now() + delay);
54}
void PostTaskForTime(const fml::closure &task, fml::TimePoint target_time) override
static TimePoint Now()
Definition time_point.cc:49

◆ PostTask() [1/2]

void flutter::EmbedderTaskRunner::PostTask ( const fml::closure task)
overrideprivatevirtual

Schedules task to be executed on the TaskRunner's associated event loop.

Reimplemented from fml::TaskRunner.

Definition at line 29 of file embedder_task_runner.cc.

29 {
31}

◆ PostTask() [2/2]

bool flutter::EmbedderTaskRunner::PostTask ( uint64_t  baton)

Definition at line 60 of file embedder_task_runner.cc.

60 {
61 fml::closure task;
62
63 {
64 std::scoped_lock lock(tasks_mutex_);
65 auto found = pending_tasks_.find(baton);
66 if (found == pending_tasks_.end()) {
67 FML_LOG(ERROR) << "Embedder attempted to post an unknown task.";
68 return false;
69 }
70 task = found->second;
71 pending_tasks_.erase(found);
72
73 // Let go of the tasks mutex befor executing the task.
74 }
75
76 FML_DCHECK(task);
77 task();
78 return true;
79}
#define FML_LOG(severity)
Definition logging.h:82
std::function< void()> closure
Definition closure.h:14
#define ERROR(message)

◆ PostTaskForTime()

void flutter::EmbedderTaskRunner::PostTaskForTime ( const fml::closure task,
fml::TimePoint  target_time 
)
overrideprivatevirtual

Reimplemented from fml::TaskRunner.

Definition at line 33 of file embedder_task_runner.cc.

34 {
35 if (!task) {
36 return;
37 }
38
39 uint64_t baton = 0;
40
41 {
42 // Release the lock before the jump via the dispatch table.
43 std::scoped_lock lock(tasks_mutex_);
44 baton = ++last_baton_;
45 pending_tasks_[baton] = task;
46 }
47
48 dispatch_table_.post_task_callback(this, baton, target_time);
49}

◆ RunsTasksOnCurrentThread()

bool flutter::EmbedderTaskRunner::RunsTasksOnCurrentThread ( )
overrideprivatevirtual

Returns true when the current executing thread's TaskRunner matches this instance.

Reimplemented from fml::TaskRunner.

Definition at line 56 of file embedder_task_runner.cc.

56 {
57 return dispatch_table_.runs_task_on_current_thread_callback();
58}

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