Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Friends | List of all members
fml::MessageLoop Class Reference

#include <message_loop.h>

Public Member Functions

void Run ()
 
void Terminate ()
 
void AddTaskObserver (intptr_t key, const fml::closure &callback)
 
void RemoveTaskObserver (intptr_t key)
 
fml::RefPtr< fml::TaskRunnerGetTaskRunner () const
 
void RunExpiredTasksNow ()
 
 ~MessageLoop ()
 

Static Public Member Functions

static FML_EMBEDDER_ONLY MessageLoopGetCurrent ()
 
static void EnsureInitializedForCurrentThread ()
 
static bool IsInitializedForCurrentThread ()
 
static TaskQueueId GetCurrentTaskQueueId ()
 

Friends

class TaskRunner
 
class MessageLoopImpl
 

Detailed Description

An event loop associated with a thread.

This class is the generic front-end to the MessageLoop, differences in implementation based on the running platform are in the subclasses of flutter::MessageLoopImpl (ex flutter::MessageLoopAndroid).

For scheduling events on the message loop see flutter::TaskRunner.

See also
fml::TaskRunner
fml::MessageLoopImpl
fml::MessageLoopTaskQueues
fml::Wakeable

Definition at line 28 of file message_loop.h.

Constructor & Destructor Documentation

◆ ~MessageLoop()

fml::MessageLoop::~MessageLoop ( )
default

Member Function Documentation

◆ AddTaskObserver()

void fml::MessageLoop::AddTaskObserver ( intptr_t  key,
const fml::closure callback 
)

Definition at line 64 of file message_loop.cc.

64 {
65 loop_->AddTaskObserver(key, callback);
66}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ EnsureInitializedForCurrentThread()

void fml::MessageLoop::EnsureInitializedForCurrentThread ( )
static

Definition at line 27 of file message_loop.cc.

27 {
28 if (tls_message_loop.get() != nullptr) {
29 // Already initialized.
30 return;
31 }
32 tls_message_loop.reset(new MessageLoop());
33}
static thread_local std::unique_ptr< MessageLoop > tls_message_loop
Definition: message_loop.cc:17

◆ GetCurrent()

MessageLoop & fml::MessageLoop::GetCurrent ( )
static

Definition at line 19 of file message_loop.cc.

19 {
20 auto* loop = tls_message_loop.get();
21 FML_CHECK(loop != nullptr)
22 << "MessageLoop::EnsureInitializedForCurrentThread was not called on "
23 "this thread prior to message loop use.";
24 return *loop;
25}
#define FML_CHECK(condition)
Definition: logging.h:85

◆ GetCurrentTaskQueueId()

TaskQueueId fml::MessageLoop::GetCurrentTaskQueueId ( )
static

Gets the unique identifier for the TaskQueue associated with the current thread.

See also
fml::MessageLoopTaskQueues

Definition at line 76 of file message_loop.cc.

76 {
77 auto* loop = tls_message_loop.get();
78 FML_CHECK(loop != nullptr)
79 << "MessageLoop::EnsureInitializedForCurrentThread was not called on "
80 "this thread prior to message loop use.";
81 return loop->GetLoopImpl()->GetTaskQueueId();
82}

◆ GetTaskRunner()

fml::RefPtr< fml::TaskRunner > fml::MessageLoop::GetTaskRunner ( ) const

Definition at line 56 of file message_loop.cc.

56 {
57 return task_runner_;
58}

◆ IsInitializedForCurrentThread()

bool fml::MessageLoop::IsInitializedForCurrentThread ( )
static

Returns true if EnsureInitializedForCurrentThread has been called on this thread already.

Definition at line 35 of file message_loop.cc.

35 {
36 return tls_message_loop.get() != nullptr;
37}

◆ RemoveTaskObserver()

void fml::MessageLoop::RemoveTaskObserver ( intptr_t  key)

Definition at line 68 of file message_loop.cc.

68 {
69 loop_->RemoveTaskObserver(key);
70}

◆ Run()

void fml::MessageLoop::Run ( )

Definition at line 48 of file message_loop.cc.

48 {
49 loop_->DoRun();
50}

◆ RunExpiredTasksNow()

void fml::MessageLoop::RunExpiredTasksNow ( )

Definition at line 72 of file message_loop.cc.

72 {
73 loop_->RunExpiredTasksNow();
74}

◆ Terminate()

void fml::MessageLoop::Terminate ( )

Definition at line 52 of file message_loop.cc.

52 {
53 loop_->DoTerminate();
54}

Friends And Related Function Documentation

◆ MessageLoopImpl

friend class MessageLoopImpl
friend

Definition at line 62 of file message_loop.h.

◆ TaskRunner

friend class TaskRunner
friend

Definition at line 61 of file message_loop.h.


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