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

Side by Side Diff: webrtc/base/taskrunner.cc

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 years, 2 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 | « webrtc/base/taskrunner.h ('k') | webrtc/base/testclient.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 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // "ChildSet copy" in TaskParent::AbortAllChildren. 57 // "ChildSet copy" in TaskParent::AbortAllChildren.
58 // Subsequent use of those task may cause data corruption or crashes. 58 // Subsequent use of those task may cause data corruption or crashes.
59 ASSERT(!abort_count_); 59 ASSERT(!abort_count_);
60 // Running continues until all tasks are Blocked (ok for a small # of tasks) 60 // Running continues until all tasks are Blocked (ok for a small # of tasks)
61 if (tasks_running_) { 61 if (tasks_running_) {
62 return; // don't reenter 62 return; // don't reenter
63 } 63 }
64 64
65 tasks_running_ = true; 65 tasks_running_ = true;
66 66
67 int64 previous_timeout_time = next_task_timeout(); 67 int64_t previous_timeout_time = next_task_timeout();
68 68
69 int did_run = true; 69 int did_run = true;
70 while (did_run) { 70 while (did_run) {
71 did_run = false; 71 did_run = false;
72 // use indexing instead of iterators because tasks_ may grow 72 // use indexing instead of iterators because tasks_ may grow
73 for (size_t i = 0; i < tasks_.size(); ++i) { 73 for (size_t i = 0; i < tasks_.size(); ++i) {
74 while (!tasks_[i]->Blocked()) { 74 while (!tasks_[i]->Blocked()) {
75 tasks_[i]->Step(); 75 tasks_[i]->Step();
76 did_run = true; 76 did_run = true;
77 } 77 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 Task* old_timeout_task = NULL; 128 Task* old_timeout_task = NULL;
129 while (next_timeout_task_ && 129 while (next_timeout_task_ &&
130 old_timeout_task != next_timeout_task_ && 130 old_timeout_task != next_timeout_task_ &&
131 next_timeout_task_->TimedOut()) { 131 next_timeout_task_->TimedOut()) {
132 old_timeout_task = next_timeout_task_; 132 old_timeout_task = next_timeout_task_;
133 next_timeout_task_->Wake(); 133 next_timeout_task_->Wake();
134 WakeTasks(); 134 WakeTasks();
135 } 135 }
136 } 136 }
137 137
138 int64 TaskRunner::next_task_timeout() const { 138 int64_t TaskRunner::next_task_timeout() const {
139 if (next_timeout_task_) { 139 if (next_timeout_task_) {
140 return next_timeout_task_->timeout_time(); 140 return next_timeout_task_->timeout_time();
141 } 141 }
142 return 0; 142 return 0;
143 } 143 }
144 144
145 // this function gets called frequently -- when each task changes 145 // this function gets called frequently -- when each task changes
146 // state to something other than DONE, ERROR or BLOCKED, it calls 146 // state to something other than DONE, ERROR or BLOCKED, it calls
147 // ResetTimeout(), which will call this function to make sure that 147 // ResetTimeout(), which will call this function to make sure that
148 // the next timeout-able task hasn't changed. The logic in this function 148 // the next timeout-able task hasn't changed. The logic in this function
149 // prevents RecalcNextTimeout() from getting called in most cases, 149 // prevents RecalcNextTimeout() from getting called in most cases,
150 // effectively making the task scheduler O-1 instead of O-N 150 // effectively making the task scheduler O-1 instead of O-N
151 151
152 void TaskRunner::UpdateTaskTimeout(Task* task, 152 void TaskRunner::UpdateTaskTimeout(Task* task,
153 int64 previous_task_timeout_time) { 153 int64_t previous_task_timeout_time) {
154 ASSERT(task != NULL); 154 ASSERT(task != NULL);
155 int64 previous_timeout_time = next_task_timeout(); 155 int64_t previous_timeout_time = next_task_timeout();
156 bool task_is_timeout_task = next_timeout_task_ != NULL && 156 bool task_is_timeout_task = next_timeout_task_ != NULL &&
157 task->unique_id() == next_timeout_task_->unique_id(); 157 task->unique_id() == next_timeout_task_->unique_id();
158 if (task_is_timeout_task) { 158 if (task_is_timeout_task) {
159 previous_timeout_time = previous_task_timeout_time; 159 previous_timeout_time = previous_task_timeout_time;
160 } 160 }
161 161
162 // if the relevant task has a timeout, then 162 // if the relevant task has a timeout, then
163 // check to see if it's closer than the current 163 // check to see if it's closer than the current
164 // "about to timeout" task 164 // "about to timeout" task
165 if (task->timeout_time()) { 165 if (task->timeout_time()) {
(...skipping 17 matching lines...) Expand all
183 } 183 }
184 } 184 }
185 185
186 void TaskRunner::RecalcNextTimeout(Task *exclude_task) { 186 void TaskRunner::RecalcNextTimeout(Task *exclude_task) {
187 // walk through all the tasks looking for the one 187 // walk through all the tasks looking for the one
188 // which satisfies the following: 188 // which satisfies the following:
189 // it's not finished already 189 // it's not finished already
190 // we're not excluding it 190 // we're not excluding it
191 // it has the closest timeout time 191 // it has the closest timeout time
192 192
193 int64 next_timeout_time = 0; 193 int64_t next_timeout_time = 0;
194 next_timeout_task_ = NULL; 194 next_timeout_task_ = NULL;
195 195
196 for (size_t i = 0; i < tasks_.size(); ++i) { 196 for (size_t i = 0; i < tasks_.size(); ++i) {
197 Task *task = tasks_[i]; 197 Task *task = tasks_[i];
198 // if the task isn't complete, and it actually has a timeout time 198 // if the task isn't complete, and it actually has a timeout time
199 if (!task->IsDone() && (task->timeout_time() > 0)) 199 if (!task->IsDone() && (task->timeout_time() > 0))
200 // if it doesn't match our "exclude" task 200 // if it doesn't match our "exclude" task
201 if (exclude_task == NULL || 201 if (exclude_task == NULL ||
202 exclude_task->unique_id() != task->unique_id()) 202 exclude_task->unique_id() != task->unique_id())
203 // if its timeout time is sooner than our current timeout time 203 // if its timeout time is sooner than our current timeout time
204 if (next_timeout_time == 0 || 204 if (next_timeout_time == 0 ||
205 task->timeout_time() <= next_timeout_time) { 205 task->timeout_time() <= next_timeout_time) {
206 // set this task as our next-to-timeout 206 // set this task as our next-to-timeout
207 next_timeout_time = task->timeout_time(); 207 next_timeout_time = task->timeout_time();
208 next_timeout_task_ = task; 208 next_timeout_task_ = task;
209 } 209 }
210 } 210 }
211 } 211 }
212 212
213 void TaskRunner::CheckForTimeoutChange(int64 previous_timeout_time) { 213 void TaskRunner::CheckForTimeoutChange(int64_t previous_timeout_time) {
214 int64 next_timeout = next_task_timeout(); 214 int64_t next_timeout = next_task_timeout();
215 bool timeout_change = (previous_timeout_time == 0 && next_timeout != 0) || 215 bool timeout_change = (previous_timeout_time == 0 && next_timeout != 0) ||
216 next_timeout < previous_timeout_time || 216 next_timeout < previous_timeout_time ||
217 (previous_timeout_time <= CurrentTime() && 217 (previous_timeout_time <= CurrentTime() &&
218 previous_timeout_time != next_timeout); 218 previous_timeout_time != next_timeout);
219 if (timeout_change) { 219 if (timeout_change) {
220 OnTimeoutChange(); 220 OnTimeoutChange();
221 } 221 }
222 } 222 }
223 223
224 } // namespace rtc 224 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/taskrunner.h ('k') | webrtc/base/testclient.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698