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

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

Issue 878033005: Move 'super-long post delayed task' warning to IncomingTaskQueue. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/message_loop/message_loop.cc » ('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>
8
7 #include "base/location.h" 9 #include "base/location.h"
8 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
10 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
11 #include "base/time/time.h" 13 #include "base/time/time.h"
12 14
13 namespace base { 15 namespace base {
14 namespace internal { 16 namespace internal {
15 17
16 namespace { 18 namespace {
17 19
20 // Delays larger than this many microseconds are often bogus, and a warning
21 // should be emitted in debug builds to warn developers.
22 // http://crbug.com/450045
23 const int kTaskDelayWarningThresholdInMicroseconds =
24 std::numeric_limits<int>::max() / 2; // A little less than 18 minutes.
25
18 // Returns true if MessagePump::ScheduleWork() must be called one 26 // Returns true if MessagePump::ScheduleWork() must be called one
19 // time for every task that is added to the MessageLoop incoming queue. 27 // time for every task that is added to the MessageLoop incoming queue.
20 bool AlwaysNotifyPump(MessageLoop::Type type) { 28 bool AlwaysNotifyPump(MessageLoop::Type type) {
21 #if defined(OS_ANDROID) 29 #if defined(OS_ANDROID)
22 // The Android UI message loop needs to get notified each time a task is 30 // The Android UI message loop needs to get notified each time a task is
23 // added 31 // added
24 // to the incoming queue. 32 // to the incoming queue.
25 return type == MessageLoop::TYPE_UI || type == MessageLoop::TYPE_JAVA; 33 return type == MessageLoop::TYPE_UI || type == MessageLoop::TYPE_JAVA;
26 #else 34 #else
27 return false; 35 return false;
28 #endif 36 #endif
29 } 37 }
30 38
31 } // namespace 39 } // namespace
32 40
33 IncomingTaskQueue::IncomingTaskQueue(MessageLoop* message_loop) 41 IncomingTaskQueue::IncomingTaskQueue(MessageLoop* message_loop)
34 : high_res_task_count_(0), 42 : high_res_task_count_(0),
35 message_loop_(message_loop), 43 message_loop_(message_loop),
36 next_sequence_num_(0), 44 next_sequence_num_(0),
37 message_loop_scheduled_(false), 45 message_loop_scheduled_(false),
38 always_schedule_work_(AlwaysNotifyPump(message_loop_->type())) { 46 always_schedule_work_(AlwaysNotifyPump(message_loop_->type())) {
39 } 47 }
40 48
41 bool IncomingTaskQueue::AddToIncomingQueue( 49 bool IncomingTaskQueue::AddToIncomingQueue(
42 const tracked_objects::Location& from_here, 50 const tracked_objects::Location& from_here,
43 const Closure& task, 51 const Closure& task,
44 TimeDelta delay, 52 TimeDelta delay,
45 bool nestable) { 53 bool nestable) {
54 DLOG_IF(WARNING,
55 delay.InMicroseconds() > kTaskDelayWarningThresholdInMicroseconds)
56 << "Requesting super-long task delay period of " << delay.InMicroseconds()
57 << " usec from here: " << from_here.ToString();
58
46 AutoLock locked(incoming_queue_lock_); 59 AutoLock locked(incoming_queue_lock_);
47 PendingTask pending_task( 60 PendingTask pending_task(
48 from_here, task, CalculateDelayedRuntime(delay), nestable); 61 from_here, task, CalculateDelayedRuntime(delay), nestable);
49 #if defined(OS_WIN) 62 #if defined(OS_WIN)
50 // We consider the task needs a high resolution timer if the delay is 63 // We consider the task needs a high resolution timer if the delay is
51 // more than 0 and less than 32ms. This caps the relative error to 64 // more than 0 and less than 32ms. This caps the relative error to
52 // less than 50% : a 33ms wait can wake at 48ms since the default 65 // less than 50% : a 33ms wait can wake at 48ms since the default
53 // resolution on Windows is between 10 and 15ms. 66 // resolution on Windows is between 10 and 15ms.
54 if (delay > TimeDelta() && 67 if (delay > TimeDelta() &&
55 delay.InMilliseconds() < (2 * Time::kMinLowResolutionThresholdMs)) { 68 delay.InMilliseconds() < (2 * Time::kMinLowResolutionThresholdMs)) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // reload from the incoming queue before waiting again so we clear this flag 156 // reload from the incoming queue before waiting again so we clear this flag
144 // in ReloadWorkQueue(). 157 // in ReloadWorkQueue().
145 message_loop_scheduled_ = true; 158 message_loop_scheduled_ = true;
146 } 159 }
147 160
148 return true; 161 return true;
149 } 162 }
150 163
151 } // namespace internal 164 } // namespace internal
152 } // namespace base 165 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/message_loop/message_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698