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/memory/task_runner_checker.h" |
6 | |
7 | namespace fml { |
8 | |
9 | TaskRunnerChecker::TaskRunnerChecker() |
10 | : initialized_queue_id_(InitTaskQueueId()){}; |
11 | |
12 | TaskRunnerChecker::~TaskRunnerChecker() = default; |
13 | |
14 | bool TaskRunnerChecker::RunsOnCreationTaskRunner() const { |
15 | FML_CHECK(fml::MessageLoop::IsInitializedForCurrentThread()); |
16 | const auto current_queue_id = MessageLoop::GetCurrentTaskQueueId(); |
17 | return RunsOnTheSameThread(current_queue_id, initialized_queue_id_); |
18 | }; |
19 | |
20 | bool TaskRunnerChecker::RunsOnTheSameThread(TaskQueueId queue_a, |
21 | TaskQueueId queue_b) { |
22 | if (queue_a == queue_b) { |
23 | return true; |
24 | } |
25 | |
26 | auto queues = MessageLoopTaskQueues::GetInstance(); |
27 | if (queues->Owns(queue_a, queue_b)) { |
28 | return true; |
29 | } |
30 | if (queues->Owns(queue_b, queue_a)) { |
31 | return true; |
32 | } |
33 | return false; |
34 | }; |
35 | |
36 | TaskQueueId TaskRunnerChecker::InitTaskQueueId() { |
37 | MessageLoop::EnsureInitializedForCurrentThread(); |
38 | return MessageLoop::GetCurrentTaskQueueId(); |
39 | }; |
40 | |
41 | } // namespace fml |
42 |