Flutter Engine
 
Loading...
Searching...
No Matches
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)
 
intptr_t unique_id () const
 
- 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
 

Additional Inherited Members

- Static Public Member Functions inherited from fml::TaskRunner
static void RunNowOrPostTask (const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
 
static void RunNowAndFlushMessages (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 14 of file embedder_task_runner.cc.

16 : TaskRunner(nullptr /* loop implemenation*/),
17 embedder_identifier_(embedder_identifier),
18 dispatch_table_(std::move(table)),
20 unique_id_(next_unique_id_++) {
21 FML_DCHECK(dispatch_table_.post_task_callback);
23 FML_DCHECK(dispatch_table_.destruction_callback);
24}
static const size_t kInvalid
TaskRunner(fml::RefPtr< MessageLoopImpl > loop)
#define FML_DCHECK(condition)
Definition logging.h:122
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
std::function< void()> destruction_callback
Performs user-designated cleanup on destruction.

References flutter::EmbedderTaskRunner::DispatchTable::destruction_callback, FML_DCHECK, flutter::EmbedderTaskRunner::DispatchTable::post_task_callback, and flutter::EmbedderTaskRunner::DispatchTable::runs_task_on_current_thread_callback.

◆ ~EmbedderTaskRunner()

flutter::EmbedderTaskRunner::~EmbedderTaskRunner ( )
override

Definition at line 26 of file embedder_task_runner.cc.

26 {
27 dispatch_table_.destruction_callback();
28}

References flutter::EmbedderTaskRunner::DispatchTable::destruction_callback.

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 30 of file embedder_task_runner.cc.

30 {
31 return embedder_identifier_;
32}

◆ PostTask()

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

Definition at line 65 of file embedder_task_runner.cc.

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

References FML_DCHECK, and FML_LOG.

◆ unique_id()

intptr_t flutter::EmbedderTaskRunner::unique_id ( ) const
inline

Definition at line 78 of file embedder_task_runner.h.

78{ return unique_id_; }

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