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

Unified Diff: content/renderer/scheduler/task_queue_manager.cc

Issue 894183002: Revert of Run task queue manager work in batches (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 11 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: content/renderer/scheduler/task_queue_manager.cc
diff --git a/content/renderer/scheduler/task_queue_manager.cc b/content/renderer/scheduler/task_queue_manager.cc
index 5db247bf7839045110afbfb3a2b051d02c2524fe..07d5e669919d408d9ea126a3d3291f13c0dc4eef 100644
--- a/content/renderer/scheduler/task_queue_manager.cc
+++ b/content/renderer/scheduler/task_queue_manager.cc
@@ -4,18 +4,13 @@
#include "content/renderer/scheduler/task_queue_manager.h"
-#include <queue>
-
#include "base/bind.h"
+#include "base/debug/trace_event.h"
+#include "base/debug/trace_event_argument.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_event_argument.h"
-#include "cc/test/test_now_source.h"
#include "content/renderer/scheduler/task_queue_selector.h"
-namespace {
-const int64_t kMaxTimeTicks = std::numeric_limits<int64>::max();
-}
-
namespace content {
namespace internal {
@@ -47,7 +42,7 @@ class TaskQueue : public base::SingleThreadTaskRunner {
void SetAutoPump(bool auto_pump);
void PumpQueue();
- bool UpdateWorkQueue(base::TimeTicks* next_pending_delayed_task);
+ bool UpdateWorkQueue();
base::PendingTask TakeTaskFromWorkQueue();
void WillDeleteTaskQueueManager();
@@ -81,9 +76,6 @@ class TaskQueue : public base::SingleThreadTaskRunner {
base::TaskQueue incoming_queue_;
bool auto_pump_;
const char* name_;
- std::priority_queue<base::TimeTicks,
- std::vector<base::TimeTicks>,
- std::greater<base::TimeTicks>> delayed_task_run_times_;
base::TaskQueue work_queue_;
@@ -123,8 +115,6 @@ bool TaskQueue::PostDelayedTaskImpl(const tracked_objects::Location& from_here,
task_queue_manager_->DidQueueTask(&pending_task);
if (delay > base::TimeDelta()) {
- pending_task.delayed_run_time = task_queue_manager_->Now() + delay;
- delayed_task_run_times_.push(pending_task.delayed_run_time);
return task_queue_manager_->PostDelayedTask(
from_here, Bind(&TaskQueue::EnqueueTask, this, pending_task), delay);
}
@@ -142,16 +132,12 @@ bool TaskQueue::IsQueueEmpty() const {
}
}
-bool TaskQueue::UpdateWorkQueue(base::TimeTicks* next_pending_delayed_task) {
+bool TaskQueue::UpdateWorkQueue() {
if (!work_queue_.empty())
return true;
{
base::AutoLock lock(lock_);
- if (!delayed_task_run_times_.empty()) {
- *next_pending_delayed_task =
- std::min(*next_pending_delayed_task, delayed_task_run_times_.top());
- }
if (!auto_pump_ || incoming_queue_.empty())
return false;
work_queue_.Swap(&incoming_queue_);
@@ -186,14 +172,6 @@ void TaskQueue::EnqueueTaskLocked(const base::PendingTask& pending_task) {
if (auto_pump_ && incoming_queue_.empty())
task_queue_manager_->MaybePostDoWorkOnMainRunner();
incoming_queue_.push(pending_task);
-
- if (!pending_task.delayed_run_time.is_null()) {
- // Update the time of the next pending delayed task.
- while (!delayed_task_run_times_.empty() &&
- delayed_task_run_times_.top() <= pending_task.delayed_run_time) {
- delayed_task_run_times_.pop();
- }
- }
}
void TaskQueue::SetAutoPump(bool auto_pump) {
@@ -269,8 +247,6 @@ TaskQueueManager::TaskQueueManager(
: main_task_runner_(main_task_runner),
selector_(selector),
pending_dowork_count_(0),
- work_batch_size_(1),
- time_source_(nullptr),
weak_factory_(this) {
DCHECK(main_task_runner->RunsTasksOnCurrentThread());
TRACE_EVENT_OBJECT_CREATED_WITH_ID(
@@ -325,15 +301,14 @@ void TaskQueueManager::PumpQueue(size_t queue_index) {
queue->PumpQueue();
}
-bool TaskQueueManager::UpdateWorkQueues(
- base::TimeTicks* next_pending_delayed_task) {
+bool TaskQueueManager::UpdateWorkQueues() {
// TODO(skyostil): This is not efficient when the number of queues grows very
// large due to the number of locks taken. Consider optimizing when we get
// there.
main_thread_checker_.CalledOnValidThread();
bool has_work = false;
for (auto& queue : queues_)
- has_work |= queue->UpdateWorkQueue(next_pending_delayed_task);
+ has_work |= queue->UpdateWorkQueue();
return has_work;
}
@@ -359,26 +334,14 @@ void TaskQueueManager::DoWork(bool posted_from_main_thread) {
DCHECK_GE(pending_dowork_count_, 0);
}
main_thread_checker_.CalledOnValidThread();
+ if (!UpdateWorkQueues())
+ return;
- base::TimeTicks next_pending_delayed_task(
- base::TimeTicks::FromInternalValue(kMaxTimeTicks));
- for (int i = 0; i < work_batch_size_; i++) {
- if (!UpdateWorkQueues(&next_pending_delayed_task))
- return;
-
- // Interrupt the work batch if we should run the next delayed task.
- if (i > 0 && next_pending_delayed_task.ToInternalValue() != kMaxTimeTicks &&
- Now() >= next_pending_delayed_task)
- return;
-
- size_t queue_index;
- if (!SelectWorkQueueToService(&queue_index))
- return;
- // Note that this function won't post another call to DoWork if one is
- // already pending, so it is safe to call it in a loop.
- MaybePostDoWorkOnMainRunner();
- ProcessTaskFromWorkQueue(queue_index);
- }
+ size_t queue_index;
+ if (!SelectWorkQueueToService(&queue_index))
+ return;
+ MaybePostDoWorkOnMainRunner();
+ ProcessTaskFromWorkQueue(queue_index);
}
bool TaskQueueManager::SelectWorkQueueToService(size_t* out_queue_index) {
@@ -427,22 +390,6 @@ void TaskQueueManager::SetQueueName(size_t queue_index, const char* name) {
queue->set_name(name);
}
-void TaskQueueManager::SetWorkBatchSize(int work_batch_size) {
- main_thread_checker_.CalledOnValidThread();
- DCHECK_GE(work_batch_size, 1);
- work_batch_size_ = work_batch_size;
-}
-
-void TaskQueueManager::SetTimeSourceForTesting(
- scoped_refptr<cc::TestNowSource> time_source) {
- main_thread_checker_.CalledOnValidThread();
- time_source_ = time_source;
-}
-
-base::TimeTicks TaskQueueManager::Now() const {
- return UNLIKELY(time_source_) ? time_source_->Now() : base::TimeTicks::Now();
-}
-
scoped_refptr<base::debug::ConvertableToTraceFormat>
TaskQueueManager::AsValueWithSelectorResult(bool should_run,
size_t selected_queue) const {
« no previous file with comments | « content/renderer/scheduler/task_queue_manager.h ('k') | content/renderer/scheduler/task_queue_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698