// Copyright 2013 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "flutter/fml/memory/task_runner_checker.h" namespace fml { TaskRunnerChecker::TaskRunnerChecker() : initialized_queue_id_(InitTaskQueueId()){}; TaskRunnerChecker::~TaskRunnerChecker() = default; bool TaskRunnerChecker::RunsOnCreationTaskRunner() const { FML_CHECK(fml::MessageLoop::IsInitializedForCurrentThread()); const auto current_queue_id = MessageLoop::GetCurrentTaskQueueId(); return RunsOnTheSameThread(current_queue_id, initialized_queue_id_); }; bool TaskRunnerChecker::RunsOnTheSameThread(TaskQueueId queue_a, TaskQueueId queue_b) { if (queue_a == queue_b) { return true; } auto queues = MessageLoopTaskQueues::GetInstance(); if (queues->Owns(queue_a, queue_b)) { return true; } if (queues->Owns(queue_b, queue_a)) { return true; } return false; }; TaskQueueId TaskRunnerChecker::InitTaskQueueId() { MessageLoop::EnsureInitializedForCurrentThread(); return MessageLoop::GetCurrentTaskQueueId(); }; } // namespace fml