OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_H_ | 5 #ifndef BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_H_ |
6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_H_ | 6 #define BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/sequenced_task_runner.h" |
| 13 #include "base/single_thread_task_runner.h" |
12 #include "base/task_runner.h" | 14 #include "base/task_runner.h" |
13 #include "base/task_scheduler/sequence.h" | 15 #include "base/task_scheduler/sequence.h" |
14 #include "base/task_scheduler/task.h" | 16 #include "base/task_scheduler/task.h" |
15 #include "base/task_scheduler/task_traits.h" | 17 #include "base/task_scheduler/task_traits.h" |
16 | 18 |
17 namespace base { | 19 namespace base { |
18 namespace internal { | 20 namespace internal { |
19 | 21 |
20 class SchedulerWorker; | 22 class SchedulerWorker; |
21 class SequenceSortKey; | 23 class SequenceSortKey; |
22 | 24 |
23 // Interface for a worker pool. | 25 // Interface for a worker pool. |
24 class BASE_EXPORT SchedulerWorkerPool { | 26 class BASE_EXPORT SchedulerWorkerPool { |
25 public: | 27 public: |
26 virtual ~SchedulerWorkerPool() = default; | 28 virtual ~SchedulerWorkerPool() = default; |
27 | 29 |
28 // Returns a TaskRunner whose PostTask invocations will result in scheduling | 30 // Returns a TaskRunner whose PostTask invocations result in scheduling tasks |
29 // Tasks with |traits| and |execution_mode| in this SchedulerWorkerPool. | 31 // in this SchedulerWorkerPool using |traits|. Tasks may run in any order and |
| 32 // in parallel. |
30 virtual scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( | 33 virtual scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
31 const TaskTraits& traits, | 34 const TaskTraits& traits) = 0; |
32 ExecutionMode execution_mode) = 0; | 35 |
| 36 // Returns a SequencedTaskRunner whose PostTask invocations result in |
| 37 // scheduling tasks in this SchedulerWorkerPool using |traits|. Tasks run one |
| 38 // at a time in posting order. |
| 39 virtual scoped_refptr<SequencedTaskRunner> |
| 40 CreateSequencedTaskRunnerWithTraits(const TaskTraits& traits) = 0; |
| 41 |
| 42 // Returns a SingleThreadTaskRunner whose PostTask invocations result in |
| 43 // scheduling tasks in this SchedulerWorkerPool using |traits|. Tasks run on a |
| 44 // single thread in posting order. |
| 45 virtual scoped_refptr<SingleThreadTaskRunner> |
| 46 CreateSingleThreadTaskRunnerWithTraits(const TaskTraits& traits) = 0; |
33 | 47 |
34 // Inserts |sequence| with |sequence_sort_key| into a queue of Sequences that | 48 // Inserts |sequence| with |sequence_sort_key| into a queue of Sequences that |
35 // can be processed by any worker owned by this SchedulerWorkerPool. Must only | 49 // can be processed by any worker owned by this SchedulerWorkerPool. Must only |
36 // be used to put |sequence| back into a queue after running a Task from it. | 50 // be used to put |sequence| back into a queue after running a Task from it. |
37 // The thread that calls this doesn't have to belong to this | 51 // The thread that calls this doesn't have to belong to this |
38 // SchedulerWorkerPool. | 52 // SchedulerWorkerPool. |
39 virtual void ReEnqueueSequence(scoped_refptr<Sequence> sequence, | 53 virtual void ReEnqueueSequence(scoped_refptr<Sequence> sequence, |
40 const SequenceSortKey& sequence_sort_key) = 0; | 54 const SequenceSortKey& sequence_sort_key) = 0; |
41 | 55 |
42 // Posts |task| to be executed by this SchedulerWorkerPool as part of | 56 // Posts |task| to be executed by this SchedulerWorkerPool as part of |
(...skipping 14 matching lines...) Expand all Loading... |
57 // |task|'s delayed run time. | 71 // |task|'s delayed run time. |
58 virtual void PostTaskWithSequenceNow(std::unique_ptr<Task> task, | 72 virtual void PostTaskWithSequenceNow(std::unique_ptr<Task> task, |
59 scoped_refptr<Sequence> sequence, | 73 scoped_refptr<Sequence> sequence, |
60 SchedulerWorker* worker) = 0; | 74 SchedulerWorker* worker) = 0; |
61 }; | 75 }; |
62 | 76 |
63 } // namespace internal | 77 } // namespace internal |
64 } // namespace base | 78 } // namespace base |
65 | 79 |
66 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_H_ | 80 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_H_ |
OLD | NEW |