Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(889)

Unified Diff: base/task_scheduler/utils.cc

Issue 1708773002: TaskScheduler [7] SchedulerThreadPool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@s_5_worker_thread
Patch Set: self review Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698