| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium 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 BASE_THREADING_TASK_RUNNER_HANDLE_INTERNAL_H_ |
| 6 #define BASE_THREADING_TASK_RUNNER_HANDLE_INTERNAL_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" |
| 10 |
| 11 namespace base { |
| 12 |
| 13 class SequencedTaskRunner; |
| 14 class SingleThreadTaskRunner; |
| 15 class TaskRunner; |
| 16 |
| 17 namespace internal { |
| 18 |
| 19 // Holds the state associated with one of the TaskScope variants. Stores the |
| 20 // relevant pointer in a union and remembers the type through an enum which |
| 21 // makes for fast lookup of which levels of TaskRunners are available. |
| 22 struct TaskScopeState { |
| 23 TaskScopeState(scoped_refptr<TaskRunner> task_runner); |
| 24 TaskScopeState(scoped_refptr<SequencedTaskRunner> sequenced_task_runner); |
| 25 TaskScopeState( |
| 26 scoped_refptr<SingleThreadTaskRunner> single_thread_task_runner); |
| 27 |
| 28 ~TaskScopeState(); |
| 29 |
| 30 // TaskScope types sorted from least restrictive to most restrictive. Order |
| 31 // is used for quick lookup of available TaskScope type on current thread. |
| 32 enum Type { PARALLEL, SEQUENCED, SINGLE_THREADED }; |
| 33 |
| 34 union TaskRunnerUnion { |
| 35 TaskRunnerUnion(scoped_refptr<TaskRunner> task_runner); |
| 36 TaskRunnerUnion(scoped_refptr<SequencedTaskRunner> sequenced_task_runner); |
| 37 TaskRunnerUnion( |
| 38 scoped_refptr<SingleThreadTaskRunner> single_thread_task_runner); |
| 39 ~TaskRunnerUnion(); |
| 40 |
| 41 scoped_refptr<TaskRunner> task_runner; |
| 42 scoped_refptr<SequencedTaskRunner> sequenced_task_runner; |
| 43 scoped_refptr<SingleThreadTaskRunner> single_thread_task_runner; |
| 44 }; |
| 45 |
| 46 const Type type; |
| 47 |
| 48 // A union of TaskRunner types. Since the more specific TaskRunners inherit |
| 49 // from the less specific ones, it is always ok to get a less specific type |
| 50 // after confirming that |type| at least covers that type. |
| 51 const TaskRunnerUnion task_runners; |
| 52 |
| 53 private: |
| 54 DISALLOW_COPY_AND_ASSIGN(TaskScopeState); |
| 55 }; |
| 56 |
| 57 } // namespace internal |
| 58 } // namespace base |
| 59 |
| 60 #endif // BASE_THREADING_TASK_RUNNER_HANDLE_INTERNAL_H_ |
| OLD | NEW |