Chromium Code Reviews| 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_THREAD_POOL_H_ |
| 6 #define BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_ | 6 #define BASE_TASK_SCHEDULER_SCHEDULER_THREAD_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 struct SequenceSortKey; | 21 struct SequenceSortKey; |
| 21 | 22 |
| 22 // Interface for a thread pool. | 23 // Interface for a thread pool. |
| 23 class BASE_EXPORT SchedulerThreadPool { | 24 class BASE_EXPORT SchedulerThreadPool { |
| 24 public: | 25 public: |
| 25 virtual ~SchedulerThreadPool() = default; | 26 virtual ~SchedulerThreadPool() = default; |
| 26 | 27 |
| 27 // Returns a TaskRunner whose PostTask invocations will result in scheduling | 28 // Returns a TaskRunner whose PostTask invocations will result in scheduling |
| 28 // Tasks with |traits| and |execution_mode| in this thread pool. | 29 // Tasks with |traits| and |execution_mode| in this thread pool. |
| 29 virtual scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( | 30 virtual scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
| 30 const TaskTraits& traits, | 31 const TaskTraits& traits, |
| 31 ExecutionMode execution_mode) = 0; | 32 ExecutionMode execution_mode) = 0; |
| 32 | 33 |
| 33 // Inserts |sequence| into this thread pool's shared priority queue with | 34 // Inserts |sequence| into this thread pool's shared priority queue with |
| 34 // |sequence_sort_key|. Must only be called from a worker thread to put | 35 // |sequence_sort_key|. Must only be called from a worker thread to put |
| 35 // |sequence| back into a PriorityQueue after running a Task from it. The | 36 // |sequence| back into a PriorityQueue after running a Task from it. The |
| 36 // worker thread doesn't have to belong to this thread pool. | 37 // worker thread doesn't have to belong to this thread pool. |
| 37 virtual void ReEnqueueSequence(scoped_refptr<Sequence> sequence, | 38 virtual void ReEnqueueSequence(scoped_refptr<Sequence> sequence, |
| 38 const SequenceSortKey& sequence_sort_key) = 0; | 39 const SequenceSortKey& sequence_sort_key) = 0; |
| 39 | 40 |
| 40 // Posts |task| to be executed as part of |sequence|. Returns true if |task| | 41 // Posts |task| to be executed as part of |sequence|. |task| will run on |
| 41 // is posted. | 42 // |worker_thread| if specified. Returns true if |task| is posted. |
| 42 virtual bool PostTaskWithSequence(std::unique_ptr<Task> task, | 43 virtual bool PostTaskWithSequence(std::unique_ptr<Task> task, |
|
robliao
2016/04/25 21:42:38
Similarly, should we instead have PostSingleThread
fdoray
2016/04/25 22:34:44
danakj@: What is your take on this? I think that y
gab
2016/04/26 11:46:27
+1 to single post task flow.
| |
| 43 scoped_refptr<Sequence> sequence) = 0; | 44 scoped_refptr<Sequence> sequence, |
| 45 SchedulerWorkerThread* worker_thread) = 0; | |
| 44 | 46 |
| 45 // Posts |task| to be executed by this thread pool as part of |sequence|. The | 47 // Posts |task| to be executed by this thread pool as part of |sequence|. |
| 46 // scheduler's TaskTracker must have allowed |task| to be posted before this | 48 // |task| will run on |worker_thread| if specified. The scheduler's |
|
gab
2016/04/25 21:00:20
Add a note that SchedulerThreadPool has to be the
fdoray
2016/04/25 22:34:44
Done.
| |
| 47 // is called. This must only be called after |task|'s delayed run time. | 49 // TaskTracker must have allowed |task| to be posted before this is called. |
| 48 virtual void PostTaskWithSequenceNow(std::unique_ptr<Task> task, | 50 // This must only be called after |task|'s delayed run time. |
| 49 scoped_refptr<Sequence> sequence) = 0; | 51 virtual void PostTaskWithSequenceNow( |
| 52 std::unique_ptr<Task> task, | |
| 53 scoped_refptr<Sequence> sequence, | |
| 54 SchedulerWorkerThread* worker_thread) = 0; | |
| 50 }; | 55 }; |
| 51 | 56 |
| 52 } // namespace internal | 57 } // namespace internal |
| 53 } // namespace base | 58 } // namespace base |
| 54 | 59 |
| 55 #endif // BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_ | 60 #endif // BASE_TASK_SCHEDULER_SCHEDULER_THREAD_POOL_H_ |
| OLD | NEW |