| OLD | NEW |
| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 TimeDelta delay, | 54 TimeDelta delay, |
| 55 bool nestable) { | 55 bool nestable) { |
| 56 DLOG_IF(WARNING, | 56 DLOG_IF(WARNING, |
| 57 delay.InSeconds() > kTaskDelayWarningThresholdInSeconds) | 57 delay.InSeconds() > kTaskDelayWarningThresholdInSeconds) |
| 58 << "Requesting super-long task delay period of " << delay.InSeconds() | 58 << "Requesting super-long task delay period of " << delay.InSeconds() |
| 59 << " seconds from here: " << from_here.ToString(); | 59 << " seconds from here: " << from_here.ToString(); |
| 60 | 60 |
| 61 AutoLock locked(incoming_queue_lock_); | 61 AutoLock locked(incoming_queue_lock_); |
| 62 PendingTask pending_task( | 62 PendingTask pending_task( |
| 63 from_here, task, CalculateDelayedRuntime(delay), nestable); | 63 from_here, task, CalculateDelayedRuntime(delay), nestable); |
| 64 #if defined(OS_WIN) | |
| 65 // We consider the task needs a high resolution timer if the delay is | |
| 66 // more than 0 and less than 32ms. This caps the relative error to | |
| 67 // less than 50% : a 33ms wait can wake at 48ms since the default | |
| 68 // resolution on Windows is between 10 and 15ms. | |
| 69 if (delay > TimeDelta() && | |
| 70 delay.InMilliseconds() < (2 * Time::kMinLowResolutionThresholdMs)) { | |
| 71 ++high_res_task_count_; | |
| 72 pending_task.is_high_res = true; | |
| 73 } | |
| 74 #endif | |
| 75 return PostPendingTask(&pending_task); | 64 return PostPendingTask(&pending_task); |
| 76 } | 65 } |
| 77 | 66 |
| 78 bool IncomingTaskQueue::HasHighResolutionTasks() { | 67 bool IncomingTaskQueue::HasHighResolutionTasks() { |
| 79 AutoLock lock(incoming_queue_lock_); | 68 AutoLock lock(incoming_queue_lock_); |
| 80 return high_res_task_count_ > 0; | 69 return high_res_task_count_ > 0; |
| 81 } | 70 } |
| 82 | 71 |
| 83 bool IncomingTaskQueue::IsIdleForTesting() { | 72 bool IncomingTaskQueue::IsIdleForTesting() { |
| 84 AutoLock lock(incoming_queue_lock_); | 73 AutoLock lock(incoming_queue_lock_); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // After we've scheduled the message loop, we do not need to do so again | 162 // 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 | 163 // 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 | 164 // 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 | 165 // reload from the incoming queue before waiting again so we clear this flag |
| 177 // in ReloadWorkQueue(). | 166 // in ReloadWorkQueue(). |
| 178 message_loop_scheduled_ = true; | 167 message_loop_scheduled_ = true; |
| 179 } | 168 } |
| 180 | 169 |
| 181 } // namespace internal | 170 } // namespace internal |
| 182 } // namespace base | 171 } // namespace base |
| OLD | NEW |