Flutter Engine
The Flutter Engine
task_runner.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#define FML_USED_ON_EMBEDDER
6
7#include "flutter/fml/task_runner.h"
8#include "flutter/fml/memory/task_runner_checker.h"
9
10#include <utility>
11
12#include "flutter/fml/logging.h"
13#include "flutter/fml/message_loop.h"
14#include "flutter/fml/message_loop_impl.h"
15#include "flutter/fml/message_loop_task_queues.h"
16
17namespace fml {
18
20 : loop_(std::move(loop)) {}
21
22TaskRunner::~TaskRunner() = default;
23
25 loop_->PostTask(task, fml::TimePoint::Now());
26}
27
29 fml::TimePoint target_time) {
30 loop_->PostTask(task, target_time);
31}
32
34 fml::TimeDelta delay) {
35 loop_->PostTask(task, fml::TimePoint::Now() + delay);
36}
37
39 FML_DCHECK(loop_);
40 return loop_->GetTaskQueueId();
41}
42
45 return false;
46 }
47
48 const auto current_queue_id = MessageLoop::GetCurrentTaskQueueId();
49 const auto loop_queue_id = loop_->GetTaskQueueId();
50
51 return TaskRunnerChecker::RunsOnTheSameThread(current_queue_id,
52 loop_queue_id);
53}
54
56 const fml::closure& task) {
57 FML_DCHECK(runner);
58 if (runner->RunsTasksOnCurrentThread()) {
59 task();
60 } else {
61 runner->PostTask(task);
62 }
63}
64
65} // namespace fml
static bool IsInitializedForCurrentThread()
Definition: message_loop.cc:35
static TaskQueueId GetCurrentTaskQueueId()
Definition: message_loop.cc:76
static bool RunsOnTheSameThread(TaskQueueId queue_a, TaskQueueId queue_b)
static void RunNowOrPostTask(const fml::RefPtr< fml::TaskRunner > &runner, const fml::closure &task)
Definition: task_runner.cc:55
virtual ~TaskRunner()
virtual void PostTaskForTime(const fml::closure &task, fml::TimePoint target_time)
Definition: task_runner.cc:28
virtual void PostTask(const fml::closure &task) override
Definition: task_runner.cc:24
TaskRunner(fml::RefPtr< MessageLoopImpl > loop)
Definition: task_runner.cc:19
virtual bool RunsTasksOnCurrentThread()
Definition: task_runner.cc:43
virtual TaskQueueId GetTaskQueueId()
Definition: task_runner.cc:38
virtual void PostDelayedTask(const fml::closure &task, fml::TimeDelta delay)
Definition: task_runner.cc:33
static TimePoint Now()
Definition: time_point.cc:49
#define FML_DCHECK(condition)
Definition: logging.h:103
Definition: ascii_trie.cc:9
std::function< void()> closure
Definition: closure.h:14
Definition: ref_ptr.h:256