Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/task_scheduler/utils.h" | |
| 6 | |
| 7 #include <utility> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/memory/ptr_util.h" | |
| 11 #include "base/task_scheduler/priority_queue.h" | |
| 12 #include "base/task_scheduler/sequence_sort_key.h" | |
| 13 #include "base/task_scheduler/task_tracker.h" | |
| 14 | |
| 15 namespace base { | |
| 16 namespace internal { | |
| 17 | |
| 18 bool PostTaskHelper(std::unique_ptr<Task> task, | |
|
danakj
2016/04/07 23:08:44
Can this be a method on SchedulerThreadPool?
That
fdoray
2016/04/08 14:53:03
This method will also be used with single-threaded
danakj
2016/04/08 18:05:32
Why aren't single-threaded queues a SchedulerThrea
fdoray
2016/04/08 19:00:05
Each thread in a pool will get work from both the
fdoray
2016/04/11 14:25:46
Usage of this helper in DelayedTaskManager: https:
| |
| 19 scoped_refptr<Sequence> sequence, | |
| 20 PriorityQueue* priority_queue, | |
| 21 TaskTracker* task_tracker) { | |
| 22 DCHECK(task); | |
| 23 DCHECK(sequence); | |
| 24 DCHECK(priority_queue); | |
| 25 DCHECK(task_tracker); | |
| 26 | |
| 27 if (!task_tracker->WillPostTask(task.get())) | |
| 28 return false; | |
| 29 | |
| 30 const bool sequence_was_empty = sequence->PushTask(std::move(task)); | |
| 31 if (sequence_was_empty) { | |
| 32 // Insert |sequence| in |priority_queue| if it was empty before |task| was | |
| 33 // inserted into it. When that's not the case, one of these must be true: | |
| 34 // - |sequence| is already in a PriorityQueue, or, | |
| 35 // - A worker thread is running a Task from |sequence|. It will insert | |
| 36 // |sequence| in a PriorityQueue once it's done running the Task. | |
| 37 const SequenceSortKey sequence_sort_key = sequence->GetSortKey(); | |
| 38 priority_queue->BeginTransaction()->Push( | |
| 39 WrapUnique(new PriorityQueue::SequenceAndSortKey(std::move(sequence), | |
| 40 sequence_sort_key))); | |
| 41 } | |
| 42 | |
| 43 return true; | |
| 44 } | |
| 45 | |
| 46 } // namespace internal | |
| 47 } // namespace base | |
| OLD | NEW |