Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Private Member Functions | List of all members
fml::MessageLoopFuchsia Class Reference

#include <message_loop_fuchsia.h>

Inheritance diagram for fml::MessageLoopFuchsia:
fml::MessageLoopImpl fml::Wakeable fml::RefCountedThreadSafe< MessageLoopImpl > fml::internal::RefCountedThreadSafeBase

Private Member Functions

 ~MessageLoopFuchsia () override
 
void Run () override
 
void Terminate () override
 
void WakeUp (fml::TimePoint time_point) override
 

Additional Inherited Members

- Public Member Functions inherited from fml::MessageLoopImpl
virtual ~MessageLoopImpl ()
 
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 ()
 
- 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 inherited from fml::MessageLoopImpl
static fml::RefPtr< MessageLoopImplCreate ()
 
- Protected Member Functions inherited from fml::MessageLoopImpl
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 ()
 

Detailed Description

Definition at line 17 of file message_loop_fuchsia.h.

Member Function Documentation

◆ Run()

void fml::MessageLoopFuchsia::Run ( )
overrideprivatevirtual

Implements fml::MessageLoopImpl.

Definition at line 49 of file message_loop_fuchsia.cc.

49 {
50 timer_wait_ = std::make_unique<async::Wait>(
51 timer_.get(), ZX_TIMER_SIGNALED, 0,
52 [this](async_dispatcher_t* dispatcher, async::Wait* wait,
53 zx_status_t status, const zx_packet_signal_t* signal) {
54 if (status == ZX_ERR_CANCELED) {
55 return;
56 }
57 FML_CHECK(signal->observed & ZX_TIMER_SIGNALED);
58
59 // Cancel the timer now, because `RunExpiredTasksNow` might not re-arm
60 // the timer. That would leave the timer in a signalled state and it
61 // would trigger the async::Wait again immediately, creating a busy
62 // loop.
63 //
64 // NOTE: It is not neccesary to synchronize this with the timer_.set()
65 // call below, even though WakeUp() can be called from any thread and
66 // thus timer_.set() can run in parallel with this timer_.cancel().
67 //
68 // Zircon will synchronize the 2 syscalls internally, and the Wait loop
69 // here is resilient to cancel() and set() being called in any order.
70 timer_.cancel();
71
72 // Run the tasks, which may or may not re-arm the timer for the future.
74
75 // Kick off the next iteration of the timer wait loop.
76 zx_status_t wait_status = wait->Begin(loop_.dispatcher());
77 FML_CHECK(wait_status == ZX_OK)
78 << "MessageLoopFuchsia::WakeUp failed to wait for timer; status="
79 << zx_status_get_string(wait_status);
80 });
81
82 // Kick off the first iteration of the timer wait loop.
83 zx_status_t wait_status = timer_wait_->Begin(loop_.dispatcher());
84 FML_CHECK(wait_status == ZX_OK)
85 << "MessageLoopFuchsia::WakeUp failed to wait for timer; status="
86 << zx_status_get_string(wait_status);
87
88 // Kick off the underlying async loop that services the timer wait in addition
89 // to other tasks and waits queued on its `async_dispatcher_t`.
90 loop_.Run();
91
92 // Ensure any pending waits on the timer are properly canceled.
93 if (timer_wait_->is_pending()) {
94 timer_wait_->Cancel();
95 timer_.cancel();
96 }
97}
#define FML_CHECK(condition)
Definition logging.h:85

◆ Terminate()

void fml::MessageLoopFuchsia::Terminate ( )
overrideprivatevirtual

Implements fml::MessageLoopImpl.

Definition at line 99 of file message_loop_fuchsia.cc.

99 {
100 loop_.Quit();
101}

◆ WakeUp()

void fml::MessageLoopFuchsia::WakeUp ( fml::TimePoint  time_point)
overrideprivatevirtual

Implements fml::Wakeable.

Definition at line 103 of file message_loop_fuchsia.cc.

103 {
104 constexpr zx::duration kZeroSlack(0);
105 zx::time due_time(time_point.ToEpochDelta().ToNanoseconds());
106
107 zx_status_t timer_status = timer_.set(due_time, kZeroSlack);
108 FML_CHECK(timer_status == ZX_OK)
109 << "MessageLoopFuchsia::WakeUp failed to set timer; status="
110 << zx_status_get_string(timer_status);
111}
constexpr int64_t ToNanoseconds() const
Definition time_delta.h:61
TimeDelta ToEpochDelta() const
Definition time_point.h:52

◆ ~MessageLoopFuchsia()

fml::MessageLoopFuchsia::~MessageLoopFuchsia ( )
overrideprivate

Definition at line 41 of file message_loop_fuchsia.cc.

41 {
42 // It is only safe to unset the current thread's default dispatcher if it is
43 // already pointing to this loop.
44 if (async_get_default_dispatcher() == loop_.dispatcher()) {
45 async_set_default_dispatcher(nullptr);
46 }
47}

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