Chromium Code Reviews| Index: base/task_scheduler/utils.cc |
| diff --git a/base/task_scheduler/utils.cc b/base/task_scheduler/utils.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ee1dec341d936fcc68aedf9997554b655702f4b2 |
| --- /dev/null |
| +++ b/base/task_scheduler/utils.cc |
| @@ -0,0 +1,47 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/task_scheduler/utils.h" |
| + |
| +#include <utility> |
| + |
| +#include "base/logging.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "base/task_scheduler/priority_queue.h" |
| +#include "base/task_scheduler/sequence_sort_key.h" |
| +#include "base/task_scheduler/task_tracker.h" |
| + |
| +namespace base { |
| +namespace internal { |
| + |
| +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:
|
| + scoped_refptr<Sequence> sequence, |
| + PriorityQueue* priority_queue, |
| + TaskTracker* task_tracker) { |
| + DCHECK(task); |
| + DCHECK(sequence); |
| + DCHECK(priority_queue); |
| + DCHECK(task_tracker); |
| + |
| + if (!task_tracker->WillPostTask(task.get())) |
| + return false; |
| + |
| + const bool sequence_was_empty = sequence->PushTask(std::move(task)); |
| + if (sequence_was_empty) { |
| + // Insert |sequence| in |priority_queue| if it was empty before |task| was |
| + // inserted into it. When that's not the case, one of these must be true: |
| + // - |sequence| is already in a PriorityQueue, or, |
| + // - A worker thread is running a Task from |sequence|. It will insert |
| + // |sequence| in a PriorityQueue once it's done running the Task. |
| + const SequenceSortKey sequence_sort_key = sequence->GetSortKey(); |
| + priority_queue->BeginTransaction()->Push( |
| + WrapUnique(new PriorityQueue::SequenceAndSortKey(std::move(sequence), |
| + sequence_sort_key))); |
| + } |
| + |
| + return true; |
| +} |
| + |
| +} // namespace internal |
| +} // namespace base |