Flutter Engine
message_loop_fuchsia.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/fml/platform/fuchsia/message_loop_fuchsia.h"
6 
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 
12 namespace fml {
13 
14 MessageLoopFuchsia::MessageLoopFuchsia()
15  : loop_(&kAsyncLoopConfigNoAttachToCurrentThread) {
16  async_set_default_dispatcher(loop_.dispatcher());
17 }
18 
19 MessageLoopFuchsia::~MessageLoopFuchsia() {
20  // It is only safe to unset the current thread's default dispatcher if it is
21  // already pointing to this loop.
22  if (async_get_default_dispatcher() == loop_.dispatcher()) {
23  async_set_default_dispatcher(nullptr);
24  }
25 }
26 
27 void MessageLoopFuchsia::Run() {
28  loop_.Run();
29 }
30 
31 void MessageLoopFuchsia::Terminate() {
32  loop_.Quit();
33 }
34 
35 void MessageLoopFuchsia::WakeUp(fml::TimePoint time_point) {
37  zx::duration due_time{0};
38  if (time_point > now) {
39  due_time = zx::nsec((time_point - now).ToNanoseconds());
40  }
41 
42  auto status = async::PostDelayedTask(
43  loop_.dispatcher(), [this]() { RunExpiredTasksNow(); }, due_time);
44  FML_DCHECK(status == ZX_OK);
45 }
46 
47 } // namespace fml
#define FML_DCHECK(condition)
Definition: logging.h:86
Definition: ascii_trie.cc:9
static TimePoint Now()
Definition: time_point.cc:26