OLD | NEW |
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 #if _MSC_VER >= 1700 | |
12 // This a temporary fix for compiling on VS2012. http://crbug.com/154744 | |
13 PendingTask::PendingTask() : sequence_num(-1), nestable(false) { | |
14 } | |
15 #endif | |
16 | |
17 PendingTask::PendingTask(const tracked_objects::Location& posted_from, | 11 PendingTask::PendingTask(const tracked_objects::Location& posted_from, |
18 const base::Closure& task) | 12 const base::Closure& task) |
19 : base::TrackingInfo(posted_from, TimeTicks()), | 13 : base::TrackingInfo(posted_from, TimeTicks()), |
20 task(task), | 14 task(task), |
21 posted_from(posted_from), | 15 posted_from(posted_from), |
22 sequence_num(0), | 16 sequence_num(0), |
23 nestable(true) { | 17 nestable(true), |
| 18 is_high_res(false) { |
24 } | 19 } |
25 | 20 |
26 PendingTask::PendingTask(const tracked_objects::Location& posted_from, | 21 PendingTask::PendingTask(const tracked_objects::Location& posted_from, |
27 const base::Closure& task, | 22 const base::Closure& task, |
28 TimeTicks delayed_run_time, | 23 TimeTicks delayed_run_time, |
29 bool nestable) | 24 bool nestable) |
30 : base::TrackingInfo(posted_from, delayed_run_time), | 25 : base::TrackingInfo(posted_from, delayed_run_time), |
31 task(task), | 26 task(task), |
32 posted_from(posted_from), | 27 posted_from(posted_from), |
33 sequence_num(0), | 28 sequence_num(0), |
34 nestable(nestable) { | 29 nestable(nestable), |
| 30 is_high_res(false) { |
35 } | 31 } |
36 | 32 |
37 PendingTask::~PendingTask() { | 33 PendingTask::~PendingTask() { |
38 } | 34 } |
39 | 35 |
40 bool PendingTask::operator<(const PendingTask& other) const { | 36 bool PendingTask::operator<(const PendingTask& other) const { |
41 // Since the top of a priority queue is defined as the "greatest" element, we | 37 // Since the top of a priority queue is defined as the "greatest" element, we |
42 // need to invert the comparison here. We want the smaller time to be at the | 38 // need to invert the comparison here. We want the smaller time to be at the |
43 // top of the heap. | 39 // top of the heap. |
44 | 40 |
45 if (delayed_run_time < other.delayed_run_time) | 41 if (delayed_run_time < other.delayed_run_time) |
46 return false; | 42 return false; |
47 | 43 |
48 if (delayed_run_time > other.delayed_run_time) | 44 if (delayed_run_time > other.delayed_run_time) |
49 return true; | 45 return true; |
50 | 46 |
51 // If the times happen to match, then we use the sequence number to decide. | 47 // If the times happen to match, then we use the sequence number to decide. |
52 // Compare the difference to support integer roll-over. | 48 // Compare the difference to support integer roll-over. |
53 return (sequence_num - other.sequence_num) > 0; | 49 return (sequence_num - other.sequence_num) > 0; |
54 } | 50 } |
55 | 51 |
56 void TaskQueue::Swap(TaskQueue* queue) { | 52 void TaskQueue::Swap(TaskQueue* queue) { |
57 c.swap(queue->c); // Calls std::deque::swap. | 53 c.swap(queue->c); // Calls std::deque::swap. |
58 } | 54 } |
59 | 55 |
60 } // namespace base | 56 } // namespace base |
OLD | NEW |