Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
embedder_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#include "flutter/shell/platform/embedder/embedder_task_runner.h"
6
7#include "flutter/fml/message_loop_impl.h"
8#include "flutter/fml/message_loop_task_queues.h"
9
10namespace flutter {
11
13 size_t embedder_identifier)
14 : TaskRunner(nullptr /* loop implemenation*/),
15 embedder_identifier_(embedder_identifier),
16 dispatch_table_(std::move(table)),
17 placeholder_id_(
18 fml::MessageLoopTaskQueues::GetInstance()->CreateTaskQueue()) {
19 FML_DCHECK(dispatch_table_.post_task_callback);
21}
22
24
26 return embedder_identifier_;
27}
28
32
34 fml::TimePoint target_time) {
35 if (!task) {
36 return;
37 }
38
39 uint64_t baton = 0;
40
41 {
42 // Release the lock before the jump via the dispatch table.
43 std::scoped_lock lock(tasks_mutex_);
44 baton = ++last_baton_;
45 pending_tasks_[baton] = task;
46 }
47
48 dispatch_table_.post_task_callback(this, baton, target_time);
49}
50
55
59
60bool EmbedderTaskRunner::PostTask(uint64_t baton) {
61 fml::closure task;
62
63 {
64 std::scoped_lock lock(tasks_mutex_);
65 auto found = pending_tasks_.find(baton);
66 if (found == pending_tasks_.end()) {
67 FML_LOG(ERROR) << "Embedder attempted to post an unknown task.";
68 return false;
69 }
70 task = found->second;
71 pending_tasks_.erase(found);
72
73 // Let go of the tasks mutex befor executing the task.
74 }
75
76 FML_DCHECK(task);
77 task();
78 return true;
79}
80
81// |fml::TaskRunner|
83 return placeholder_id_;
84}
85
86} // namespace flutter
SI F table(const skcms_Curve *curve, F v)
fml::TaskQueueId GetTaskQueueId() override
void PostDelayedTask(const fml::closure &task, fml::TimeDelta delay) override
size_t GetEmbedderIdentifier() const
The unique identifier provided by the embedder for the task runner. Embedders whose dispatch tables s...
void PostTaskForTime(const fml::closure &task, fml::TimePoint target_time) override
EmbedderTaskRunner(DispatchTable table, size_t embedder_identifier)
Create a task runner with a dispatch table for delegation of task runner responsibility to the embedd...
static TimePoint Now()
Definition time_point.cc:49
#define FML_LOG(severity)
Definition logging.h:82
#define FML_DCHECK(condition)
Definition logging.h:103
std::function< void()> closure
Definition closure.h:14
Definition ref_ptr.h:256
std::function< void(EmbedderTaskRunner *task_runner, uint64_t task_baton, fml::TimePoint target_time)> post_task_callback
std::function< bool(void)> runs_task_on_current_thread_callback
#define ERROR(message)