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