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

Definition at line 26 of file message_loop_impl.h.

Constructor & Destructor Documentation

◆ ~MessageLoopImpl()

fml::MessageLoopImpl::~MessageLoopImpl ( )
virtual

Definition at line 53 of file message_loop_impl.cc.

53  {
54  task_queue_->Dispose(queue_id_);
55 }

◆ MessageLoopImpl()

fml::MessageLoopImpl::MessageLoopImpl ( )
protected

Definition at line 46 of file message_loop_impl.cc.

47  : task_queue_(MessageLoopTaskQueues::GetInstance()),
48  queue_id_(task_queue_->CreateTaskQueue()),
49  terminated_(false) {
50  task_queue_->SetWakeable(queue_id_, this);
51 }
static fml::RefPtr< MessageLoopTaskQueues > GetInstance()

Member Function Documentation

◆ AddTaskObserver()

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

Definition at line 69 of file message_loop_impl.cc.

References FML_DCHECK, FML_LOG, and fml::MessageLoop::GetCurrent().

70  {
71  FML_DCHECK(callback != nullptr);
72  FML_DCHECK(MessageLoop::GetCurrent().GetLoopImpl().get() == this)
73  << "Message loop task observer must be added on the same thread as the "
74  "loop.";
75  if (callback != nullptr) {
76  task_queue_->AddTaskObserver(queue_id_, key, callback);
77  } else {
78  FML_LOG(ERROR) << "Tried to add a null TaskObserver.";
79  }
80 }
#define FML_DCHECK(condition)
Definition: logging.h:86
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
#define FML_LOG(severity)
Definition: logging.h:65

◆ Create()

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

Definition at line 30 of file message_loop_impl.cc.

Referenced by fml::MessageLoop::IsInitializedForCurrentThread().

30  {
31 #if OS_MACOSX
32  return fml::MakeRefCounted<MessageLoopDarwin>();
33 #elif OS_ANDROID
34  return fml::MakeRefCounted<MessageLoopAndroid>();
35 #elif OS_FUCHSIA
36  return fml::MakeRefCounted<MessageLoopFuchsia>();
37 #elif OS_LINUX
38  return fml::MakeRefCounted<MessageLoopLinux>();
39 #elif OS_WIN
40  return fml::MakeRefCounted<MessageLoopWin>();
41 #else
42  return nullptr;
43 #endif
44 }

◆ DoRun()

void fml::MessageLoopImpl::DoRun ( )

Definition at line 89 of file message_loop_impl.cc.

References Run(), and RunExpiredTasksNow().

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

◆ DoTerminate()

void fml::MessageLoopImpl::DoTerminate ( )

Definition at line 115 of file message_loop_impl.cc.

References fml::kSingle, fml::TimePoint::Now(), Terminate(), and TRACE_EVENT0.

115  {
116  terminated_ = true;
117  Terminate();
118 }
virtual void Terminate()=0

◆ GetTaskQueueId()

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

Definition at line 150 of file message_loop_impl.cc.

150  {
151  return queue_id_;
152 }

◆ PostTask()

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

Definition at line 57 of file message_loop_impl.cc.

References FML_DCHECK.

58  {
59  FML_DCHECK(task != nullptr);
60  FML_DCHECK(task != nullptr);
61  if (terminated_) {
62  // If the message loop has already been terminated, PostTask should destruct
63  // |task| synchronously within this function.
64  return;
65  }
66  task_queue_->RegisterTask(queue_id_, task, target_time);
67 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ RemoveTaskObserver()

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

Definition at line 82 of file message_loop_impl.cc.

References FML_DCHECK, and fml::MessageLoop::GetCurrent().

82  {
83  FML_DCHECK(MessageLoop::GetCurrent().GetLoopImpl().get() == this)
84  << "Message loop task observer must be removed from the same thread as "
85  "the loop.";
86  task_queue_->RemoveTaskObserver(queue_id_, key);
87 }
#define FML_DCHECK(condition)
Definition: logging.h:86
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19

◆ Run()

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

Referenced by DoRun().

◆ RunExpiredTasksNow()

void fml::MessageLoopImpl::RunExpiredTasksNow ( )
protected

Definition at line 142 of file message_loop_impl.cc.

References fml::kAll.

Referenced by fml::AcquireLooperForThread(), and DoRun().

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

◆ RunSingleExpiredTaskNow()

void fml::MessageLoopImpl::RunSingleExpiredTaskNow ( )
protected

Definition at line 146 of file message_loop_impl.cc.

References fml::kSingle.

146  {
147  FlushTasks(FlushType::kSingle);
148 }

◆ Terminate()

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

Referenced by DoTerminate().

Friends And Related Function Documentation

◆ MessageLoop

friend class MessageLoop
friend

Definition at line 52 of file message_loop_impl.h.


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