Chromium Code Reviews| Index: base/message_loop/message_loop.cc |
| diff --git a/base/message_loop/message_loop.cc b/base/message_loop/message_loop.cc |
| index 8e817dab8adece6ff025f277167901d6babdeab4..e783780d70b210933674fd0e42a733ce3ada2511 100644 |
| --- a/base/message_loop/message_loop.cc |
| +++ b/base/message_loop/message_loop.cc |
| @@ -127,6 +127,7 @@ MessageLoop::DestructionObserver::~DestructionObserver() { |
| MessageLoop::MessageLoop(Type type) |
| : type_(type), |
| + pending_high_res_tasks_(false), |
|
jamesr
2014/07/18 04:45:37
s/false/0/
cpu_(ooo_6.6-7.5)
2014/07/18 22:53:10
Done.
|
| nestable_tasks_allowed_(true), |
| #if defined(OS_WIN) |
| os_modal_loop_(false), |
| @@ -141,6 +142,7 @@ MessageLoop::MessageLoop(Type type) |
| MessageLoop::MessageLoop(scoped_ptr<MessagePump> pump) |
| : pump_(pump.Pass()), |
| type_(TYPE_CUSTOM), |
| + pending_high_res_tasks_(false), |
|
jamesr
2014/07/18 04:45:37
s/false/0/
cpu_(ooo_6.6-7.5)
2014/07/18 22:53:10
Done.
|
| nestable_tasks_allowed_(true), |
| #if defined(OS_WIN) |
| os_modal_loop_(false), |
| @@ -369,8 +371,8 @@ bool MessageLoop::is_running() const { |
| return run_loop_ != NULL; |
| } |
| -bool MessageLoop::IsHighResolutionTimerEnabledForTesting() { |
| - return incoming_task_queue_->IsHighResolutionTimerEnabledForTesting(); |
| +bool MessageLoop::HasHighResolutionTasks() { |
| + return incoming_task_queue_->HasHighResolutionTasks(); |
| } |
| bool MessageLoop::IsIdleForTesting() { |
| @@ -438,6 +440,11 @@ void MessageLoop::RunTask(const PendingTask& pending_task) { |
| "src_file", pending_task.posted_from.file_name(), |
| "src_func", pending_task.posted_from.function_name()); |
| + if (pending_task.is_high_res) { |
| + pending_high_res_tasks_--; |
| + CHECK(pending_high_res_tasks_ >= 0); |
| + } |
| + |
| DCHECK(nestable_tasks_allowed_); |
| // Execute the task and assume the worst: It is probably not reentrant. |
| nestable_tasks_allowed_ = false; |
| @@ -523,8 +530,10 @@ void MessageLoop::ReloadWorkQueue() { |
| // |*work_queue| by waiting until the last minute (|*work_queue| is empty) to |
| // load. That reduces the number of locks-per-task significantly when our |
| // queues get large. |
| - if (work_queue_.empty()) |
| - incoming_task_queue_->ReloadWorkQueue(&work_queue_); |
| + if (work_queue_.empty()) { |
| + pending_high_res_tasks_ += |
| + incoming_task_queue_->ReloadWorkQueue(&work_queue_); |
| + } |
| } |
| void MessageLoop::ScheduleWork(bool was_empty) { |
| @@ -632,6 +641,15 @@ bool MessageLoop::DoIdleWork() { |
| return false; |
| } |
| +void MessageLoop::UpdateTimerGranularity() { |
| +#if defined(OS_WIN) |
| + // Windows scheduler has by default ~15ms resolution. So, if we have high |
| + // resolution tasks pending we need to temporarity increase the systemwide |
| + // timer resolution to 1ms, and if we don't we need to go back to 15ms. |
| + Time::ActivateHighResolutionTimer(pending_high_res_tasks_ > 0); |
| +#endif |
| +} |
| + |
| void MessageLoop::DeleteSoonInternal(const tracked_objects::Location& from_here, |
| void(*deleter)(const void*), |
| const void* object) { |