Flutter Engine
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 (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

Referenced by TaskRunner().

◆ TaskRunner()

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

Definition at line 19 of file task_runner.cc.

References ~TaskRunner().

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

Definition at line 38 of file task_runner.cc.

References FML_DCHECK.

Referenced by flutter::VsyncWaiter::FireCallback(), fml::testing::TaskQueueWrapper::GetTaskQueueId(), flutter::testing::GetThreadMergerFromRasterThread(), flutter::DartIsolate::LoadLoadingUnitError(), flutter::Rasterizer::Setup(), and fml::testing::TEST().

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

◆ 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_runner::CompatTaskRunner.

Definition at line 33 of file task_runner.cc.

References fml::TimePoint::Now().

Referenced by flutter::FxlToDartOrEarlier(), flutter::Shell::GetDartVM(), flutter::testing::PendingTests::OnTestBegin(), flutter::SamplingProfiler::Stop(), and flutter::testing::TEST_F().

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

◆ 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_runner::CompatTaskRunner.

Definition at line 24 of file task_runner.cc.

References fml::TimePoint::Now().

Referenced by flutter::AndroidShellHolder::AndroidShellHolder(), flutter::PlatformMessageResponseDart::Complete(), flutter::PlatformMessageResponseDarwin::Complete(), flutter::PlatformMessageResponseDart::CompleteEmpty(), flutter::PlatformMessageResponseDarwin::CompleteEmpty(), flutter::PlatformConfiguration::CompleteKeyDataResponse(), flutter::CopyToBitmap(), flutter::testing::ShellTest::DispatchPointerData(), flutter::Rasterizer::Draw(), flutter::EmbedderPlatformMessageResponse::EmbedderPlatformMessageResponse(), flutter::EncodeImage(), flutter::VsyncWaiter::FireCallback(), flutter::Shell::GetDartVM(), flutter::MultiFrameCodec::getNextFrame(), flutter::FlutterMain::GetSettings(), flutter::testing::GetTestNameFromTestInfo(), fml::Thread::Join(), flutter::DartIsolate::LoadLoadingUnitError(), flutter::testing::ShellTest::NotifyIdle(), flutter::Shell::NotifyLowMemoryWarning(), flutter::PersistentCacheStore(), flutter::testing::PostTaskSync(), flutter::PrepareKernelMappings(), flutter::testing::ShellTest::PumpOneFrame(), flutter::PersistentCache::Purge(), flutter::Animator::RequestFrame(), RunNowOrPostTask(), flutter::testing::ShellTest::SetViewportMetrics(), flutter::SamplingProfiler::Stop(), TEST(), fml::testing::TEST(), flutter::testing::TEST_F(), flutter::testing::TestSimulatedInputEvents(), flutter::testing::ShellTest::VSyncFlush(), flutter::VsyncWaiterAndroid::VsyncWaiterAndroid(), flutter::testing::WaitForIO(), flutter::testing::WaitForRaster(), flutter::PlatformMessageResponseDart::~PlatformMessageResponseDart(), and flutter::testing::TestTimeoutListener::~TestTimeoutListener().

24  {
25  loop_->PostTask(task, fml::TimePoint::Now());
26 }
static TimePoint Now()
Definition: time_point.cc:39

◆ PostTaskForTime()

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

◆ RunNowOrPostTask()

void fml::TaskRunner::RunNowOrPostTask ( 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.

References FML_DCHECK, PostTask(), and RunsTasksOnCurrentThread().

Referenced by flutter::Shell::Create(), flutter::testing::ShellTest::DestroyShell(), flutter::ScriptCompletionTaskObserver::DidProcessTask(), flutter::Animator::EnqueueTraceFlowId(), flutter::Shell::GetDartVM(), flutter_runner::Engine::GetEngineReturnCode(), flutter::testing::GetRasterizerResourceCacheBytesSync(), flutter::HandleMessageOnHandler(), flutter::testing::ShellTest::IsAnimatorRunning(), flutter::Shell::IsSetup(), flutter::AndroidImageGenerator::MakeFromData(), flutter::PlatformViewAndroid::NotifyChanged(), flutter::PlatformViewAndroid::NotifyCreated(), flutter::PlatformView::NotifyCreated(), flutter::PlatformViewAndroid::NotifyDestroyed(), flutter::PlatformViewAndroid::NotifySurfaceWindowChanged(), flutter::testing::ShellTest::OnServiceProtocol(), flutter::testing::ShellTest::PlatformViewNotifyCreated(), flutter::testing::ShellTest::PlatformViewNotifyDestroyed(), flutter::testing::PostSync(), flutter::testing::RasterizerHasLayerTree(), flutter::Picture::RasterizeToImage(), flutter::Shell::RegisterImageDecoder(), flutter::testing::ShellTest::RestartEngine(), flutter::testing::RunDartCodeInIsolate(), flutter::testing::ShellTest::RunEngine(), flutter::Shell::RunEngine(), flutter::testing::AutoIsolateShutdown::RunInIsolateScope(), flutter::RunTester(), flutter::Shell::Screenshot(), flutter::testing::ShellTest::SendEnginePlatformMessage(), flutter::Shell::SetGpuAvailability(), flutter::testing::AutoIsolateShutdown::Shutdown(), flutter::StartupAndShutdownShell(), flutter::testing::TEST_F(), flutter::testing::ValidateShell(), flutter::testing::ShellTest::VSyncFlush(), flutter_runner::VsyncWaiter::VsyncWaiter(), flutter::testing::AutoIsolateShutdown::~AutoIsolateShutdown(), flutter_runner::Runner::~Runner(), flutter::Shell::~Shell(), flutter::testing::TestIOManager::~TestIOManager(), and flutter_runner::VsyncWaiter::~VsyncWaiter().

56  {
57  FML_DCHECK(runner);
58  if (runner->RunsTasksOnCurrentThread()) {
59  task();
60  } else {
61  runner->PostTask(std::move(task));
62  }
63 }
#define FML_DCHECK(condition)
Definition: logging.h:86
virtual bool RunsTasksOnCurrentThread()
Definition: task_runner.cc:43
virtual void PostTask(const fml::closure &task) override
Definition: task_runner.cc:24

◆ RunsTasksOnCurrentThread()

bool fml::TaskRunner::RunsTasksOnCurrentThread ( )
virtual

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

Reimplemented in flutter_runner::CompatTaskRunner.

Definition at line 43 of file task_runner.cc.

References fml::MessageLoop::GetCurrentTaskQueueId(), fml::MessageLoop::IsInitializedForCurrentThread(), and fml::TaskRunnerChecker::RunsOnTheSameThread().

Referenced by flutter::Shell::Create(), flutter::ImageDecoder::Decode(), flutter::Rasterizer::Draw(), flutter::testing::EmbedderTestTaskRunner::EmbedderTestTaskRunner(), flutter::Shell::EngineHasLivePorts(), flutter::VolatilePathTracker::Erase(), flutter::Shell::GetDartVM(), flutter::Shell::GetUIIsolateLastError(), flutter::ImageDecoder::ImageDecoder(), flutter::VolatilePathTracker::Insert(), flutter::VolatilePathTracker::OnFrame(), flutter::PlatformViewIOS::RegisterExternalTexture(), flutter::Shell::RegisterImageDecoder(), flutter::Shell::ReloadSystemFonts(), flutter::testing::RunDartCodeInIsolateOnUITaskRunner(), flutter::Shell::RunEngine(), RunNowOrPostTask(), flutter::VsyncWaiter::ScheduleSecondaryCallback(), flutter::ServiceProtocolFailureError(), flutter::PlatformViewIOS::SetOwnerViewController(), TEST(), flutter::testing::TEST_F(), flutter::testing::TestIOManager::TestIOManager(), and flutter::Shell::WaitForFirstFrame().

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 TaskQueueId GetCurrentTaskQueueId()
Definition: message_loop.cc:76
static bool IsInitializedForCurrentThread()
Definition: message_loop.cc:35
static bool RunsOnTheSameThread(TaskQueueId queue_a, TaskQueueId queue_b)

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