Flutter Engine
tonic::DartMicrotaskQueue Class Reference

#include <dart_microtask_queue.h>

Public Member Functions

 DartMicrotaskQueue ()
 
 ~DartMicrotaskQueue ()
 
void ScheduleMicrotask (Dart_Handle callback)
 
void RunMicrotasks ()
 
void Destroy ()
 
bool HasMicrotasks () const
 
DartErrorHandleType GetLastError ()
 

Static Public Member Functions

static void StartForCurrentThread ()
 
static DartMicrotaskQueueGetForCurrentThread ()
 

Detailed Description

Definition at line 16 of file dart_microtask_queue.h.

Constructor & Destructor Documentation

◆ DartMicrotaskQueue()

tonic::DartMicrotaskQueue::DartMicrotaskQueue ( )

Definition at line 54 of file dart_microtask_queue.cc.

References ~DartMicrotaskQueue().

Referenced by StartForCurrentThread().

54 : last_error_(kNoError) {}

◆ ~DartMicrotaskQueue()

tonic::DartMicrotaskQueue::~DartMicrotaskQueue ( )
default

Referenced by DartMicrotaskQueue().

Member Function Documentation

◆ Destroy()

void tonic::DartMicrotaskQueue::Destroy ( )

Definition at line 97 of file dart_microtask_queue.cc.

References GetForCurrentThread(), and TONIC_DCHECK.

Referenced by dart_runner::DartComponentController::Main().

97  {
99  SetQueue(nullptr);
100  delete this;
101 }
static DartMicrotaskQueue * GetForCurrentThread()
#define TONIC_DCHECK
Definition: macros.h:32

◆ GetForCurrentThread()

DartMicrotaskQueue * tonic::DartMicrotaskQueue::GetForCurrentThread ( )
static

Definition at line 62 of file dart_microtask_queue.cc.

Referenced by Destroy(), and dart_runner::DartComponentController::Main().

62  {
63  return GetQueue();
64 }

◆ GetLastError()

DartErrorHandleType tonic::DartMicrotaskQueue::GetLastError ( )

Definition at line 103 of file dart_microtask_queue.cc.

Referenced by flutter::UIDartState::GetLastError(), and HasMicrotasks().

103  {
104  return last_error_;
105 }

◆ HasMicrotasks()

bool tonic::DartMicrotaskQueue::HasMicrotasks ( ) const
inline

Definition at line 29 of file dart_microtask_queue.h.

References GetLastError().

29 { return !queue_.empty(); }

◆ RunMicrotasks()

void tonic::DartMicrotaskQueue::RunMicrotasks ( )

Definition at line 70 of file dart_microtask_queue.cc.

References error, tonic::GetErrorHandleType(), tonic::kNoError, tonic::LogIfError(), and fml::swap().

Referenced by flutter::UIDartState::FlushMicrotasksNow().

70  {
71  while (!queue_.empty()) {
72  MicrotaskQueue local;
73  std::swap(queue_, local);
74  for (const auto& callback : local) {
75  if (auto dart_state = callback.dart_state().lock()) {
76  DartState::Scope dart_scope(dart_state.get());
77  Dart_Handle result = Dart_InvokeClosure(callback.value(), 0, nullptr);
78  // If the Dart program has set a return code, then it is intending to
79  // shut down by way of a fatal error, and so there is no need to emit a
80  // log message.
81  if (!dart_state->has_set_return_code() || !Dart_IsError(result) ||
82  !Dart_IsFatalError(result)) {
83  LogIfError(result);
84  }
86  if (error != kNoError) {
87  last_error_ = error;
88  }
89  dart_state->MessageEpilogue(result);
90  if (!Dart_CurrentIsolate())
91  return;
92  }
93  }
94  }
95 }
FlMethodResponse GError ** error
void swap(scoped_nsprotocol< C > &p1, scoped_nsprotocol< C > &p2)
DartErrorHandleType GetErrorHandleType(Dart_Handle handle)
Definition: dart_error.cc:34
DartErrorHandleType
Definition: dart_error.h:18
bool LogIfError(Dart_Handle handle)
Definition: dart_error.cc:15

◆ ScheduleMicrotask()

void tonic::DartMicrotaskQueue::ScheduleMicrotask ( Dart_Handle  callback)

Definition at line 66 of file dart_microtask_queue.cc.

References tonic::DartState::Current().

Referenced by flutter::UIDartState::ScheduleMicrotask().

66  {
67  queue_.emplace_back(DartState::Current(), callback);
68 }
static DartState * Current()
Definition: dart_state.cc:55

◆ StartForCurrentThread()

void tonic::DartMicrotaskQueue::StartForCurrentThread ( )
static

Definition at line 58 of file dart_microtask_queue.cc.

References DartMicrotaskQueue().

Referenced by dart_runner::DartComponentController::Main().

58  {
59  SetQueue(new DartMicrotaskQueue());
60 }

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