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

Side by Side Diff: base/pending_task.cc

Issue 1886453003: Make PendingTask move-only and pass it by value on retaining params (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mac test fix Created 4 years, 5 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/pending_task.h ('k') | base/threading/worker_pool_posix.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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/pending_task.h" 5 #include "base/pending_task.h"
6 6
7 #include "base/tracked_objects.h" 7 #include "base/tracked_objects.h"
8 8
9 namespace base { 9 namespace base {
10 10
11 PendingTask::PendingTask(const tracked_objects::Location& posted_from, 11 PendingTask::PendingTask(const tracked_objects::Location& posted_from,
12 const base::Closure& task) 12 base::Closure task)
13 : base::TrackingInfo(posted_from, TimeTicks()), 13 : base::TrackingInfo(posted_from, TimeTicks()),
14 task(task), 14 task(std::move(task)),
15 posted_from(posted_from), 15 posted_from(posted_from),
16 sequence_num(0), 16 sequence_num(0),
17 nestable(true), 17 nestable(true),
18 is_high_res(false) { 18 is_high_res(false) {
19 } 19 }
20 20
21 PendingTask::PendingTask(const tracked_objects::Location& posted_from, 21 PendingTask::PendingTask(const tracked_objects::Location& posted_from,
22 const base::Closure& task, 22 base::Closure task,
23 TimeTicks delayed_run_time, 23 TimeTicks delayed_run_time,
24 bool nestable) 24 bool nestable)
25 : base::TrackingInfo(posted_from, delayed_run_time), 25 : base::TrackingInfo(posted_from, delayed_run_time),
26 task(task), 26 task(std::move(task)),
27 posted_from(posted_from), 27 posted_from(posted_from),
28 sequence_num(0), 28 sequence_num(0),
29 nestable(nestable), 29 nestable(nestable),
30 is_high_res(false) { 30 is_high_res(false) {
31 } 31 }
32 32
33 PendingTask::PendingTask(const PendingTask& other) = default; 33 PendingTask::PendingTask(PendingTask&& other) = default;
34 34
35 PendingTask::~PendingTask() { 35 PendingTask::~PendingTask() {
36 } 36 }
37 37
38 PendingTask& PendingTask::operator=(PendingTask&& other) = default;
39
38 bool PendingTask::operator<(const PendingTask& other) const { 40 bool PendingTask::operator<(const PendingTask& other) const {
39 // Since the top of a priority queue is defined as the "greatest" element, we 41 // Since the top of a priority queue is defined as the "greatest" element, we
40 // need to invert the comparison here. We want the smaller time to be at the 42 // need to invert the comparison here. We want the smaller time to be at the
41 // top of the heap. 43 // top of the heap.
42 44
43 if (delayed_run_time < other.delayed_run_time) 45 if (delayed_run_time < other.delayed_run_time)
44 return false; 46 return false;
45 47
46 if (delayed_run_time > other.delayed_run_time) 48 if (delayed_run_time > other.delayed_run_time)
47 return true; 49 return true;
48 50
49 // If the times happen to match, then we use the sequence number to decide. 51 // If the times happen to match, then we use the sequence number to decide.
50 // Compare the difference to support integer roll-over. 52 // Compare the difference to support integer roll-over.
51 return (sequence_num - other.sequence_num) > 0; 53 return (sequence_num - other.sequence_num) > 0;
52 } 54 }
53 55
54 } // namespace base 56 } // namespace base
OLDNEW
« no previous file with comments | « base/pending_task.h ('k') | base/threading/worker_pool_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698