5#include "flutter/fml/platform/fuchsia/message_loop_fuchsia.h"
7#include <lib/async-loop/default.h>
8#include <lib/async/cpp/task.h>
9#include <lib/async/default.h>
10#include <lib/zx/time.h>
11#include <zircon/status.h>
13#include "flutter/fml/platform/fuchsia/task_observers.h"
20static void LoopEpilogue(async_loop_t*,
void*) {
24constexpr async_loop_config_t kLoopConfig = {
25 .make_default_for_current_thread =
false,
26 .epilogue = &LoopEpilogue,
31MessageLoopFuchsia::MessageLoopFuchsia() : loop_(&kLoopConfig) {
32 async_set_default_dispatcher(loop_.dispatcher());
34 zx_status_t timer_status =
37 <<
"MessageLoopFuchsia failed to create timer; status="
38 << zx_status_get_string(timer_status);
41MessageLoopFuchsia::~MessageLoopFuchsia() {
44 if (async_get_default_dispatcher() == loop_.dispatcher()) {
45 async_set_default_dispatcher(
nullptr);
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) {
57 FML_CHECK(signal->observed & ZX_TIMER_SIGNALED);
76 zx_status_t wait_status = wait->Begin(loop_.dispatcher());
78 <<
"MessageLoopFuchsia::WakeUp failed to wait for timer; status="
79 << zx_status_get_string(wait_status);
83 zx_status_t wait_status = timer_wait_->Begin(loop_.dispatcher());
85 <<
"MessageLoopFuchsia::WakeUp failed to wait for timer; status="
86 << zx_status_get_string(wait_status);
93 if (timer_wait_->is_pending()) {
94 timer_wait_->Cancel();
99void MessageLoopFuchsia::Terminate() {
107 zx_status_t timer_status = timer_.set(due_time, kZeroSlack);
109 <<
"MessageLoopFuchsia::WakeUp failed to set timer; status="
110 << zx_status_get_string(timer_status);
constexpr int64_t ToNanoseconds() const
TimeDelta ToEpochDelta() const
#define FML_CHECK(condition)
void ExecuteAfterTaskObservers()
static double time(int loops, Benchmark *bench, Target *target)