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

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

Issue 2726523002: Pass Callback to TaskRunner by value and consume it on invocation (1) (Closed)
Patch Set: erase Closure* Created 3 years, 8 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_task_runner.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 #include <utility>
8 9
9 #include "base/location.h" 10 #include "base/location.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
12 #include "base/time/time.h" 13 #include "base/time/time.h"
13 #include "build/build_config.h" 14 #include "build/build_config.h"
14 15
15 namespace base { 16 namespace base {
16 namespace internal { 17 namespace internal {
17 18
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 : high_res_task_count_(0), 53 : high_res_task_count_(0),
53 message_loop_(message_loop), 54 message_loop_(message_loop),
54 next_sequence_num_(0), 55 next_sequence_num_(0),
55 message_loop_scheduled_(false), 56 message_loop_scheduled_(false),
56 always_schedule_work_(AlwaysNotifyPump(message_loop_->type())), 57 always_schedule_work_(AlwaysNotifyPump(message_loop_->type())),
57 is_ready_for_scheduling_(false) { 58 is_ready_for_scheduling_(false) {
58 } 59 }
59 60
60 bool IncomingTaskQueue::AddToIncomingQueue( 61 bool IncomingTaskQueue::AddToIncomingQueue(
61 const tracked_objects::Location& from_here, 62 const tracked_objects::Location& from_here,
62 const Closure& task, 63 Closure task,
63 TimeDelta delay, 64 TimeDelta delay,
64 bool nestable) { 65 bool nestable) {
65 DLOG_IF(WARNING, 66 DLOG_IF(WARNING,
66 delay.InSeconds() > kTaskDelayWarningThresholdInSeconds) 67 delay.InSeconds() > kTaskDelayWarningThresholdInSeconds)
67 << "Requesting super-long task delay period of " << delay.InSeconds() 68 << "Requesting super-long task delay period of " << delay.InSeconds()
68 << " seconds from here: " << from_here.ToString(); 69 << " seconds from here: " << from_here.ToString();
69 70
70 PendingTask pending_task(from_here, task, CalculateDelayedRuntime(delay), 71 PendingTask pending_task(from_here, std::move(task),
71 nestable); 72 CalculateDelayedRuntime(delay), nestable);
72 #if defined(OS_WIN) 73 #if defined(OS_WIN)
73 // We consider the task needs a high resolution timer if the delay is 74 // We consider the task needs a high resolution timer if the delay is
74 // more than 0 and less than 32ms. This caps the relative error to 75 // more than 0 and less than 32ms. This caps the relative error to
75 // less than 50% : a 33ms wait can wake at 48ms since the default 76 // less than 50% : a 33ms wait can wake at 48ms since the default
76 // resolution on Windows is between 10 and 15ms. 77 // resolution on Windows is between 10 and 15ms.
77 if (delay > TimeDelta() && 78 if (delay > TimeDelta() &&
78 delay.InMilliseconds() < (2 * Time::kMinLowResolutionThresholdMs)) { 79 delay.InMilliseconds() < (2 * Time::kMinLowResolutionThresholdMs)) {
79 pending_task.is_high_res = true; 80 pending_task.is_high_res = true;
80 } 81 }
81 #endif 82 #endif
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 // that wants to post a task will be blocked until this thread switches back 191 // that wants to post a task will be blocked until this thread switches back
191 // in and releases |incoming_queue_lock_|. 192 // in and releases |incoming_queue_lock_|.
192 if (schedule_work) 193 if (schedule_work)
193 message_loop_->ScheduleWork(); 194 message_loop_->ScheduleWork();
194 195
195 return true; 196 return true;
196 } 197 }
197 198
198 } // namespace internal 199 } // namespace internal
199 } // namespace base 200 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/incoming_task_queue.h ('k') | base/message_loop/message_loop_task_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698