Flutter Engine
The Flutter Engine
task_runner_adapter.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
6
7#include <lib/async/cpp/task.h>
8#include <lib/async/default.h>
9#include <lib/zx/time.h>
10
11#include "flutter/fml/message_loop_impl.h"
12
13namespace flutter_runner {
14
16 public:
17 CompatTaskRunner(async_dispatcher_t* dispatcher)
18 : fml::TaskRunner(nullptr), forwarding_target_(dispatcher) {
19 FML_DCHECK(forwarding_target_);
20 }
21
22 void PostTask(const fml::closure& task) override {
23 async::PostTask(forwarding_target_, task);
24 }
25
26 void PostTaskForTime(const fml::closure& task,
27 fml::TimePoint target_time) override {
28 async::PostTaskForTime(
29 forwarding_target_, task,
30 zx::time(target_time.ToEpochDelta().ToNanoseconds()));
31 }
32
33 void PostDelayedTask(const fml::closure& task,
34 fml::TimeDelta delay) override {
35 async::PostDelayedTask(forwarding_target_, task,
37 }
38
39 bool RunsTasksOnCurrentThread() override {
40 return forwarding_target_ == async_get_default_dispatcher();
41 }
42
43 private:
44 async_dispatcher_t* forwarding_target_;
45
46 FML_DISALLOW_COPY_AND_ASSIGN(CompatTaskRunner);
47 FML_FRIEND_MAKE_REF_COUNTED(CompatTaskRunner);
48 FML_FRIEND_REF_COUNTED_THREAD_SAFE(CompatTaskRunner);
49};
50
52 async_dispatcher_t* dispatcher) {
53 return fml::MakeRefCounted<CompatTaskRunner>(dispatcher);
54}
55
56} // namespace flutter_runner
void PostTask(const fml::closure &task) override
void PostTaskForTime(const fml::closure &task, fml::TimePoint target_time) override
void PostDelayedTask(const fml::closure &task, fml::TimeDelta delay) override
CompatTaskRunner(async_dispatcher_t *dispatcher)
TaskRunner(fml::RefPtr< MessageLoopImpl > loop)
Definition: task_runner.cc:19
constexpr int64_t ToNanoseconds() const
Definition: time_delta.h:61
TimeDelta ToEpochDelta() const
Definition: time_point.h:52
double duration
Definition: examples.cpp:30
#define FML_DCHECK(condition)
Definition: logging.h:103
fml::RefPtr< fml::TaskRunner > CreateFMLTaskRunner(async_dispatcher_t *dispatcher)
Definition: ascii_trie.cc:9
std::function< void()> closure
Definition: closure.h:14
static double time(int loops, Benchmark *bench, Target *target)
Definition: nanobench.cpp:394