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