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" | 12 #include "base/sequenced_task_runner.h" |
13 #include "base/task_runner.h" | 13 #include "base/task_runner.h" |
14 #include "base/task_scheduler/sequence.h" | 14 #include "base/task_scheduler/sequence.h" |
15 #include "base/task_scheduler/task.h" | 15 #include "base/task_scheduler/task.h" |
16 #include "base/task_scheduler/task_traits.h" | 16 #include "base/task_scheduler/task_traits.h" |
17 | 17 |
18 namespace base { | 18 namespace base { |
19 namespace internal { | 19 namespace internal { |
20 | 20 |
21 class SequenceSortKey; | |
22 | |
23 // Interface for a worker pool. | 21 // Interface for a worker pool. |
24 class BASE_EXPORT SchedulerWorkerPool { | 22 class BASE_EXPORT SchedulerWorkerPool { |
25 public: | 23 public: |
26 virtual ~SchedulerWorkerPool() = default; | 24 virtual ~SchedulerWorkerPool() = default; |
27 | 25 |
28 // Returns a TaskRunner whose PostTask invocations result in scheduling tasks | 26 // Returns a TaskRunner whose PostTask invocations result in scheduling tasks |
29 // in this SchedulerWorkerPool using |traits|. Tasks may run in any order and | 27 // in this SchedulerWorkerPool using |traits|. Tasks may run in any order and |
30 // in parallel. | 28 // in parallel. |
31 virtual scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( | 29 virtual scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
32 const TaskTraits& traits) = 0; | 30 const TaskTraits& traits) = 0; |
33 | 31 |
34 // Returns a SequencedTaskRunner whose PostTask invocations result in | 32 // Returns a SequencedTaskRunner whose PostTask invocations result in |
35 // scheduling tasks in this SchedulerWorkerPool using |traits|. Tasks run one | 33 // scheduling tasks in this SchedulerWorkerPool using |traits|. Tasks run one |
36 // at a time in posting order. | 34 // at a time in posting order. |
37 virtual scoped_refptr<SequencedTaskRunner> | 35 virtual scoped_refptr<SequencedTaskRunner> |
38 CreateSequencedTaskRunnerWithTraits(const TaskTraits& traits) = 0; | 36 CreateSequencedTaskRunnerWithTraits(const TaskTraits& traits) = 0; |
39 | 37 |
40 // Inserts |sequence| with |sequence_sort_key| into a queue of Sequences that | |
41 // can be processed by any worker owned by this SchedulerWorkerPool. Must only | |
42 // be used to put |sequence| back into a queue after running a Task from it. | |
43 // The thread that calls this doesn't have to belong to this | |
44 // SchedulerWorkerPool. | |
45 virtual void ReEnqueueSequence(scoped_refptr<Sequence> sequence, | |
46 const SequenceSortKey& sequence_sort_key) = 0; | |
47 | |
48 // Posts |task| to be executed by this SchedulerWorkerPool as part of | 38 // Posts |task| to be executed by this SchedulerWorkerPool as part of |
49 // |sequence|. |task| won't be executed before its delayed run time, if any. | 39 // |sequence|. |task| won't be executed before its delayed run time, if any. |
50 // Returns true if |task| is posted. | 40 // Returns true if |task| is posted. |
51 virtual bool PostTaskWithSequence(std::unique_ptr<Task> task, | 41 virtual bool PostTaskWithSequence(std::unique_ptr<Task> task, |
52 scoped_refptr<Sequence> sequence) = 0; | 42 scoped_refptr<Sequence> sequence) = 0; |
53 | 43 |
54 // Posts |task| to be executed by this SchedulerWorkerPool as part of | 44 // Posts |task| to be executed by this SchedulerWorkerPool as part of |
55 // |sequence|. This must only be called after |task| has gone through | 45 // |sequence|. This must only be called after |task| has gone through |
56 // PostTaskWithSequence() and after |task|'s delayed run time. | 46 // PostTaskWithSequence() and after |task|'s delayed run time. |
57 virtual void PostTaskWithSequenceNow(std::unique_ptr<Task> task, | 47 virtual void PostTaskWithSequenceNow(std::unique_ptr<Task> task, |
58 scoped_refptr<Sequence> sequence) = 0; | 48 scoped_refptr<Sequence> sequence) = 0; |
59 }; | 49 }; |
60 | 50 |
61 } // namespace internal | 51 } // namespace internal |
62 } // namespace base | 52 } // namespace base |
63 | 53 |
64 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_H_ | 54 #endif // BASE_TASK_SCHEDULER_SCHEDULER_WORKER_POOL_H_ |
OLD | NEW |