| 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 | #ifndef FLUTTER_FML_MEMORY_TASK_RUNNER_CHECKER_H_ |
| 6 | #define FLUTTER_FML_MEMORY_TASK_RUNNER_CHECKER_H_ |
| 7 | |
| 8 | #include "flutter/fml/message_loop.h" |
| 9 | #include "flutter/fml/task_runner.h" |
| 10 | |
| 11 | namespace fml { |
| 12 | |
| 13 | class TaskRunnerChecker final { |
| 14 | public: |
| 15 | TaskRunnerChecker(); |
| 16 | |
| 17 | ~TaskRunnerChecker(); |
| 18 | |
| 19 | bool RunsOnCreationTaskRunner() const; |
| 20 | |
| 21 | static bool RunsOnTheSameThread(TaskQueueId queue_a, TaskQueueId queue_b); |
| 22 | |
| 23 | private: |
| 24 | TaskQueueId initialized_queue_id_; |
| 25 | std::set<TaskQueueId> subsumed_queue_ids_; |
| 26 | |
| 27 | TaskQueueId InitTaskQueueId(); |
| 28 | }; |
| 29 | |
| 30 | #if !defined(NDEBUG) |
| 31 | #define FML_DECLARE_TASK_RUNNER_CHECKER(c) fml::TaskRunnerChecker c |
| 32 | #define FML_DCHECK_TASK_RUNNER_IS_CURRENT(c) \ |
| 33 | FML_DCHECK((c).RunsOnCreationTaskRunner()) |
| 34 | #else |
| 35 | #define FML_DECLARE_TASK_RUNNER_CHECKER(c) |
| 36 | #define FML_DCHECK_TASK_RUNNER_IS_CURRENT(c) ((void)0) |
| 37 | #endif |
| 38 | |
| 39 | } // namespace fml |
| 40 | |
| 41 | #endif // FLUTTER_FML_MEMORY_THREAD_CHECKER_H_ |
| 42 | |