Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
fml::MessageLoopImpl Class Referenceabstract

#include <message_loop_impl.h>

Inheritance diagram for fml::MessageLoopImpl:
fml::Wakeable fml::RefCountedThreadSafe< MessageLoopImpl > fml::internal::RefCountedThreadSafeBase fml::MessageLoopAndroid fml::MessageLoopDarwin fml::MessageLoopFuchsia fml::MessageLoopLinux fml::MessageLoopWin

Public Member Functions

virtual ~MessageLoopImpl ()
 
virtual void Run ()=0
 
virtual void Terminate ()=0
 
void PostTask (const fml::closure &task, fml::TimePoint target_time)
 
void AddTaskObserver (intptr_t key, const fml::closure &callback)
 
void RemoveTaskObserver (intptr_t key)
 
void DoRun ()
 
void DoTerminate ()
 
virtual TaskQueueId GetTaskQueueId () const
 
- Public Member Functions inherited from fml::Wakeable
virtual ~Wakeable ()
 
virtual void WakeUp (fml::TimePoint time_point)=0
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< MessageLoopImpl >
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 fml::RefPtr< MessageLoopImplCreate ()
 

Protected Member Functions

void RunExpiredTasksNow ()
 
void RunSingleExpiredTaskNow ()
 
 MessageLoopImpl ()
 
- Protected Member Functions inherited from fml::RefCountedThreadSafe< MessageLoopImpl >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 

Friends

class MessageLoop
 

Detailed Description

An abstract class that represents the differences in implementation of a fml::MessageLoop depending on the platform.

See also
fml::MessageLoop
fml::MessageLoopAndroid
fml::MessageLoopDarwin

Definition at line 31 of file message_loop_impl.h.

Constructor & Destructor Documentation

◆ ~MessageLoopImpl()

fml::MessageLoopImpl::~MessageLoopImpl ( )
virtual

Definition at line 52 of file message_loop_impl.cc.

52 {
53 task_queue_->Dispose(queue_id_);
54}
void Dispose(TaskQueueId queue_id)

◆ MessageLoopImpl()

fml::MessageLoopImpl::MessageLoopImpl ( )
protected

Definition at line 45 of file message_loop_impl.cc.

47 queue_id_(task_queue_->CreateTaskQueue()),
48 terminated_(false) {
49 task_queue_->SetWakeable(queue_id_, this);
50}
static MessageLoopTaskQueues * GetInstance()
void SetWakeable(TaskQueueId queue_id, fml::Wakeable *wakeable)

Member Function Documentation

◆ AddTaskObserver()

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

Definition at line 67 of file message_loop_impl.cc.

68 {
69 FML_DCHECK(callback != nullptr);
70 FML_DCHECK(MessageLoop::GetCurrent().GetLoopImpl().get() == this)
71 << "Message loop task observer must be added on the same thread as the "
72 "loop.";
73 if (callback != nullptr) {
74 task_queue_->AddTaskObserver(queue_id_, key, callback);
75 } else {
76 FML_LOG(ERROR) << "Tried to add a null TaskObserver.";
77 }
78}
void AddTaskObserver(TaskQueueId queue_id, intptr_t key, const fml::closure &callback)
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_LOG(severity)
Definition: logging.h:82
#define FML_DCHECK(condition)
Definition: logging.h:103
const myers::Point & get(const myers::Segment &)
#define ERROR(message)
Definition: elf_loader.cc:260

◆ Create()

fml::RefPtr< MessageLoopImpl > fml::MessageLoopImpl::Create ( )
static

Definition at line 29 of file message_loop_impl.cc.

29 {
30#if FML_OS_MACOSX
31 return fml::MakeRefCounted<MessageLoopDarwin>();
32#elif FML_OS_ANDROID
33 return fml::MakeRefCounted<MessageLoopAndroid>();
34#elif OS_FUCHSIA
35 return fml::MakeRefCounted<MessageLoopFuchsia>();
36#elif FML_OS_LINUX
37 return fml::MakeRefCounted<MessageLoopLinux>();
38#elif FML_OS_WIN
39 return fml::MakeRefCounted<MessageLoopWin>();
40#else
41 return nullptr;
42#endif
43}

◆ DoRun()

void fml::MessageLoopImpl::DoRun ( )

Definition at line 87 of file message_loop_impl.cc.

87 {
88 if (terminated_) {
89 // Message loops may be run only once.
90 return;
91 }
92
93 // Allow the implementation to do its thing.
94 Run();
95
96 // The loop may have been implicitly terminated. This can happen if the
97 // implementation supports termination via platform specific APIs or just
98 // error conditions. Set the terminated flag manually.
99 terminated_ = true;
100
101 // The message loop is shutting down. Check if there are expired tasks. This
102 // is the last chance for expired tasks to be serviced. Make sure the
103 // terminated flag is already set so we don't accrue additional tasks now.
105
106 // When the message loop is in the process of shutting down, pending tasks
107 // should be destructed on the message loop's thread. We have just returned
108 // from the implementations |Run| method which we know is on the correct
109 // thread. Drop all pending tasks on the floor.
110 task_queue_->DisposeTasks(queue_id_);
111}
virtual void Run()=0
void DisposeTasks(TaskQueueId queue_id)

◆ DoTerminate()

void fml::MessageLoopImpl::DoTerminate ( )

Definition at line 113 of file message_loop_impl.cc.

113 {
114 terminated_ = true;
115 Terminate();
116}
virtual void Terminate()=0

◆ GetTaskQueueId()

TaskQueueId fml::MessageLoopImpl::GetTaskQueueId ( ) const
virtual

Definition at line 146 of file message_loop_impl.cc.

146 {
147 return queue_id_;
148}

◆ PostTask()

void fml::MessageLoopImpl::PostTask ( const fml::closure task,
fml::TimePoint  target_time 
)

Definition at line 56 of file message_loop_impl.cc.

57 {
58 FML_DCHECK(task != nullptr);
59 if (terminated_) {
60 // If the message loop has already been terminated, PostTask should destruct
61 // |task| synchronously within this function.
62 return;
63 }
64 task_queue_->RegisterTask(queue_id_, task, target_time);
65}
void RegisterTask(TaskQueueId queue_id, const fml::closure &task, fml::TimePoint target_time, fml::TaskSourceGrade task_source_grade=fml::TaskSourceGrade::kUnspecified)

◆ RemoveTaskObserver()

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

Definition at line 80 of file message_loop_impl.cc.

80 {
81 FML_DCHECK(MessageLoop::GetCurrent().GetLoopImpl().get() == this)
82 << "Message loop task observer must be removed from the same thread as "
83 "the loop.";
84 task_queue_->RemoveTaskObserver(queue_id_, key);
85}
void RemoveTaskObserver(TaskQueueId queue_id, intptr_t key)

◆ Run()

virtual void fml::MessageLoopImpl::Run ( )
pure virtual

◆ RunExpiredTasksNow()

void fml::MessageLoopImpl::RunExpiredTasksNow ( )
protected

Definition at line 138 of file message_loop_impl.cc.

138 {
139 FlushTasks(FlushType::kAll);
140}

◆ RunSingleExpiredTaskNow()

void fml::MessageLoopImpl::RunSingleExpiredTaskNow ( )
protected

Definition at line 142 of file message_loop_impl.cc.

142 {
143 FlushTasks(FlushType::kSingle);
144}

◆ Terminate()

virtual void fml::MessageLoopImpl::Terminate ( )
pure virtual

Friends And Related Function Documentation

◆ MessageLoop

friend class MessageLoop
friend

Definition at line 57 of file message_loop_impl.h.


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