Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
fml::TaskRunner Class Reference

#include <task_runner.h>

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

Public Member Functions

virtual ~TaskRunner ()
 
virtual void PostTask (const fml::closure &task) override
 
virtual void PostTaskForTime (const fml::closure &task, fml::TimePoint target_time)
 
virtual void PostDelayedTask (const fml::closure &task, fml::TimeDelta delay)
 
virtual bool RunsTasksOnCurrentThread ()
 
virtual TaskQueueId GetTaskQueueId ()
 
- 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
 

Static Public Member Functions

static void RunNowOrPostTask (const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
 

Protected Member Functions

 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

The object for scheduling tasks on a fml::MessageLoop.

Typically there is one TaskRunner associated with each thread. When one wants to execute an operation on that thread they post a task to the TaskRunner.

See also
fml::MessageLoop

Definition at line 34 of file task_runner.h.

Constructor & Destructor Documentation

◆ ~TaskRunner()

fml::TaskRunner::~TaskRunner ( )
virtualdefault

◆ TaskRunner()

fml::TaskRunner::TaskRunner ( fml::RefPtr< MessageLoopImpl loop)
explicitprotected

Definition at line 19 of file task_runner.cc.

20 : loop_(std::move(loop)) {}

Member Function Documentation

◆ GetTaskQueueId()

TaskQueueId fml::TaskRunner::GetTaskQueueId ( )
virtual

Returns the unique identifier associated with the TaskRunner.

See also
fml::MessageLoopTaskQueues

Reimplemented in flutter::EmbedderTaskRunner.

Definition at line 38 of file task_runner.cc.

38 {
39 FML_DCHECK(loop_);
40 return loop_->GetTaskQueueId();
41}
#define FML_DCHECK(condition)
Definition logging.h:103

◆ PostDelayedTask()

void fml::TaskRunner::PostDelayedTask ( const fml::closure task,
fml::TimeDelta  delay 
)
virtual

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 in flutter::EmbedderTaskRunner, and flutter_runner::CompatTaskRunner.

Definition at line 33 of file task_runner.cc.

34 {
35 loop_->PostTask(task, fml::TimePoint::Now() + delay);
36}
static TimePoint Now()
Definition time_point.cc:49

◆ PostTask()

void fml::TaskRunner::PostTask ( const fml::closure task)
overridevirtual

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

Implements fml::BasicTaskRunner.

Reimplemented in flutter::EmbedderTaskRunner, and flutter_runner::CompatTaskRunner.

Definition at line 24 of file task_runner.cc.

24 {
25 loop_->PostTask(task, fml::TimePoint::Now());
26}

◆ PostTaskForTime()

void fml::TaskRunner::PostTaskForTime ( const fml::closure task,
fml::TimePoint  target_time 
)
virtual

Reimplemented in flutter::EmbedderTaskRunner, and flutter_runner::CompatTaskRunner.

Definition at line 28 of file task_runner.cc.

29 {
30 loop_->PostTask(task, target_time);
31}

◆ RunNowOrPostTask()

void fml::TaskRunner::RunNowOrPostTask ( const fml::RefPtr< fml::TaskRunner > &  runner,
const fml::closure task 
)
static

Executes the task directly if the TaskRunner runner is the TaskRunner associated with the current executing thread.

Definition at line 55 of file task_runner.cc.

56 {
57 FML_DCHECK(runner);
58 if (runner->RunsTasksOnCurrentThread()) {
59 task();
60 } else {
61 runner->PostTask(task);
62 }
63}
virtual void PostTask(const fml::closure &task) override
virtual bool RunsTasksOnCurrentThread()

◆ RunsTasksOnCurrentThread()

bool fml::TaskRunner::RunsTasksOnCurrentThread ( )
virtual

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

Reimplemented in flutter::EmbedderTaskRunner, and flutter_runner::CompatTaskRunner.

Definition at line 43 of file task_runner.cc.

43 {
45 return false;
46 }
47
48 const auto current_queue_id = MessageLoop::GetCurrentTaskQueueId();
49 const auto loop_queue_id = loop_->GetTaskQueueId();
50
51 return TaskRunnerChecker::RunsOnTheSameThread(current_queue_id,
52 loop_queue_id);
53}
static bool IsInitializedForCurrentThread()
static TaskQueueId GetCurrentTaskQueueId()
static bool RunsOnTheSameThread(TaskQueueId queue_a, TaskQueueId queue_b)

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