Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Unified Diff: base/threading/task_runner_handle_internal.h

Issue 2042383004: Introduce TaskRunnerHandle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: support for parallel tasks from SequencedWorkerPool Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/threading/task_runner_handle_internal.h
diff --git a/base/threading/task_runner_handle_internal.h b/base/threading/task_runner_handle_internal.h
new file mode 100644
index 0000000000000000000000000000000000000000..b3396efca086551ebf13df7e2450ad1b3ffa6df5
--- /dev/null
+++ b/base/threading/task_runner_handle_internal.h
@@ -0,0 +1,60 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_THREADING_TASK_RUNNER_HANDLE_INTERNAL_H_
+#define BASE_THREADING_TASK_RUNNER_HANDLE_INTERNAL_H_
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+
+namespace base {
+
+class SequencedTaskRunner;
+class SingleThreadTaskRunner;
+class TaskRunner;
+
+namespace internal {
+
+// Holds the state associated with one of the TaskScope variants. Stores the
+// relevant pointer in a union and remembers the type through an enum which
+// makes for fast lookup of which levels of TaskRunners are available.
+struct TaskScopeState {
+ TaskScopeState(scoped_refptr<TaskRunner> task_runner);
+ TaskScopeState(scoped_refptr<SequencedTaskRunner> sequenced_task_runner);
+ TaskScopeState(
+ scoped_refptr<SingleThreadTaskRunner> single_thread_task_runner);
+
+ ~TaskScopeState();
+
+ // TaskScope types sorted from least restrictive to most restrictive. Order
+ // is used for quick lookup of available TaskScope type on current thread.
+ enum Type { PARALLEL, SEQUENCED, SINGLE_THREADED };
+
+ union TaskRunnerUnion {
+ TaskRunnerUnion(scoped_refptr<TaskRunner> task_runner);
+ TaskRunnerUnion(scoped_refptr<SequencedTaskRunner> sequenced_task_runner);
+ TaskRunnerUnion(
+ scoped_refptr<SingleThreadTaskRunner> single_thread_task_runner);
+ ~TaskRunnerUnion();
+
+ scoped_refptr<TaskRunner> task_runner;
+ scoped_refptr<SequencedTaskRunner> sequenced_task_runner;
+ scoped_refptr<SingleThreadTaskRunner> single_thread_task_runner;
+ };
+
+ const Type type;
+
+ // A union of TaskRunner types. Since the more specific TaskRunners inherit
+ // from the less specific ones, it is always ok to get a less specific type
+ // after confirming that |type| at least covers that type.
+ const TaskRunnerUnion task_runners;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TaskScopeState);
+};
+
+} // namespace internal
+} // namespace base
+
+#endif // BASE_THREADING_TASK_RUNNER_HANDLE_INTERNAL_H_

Powered by Google App Engine
This is Rietveld 408576698