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

Side by Side Diff: base/message_loop/incoming_task_queue.cc

Issue 1140363002: Revert of Reland: Lazily initialize MessageLoop for faster thread startup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « base/message_loop/incoming_task_queue.h ('k') | base/message_loop/message_loop.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "base/message_loop/incoming_task_queue.h" 5 #include "base/message_loop/incoming_task_queue.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 26 matching lines...) Expand all
37 #endif 37 #endif
38 } 38 }
39 39
40 } // namespace 40 } // namespace
41 41
42 IncomingTaskQueue::IncomingTaskQueue(MessageLoop* message_loop) 42 IncomingTaskQueue::IncomingTaskQueue(MessageLoop* message_loop)
43 : high_res_task_count_(0), 43 : high_res_task_count_(0),
44 message_loop_(message_loop), 44 message_loop_(message_loop),
45 next_sequence_num_(0), 45 next_sequence_num_(0),
46 message_loop_scheduled_(false), 46 message_loop_scheduled_(false),
47 always_schedule_work_(AlwaysNotifyPump(message_loop_->type())), 47 always_schedule_work_(AlwaysNotifyPump(message_loop_->type())) {
48 is_ready_for_scheduling_(false) {
49 } 48 }
50 49
51 bool IncomingTaskQueue::AddToIncomingQueue( 50 bool IncomingTaskQueue::AddToIncomingQueue(
52 const tracked_objects::Location& from_here, 51 const tracked_objects::Location& from_here,
53 const Closure& task, 52 const Closure& task,
54 TimeDelta delay, 53 TimeDelta delay,
55 bool nestable) { 54 bool nestable) {
56 DLOG_IF(WARNING, 55 DLOG_IF(WARNING,
57 delay.InSeconds() > kTaskDelayWarningThresholdInSeconds) 56 delay.InSeconds() > kTaskDelayWarningThresholdInSeconds)
58 << "Requesting super-long task delay period of " << delay.InSeconds() 57 << "Requesting super-long task delay period of " << delay.InSeconds()
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 int high_res_tasks = high_res_task_count_; 102 int high_res_tasks = high_res_task_count_;
104 high_res_task_count_ = 0; 103 high_res_task_count_ = 0;
105 return high_res_tasks; 104 return high_res_tasks;
106 } 105 }
107 106
108 void IncomingTaskQueue::WillDestroyCurrentMessageLoop() { 107 void IncomingTaskQueue::WillDestroyCurrentMessageLoop() {
109 AutoLock lock(incoming_queue_lock_); 108 AutoLock lock(incoming_queue_lock_);
110 message_loop_ = NULL; 109 message_loop_ = NULL;
111 } 110 }
112 111
113 void IncomingTaskQueue::StartScheduling() {
114 AutoLock lock(incoming_queue_lock_);
115 DCHECK(!is_ready_for_scheduling_);
116 DCHECK(!message_loop_scheduled_);
117 is_ready_for_scheduling_ = true;
118 if (!incoming_queue_.empty())
119 ScheduleWork();
120 }
121
122 IncomingTaskQueue::~IncomingTaskQueue() { 112 IncomingTaskQueue::~IncomingTaskQueue() {
123 // Verify that WillDestroyCurrentMessageLoop() has been called. 113 // Verify that WillDestroyCurrentMessageLoop() has been called.
124 DCHECK(!message_loop_); 114 DCHECK(!message_loop_);
125 } 115 }
126 116
127 TimeTicks IncomingTaskQueue::CalculateDelayedRuntime(TimeDelta delay) { 117 TimeTicks IncomingTaskQueue::CalculateDelayedRuntime(TimeDelta delay) {
128 TimeTicks delayed_run_time; 118 TimeTicks delayed_run_time;
129 if (delay > TimeDelta()) 119 if (delay > TimeDelta())
130 delayed_run_time = TimeTicks::Now() + delay; 120 delayed_run_time = TimeTicks::Now() + delay;
131 else 121 else
(...skipping 19 matching lines...) Expand all
151 // delayed_run_time value) and for identifying the task in about:tracing. 141 // delayed_run_time value) and for identifying the task in about:tracing.
152 pending_task->sequence_num = next_sequence_num_++; 142 pending_task->sequence_num = next_sequence_num_++;
153 143
154 message_loop_->task_annotator()->DidQueueTask("MessageLoop::PostTask", 144 message_loop_->task_annotator()->DidQueueTask("MessageLoop::PostTask",
155 *pending_task); 145 *pending_task);
156 146
157 bool was_empty = incoming_queue_.empty(); 147 bool was_empty = incoming_queue_.empty();
158 incoming_queue_.push(*pending_task); 148 incoming_queue_.push(*pending_task);
159 pending_task->task.Reset(); 149 pending_task->task.Reset();
160 150
161 if (is_ready_for_scheduling_ && 151 if (always_schedule_work_ || (!message_loop_scheduled_ && was_empty)) {
162 (always_schedule_work_ || (!message_loop_scheduled_ && was_empty))) { 152 // Wake up the message loop.
163 ScheduleWork(); 153 message_loop_->ScheduleWork();
154 // After we've scheduled the message loop, we do not need to do so again
155 // until we know it has processed all of the work in our queue and is
156 // waiting for more work again. The message loop will always attempt to
157 // reload from the incoming queue before waiting again so we clear this flag
158 // in ReloadWorkQueue().
159 message_loop_scheduled_ = true;
164 } 160 }
165 161
166 return true; 162 return true;
167 } 163 }
168 164
169 void IncomingTaskQueue::ScheduleWork() {
170 DCHECK(is_ready_for_scheduling_);
171 // Wake up the message loop.
172 message_loop_->ScheduleWork();
173 // After we've scheduled the message loop, we do not need to do so again
174 // until we know it has processed all of the work in our queue and is
175 // waiting for more work again. The message loop will always attempt to
176 // reload from the incoming queue before waiting again so we clear this flag
177 // in ReloadWorkQueue().
178 message_loop_scheduled_ = true;
179 }
180
181 } // namespace internal 165 } // namespace internal
182 } // namespace base 166 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/incoming_task_queue.h ('k') | base/message_loop/message_loop.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698