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

Side by Side Diff: base/task_scheduler/delayed_task_manager.cc

Issue 1906083002: TaskScheduler: Remove base/task_scheduler/utils.h/.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sched_2_stack
Patch Set: typos Created 4 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/task_scheduler/delayed_task_manager.h" 5 #include "base/task_scheduler/delayed_task_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/task_scheduler/scheduler_task_executor.h" 10 #include "base/task_scheduler/scheduler_thread_pool.h"
11 11
12 namespace base { 12 namespace base {
13 namespace internal { 13 namespace internal {
14 14
15 struct DelayedTaskManager::DelayedTask { 15 struct DelayedTaskManager::DelayedTask {
16 DelayedTask(std::unique_ptr<Task> task, 16 DelayedTask(std::unique_ptr<Task> task,
17 scoped_refptr<Sequence> sequence, 17 scoped_refptr<Sequence> sequence,
18 SchedulerTaskExecutor* executor, 18 SchedulerThreadPool* thread_pool,
19 uint64_t index) 19 uint64_t index)
20 : task(std::move(task)), 20 : task(std::move(task)),
21 sequence(std::move(sequence)), 21 sequence(std::move(sequence)),
22 executor(executor), 22 thread_pool(thread_pool),
23 index(index) {} 23 index(index) {}
24 24
25 DelayedTask(DelayedTask&& other) = default; 25 DelayedTask(DelayedTask&& other) = default;
26 26
27 ~DelayedTask() = default; 27 ~DelayedTask() = default;
28 28
29 DelayedTask& operator=(DelayedTask&& other) = default; 29 DelayedTask& operator=(DelayedTask&& other) = default;
30 30
31 // |task| will be posted to |executor| as part of |sequence| when it becomes 31 // |task| will be posted to |thread_pool| as part of |sequence| when it
32 // ripe for execution. 32 // becomes ripe for execution.
33 std::unique_ptr<Task> task; 33 std::unique_ptr<Task> task;
34 scoped_refptr<Sequence> sequence; 34 scoped_refptr<Sequence> sequence;
35 SchedulerTaskExecutor* executor; 35 SchedulerThreadPool* thread_pool;
36 36
37 // Ensures that tasks that have the same |delayed_run_time| are sorted 37 // Ensures that tasks that have the same |delayed_run_time| are sorted
38 // according to the order in which they were added to the DelayedTaskManager. 38 // according to the order in which they were added to the DelayedTaskManager.
39 uint64_t index; 39 uint64_t index;
40 40
41 private: 41 private:
42 DISALLOW_COPY_AND_ASSIGN(DelayedTask); 42 DISALLOW_COPY_AND_ASSIGN(DelayedTask);
43 }; 43 };
44 44
45 DelayedTaskManager::DelayedTaskManager( 45 DelayedTaskManager::DelayedTaskManager(
46 const Closure& on_delayed_run_time_updated) 46 const Closure& on_delayed_run_time_updated)
47 : on_delayed_run_time_updated_(on_delayed_run_time_updated) { 47 : on_delayed_run_time_updated_(on_delayed_run_time_updated) {
48 DCHECK(!on_delayed_run_time_updated_.is_null()); 48 DCHECK(!on_delayed_run_time_updated_.is_null());
49 } 49 }
50 50
51 DelayedTaskManager::~DelayedTaskManager() = default; 51 DelayedTaskManager::~DelayedTaskManager() = default;
52 52
53 void DelayedTaskManager::AddDelayedTask(std::unique_ptr<Task> task, 53 void DelayedTaskManager::AddDelayedTask(std::unique_ptr<Task> task,
54 scoped_refptr<Sequence> sequence, 54 scoped_refptr<Sequence> sequence,
55 SchedulerTaskExecutor* executor) { 55 SchedulerThreadPool* thread_pool) {
56 DCHECK(task); 56 DCHECK(task);
57 DCHECK(sequence); 57 DCHECK(sequence);
58 DCHECK(executor); 58 DCHECK(thread_pool);
59 59
60 const TimeTicks new_task_delayed_run_time = task->delayed_run_time; 60 const TimeTicks new_task_delayed_run_time = task->delayed_run_time;
61 TimeTicks current_delayed_run_time; 61 TimeTicks current_delayed_run_time;
62 62
63 { 63 {
64 AutoSchedulerLock auto_lock(lock_); 64 AutoSchedulerLock auto_lock(lock_);
65 65
66 if (!delayed_tasks_.empty()) 66 if (!delayed_tasks_.empty())
67 current_delayed_run_time = delayed_tasks_.top().task->delayed_run_time; 67 current_delayed_run_time = delayed_tasks_.top().task->delayed_run_time;
68 68
69 delayed_tasks_.emplace(std::move(task), std::move(sequence), executor, 69 delayed_tasks_.emplace(std::move(task), std::move(sequence), thread_pool,
70 ++delayed_task_index_); 70 ++delayed_task_index_);
71 } 71 }
72 72
73 if (current_delayed_run_time.is_null() || 73 if (current_delayed_run_time.is_null() ||
74 new_task_delayed_run_time < current_delayed_run_time) { 74 new_task_delayed_run_time < current_delayed_run_time) {
75 on_delayed_run_time_updated_.Run(); 75 on_delayed_run_time_updated_.Run();
76 } 76 }
77 } 77 }
78 78
79 void DelayedTaskManager::PostReadyTasks() { 79 void DelayedTaskManager::PostReadyTasks() {
(...skipping 12 matching lines...) Expand all
92 // the task from |delayed_tasks_|. See DelayedTaskComparator::operator() 92 // the task from |delayed_tasks_|. See DelayedTaskComparator::operator()
93 // for minor debug-check implications. 93 // for minor debug-check implications.
94 ready_tasks.push_back( 94 ready_tasks.push_back(
95 std::move(const_cast<DelayedTask&>(delayed_tasks_.top()))); 95 std::move(const_cast<DelayedTask&>(delayed_tasks_.top())));
96 delayed_tasks_.pop(); 96 delayed_tasks_.pop();
97 } 97 }
98 } 98 }
99 99
100 // Post delayed tasks that are ready for execution. 100 // Post delayed tasks that are ready for execution.
101 for (auto& delayed_task : ready_tasks) { 101 for (auto& delayed_task : ready_tasks) {
102 delayed_task.executor->PostTaskWithSequence( 102 delayed_task.thread_pool->PostTaskWithSequenceNow(
103 std::move(delayed_task.task), std::move(delayed_task.sequence)); 103 std::move(delayed_task.task), std::move(delayed_task.sequence));
104 } 104 }
105 } 105 }
106 106
107 TimeTicks DelayedTaskManager::GetDelayedRunTime() const { 107 TimeTicks DelayedTaskManager::GetDelayedRunTime() const {
108 AutoSchedulerLock auto_lock(lock_); 108 AutoSchedulerLock auto_lock(lock_);
109 109
110 if (delayed_tasks_.empty()) 110 if (delayed_tasks_.empty())
111 return TimeTicks(); 111 return TimeTicks();
112 112
(...skipping 26 matching lines...) Expand all
139 return false; 139 return false;
140 return left.index > right.index; 140 return left.index > right.index;
141 } 141 }
142 142
143 TimeTicks DelayedTaskManager::Now() const { 143 TimeTicks DelayedTaskManager::Now() const {
144 return TimeTicks::Now(); 144 return TimeTicks::Now();
145 } 145 }
146 146
147 } // namespace internal 147 } // namespace internal
148 } // namespace base 148 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698