OLD | NEW |
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 return; | 61 return; |
62 // Set the start time before starting the task. Otherwise if the task | 62 // Set the start time before starting the task. Otherwise if the task |
63 // finishes quickly and deletes the Task object, setting start_time_ | 63 // finishes quickly and deletes the Task object, setting start_time_ |
64 // will crash. | 64 // will crash. |
65 start_time_ = CurrentTime(); | 65 start_time_ = CurrentTime(); |
66 GetRunner()->StartTask(this); | 66 GetRunner()->StartTask(this); |
67 } | 67 } |
68 | 68 |
69 void Task::Step() { | 69 void Task::Step() { |
70 if (done_) { | 70 if (done_) { |
71 #ifdef _DEBUG | 71 #if !defined(NDEBUG) |
72 // we do not know how !blocked_ happens when done_ - should be impossible. | 72 // we do not know how !blocked_ happens when done_ - should be impossible. |
73 // But it causes problems, so in retail build, we force blocked_, and | 73 // But it causes problems, so in retail build, we force blocked_, and |
74 // under debug we assert. | 74 // under debug we assert. |
75 ASSERT(blocked_); | 75 ASSERT(blocked_); |
76 #else | 76 #else |
77 blocked_ = true; | 77 blocked_ = true; |
78 #endif | 78 #endif |
79 return; | 79 return; |
80 } | 80 } |
81 | 81 |
82 // Async Error() was called | 82 // Async Error() was called |
83 if (error_) { | 83 if (error_) { |
84 done_ = true; | 84 done_ = true; |
85 state_ = STATE_ERROR; | 85 state_ = STATE_ERROR; |
86 blocked_ = true; | 86 blocked_ = true; |
87 // obsolete - an errored task is not considered done now | 87 // obsolete - an errored task is not considered done now |
88 // SignalDone(); | 88 // SignalDone(); |
89 | 89 |
90 Stop(); | 90 Stop(); |
91 #ifdef _DEBUG | 91 #if !defined(NDEBUG) |
92 // verify that stop removed this from its parent | 92 // verify that stop removed this from its parent |
93 ASSERT(!parent()->IsChildTask(this)); | 93 ASSERT(!parent()->IsChildTask(this)); |
94 #endif | 94 #endif |
95 return; | 95 return; |
96 } | 96 } |
97 | 97 |
98 busy_ = true; | 98 busy_ = true; |
99 int new_state = Process(state_); | 99 int new_state = Process(state_); |
100 busy_ = false; | 100 busy_ = false; |
101 | 101 |
(...skipping 16 matching lines...) Expand all Loading... |
118 } else if (new_state == STATE_ERROR) { | 118 } else if (new_state == STATE_ERROR) { |
119 done_ = true; | 119 done_ = true; |
120 error_ = true; | 120 error_ = true; |
121 } | 121 } |
122 | 122 |
123 if (done_) { | 123 if (done_) { |
124 // obsolete - call this yourself | 124 // obsolete - call this yourself |
125 // SignalDone(); | 125 // SignalDone(); |
126 | 126 |
127 Stop(); | 127 Stop(); |
128 #if _DEBUG | 128 #if !defined(NDEBUG) |
129 // verify that stop removed this from its parent | 129 // verify that stop removed this from its parent |
130 ASSERT(!parent()->IsChildTask(this)); | 130 ASSERT(!parent()->IsChildTask(this)); |
131 #endif | 131 #endif |
132 blocked_ = true; | 132 blocked_ = true; |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 void Task::Abort(bool nowake) { | 136 void Task::Abort(bool nowake) { |
137 // Why only check for done_ (instead of "aborted_ || done_")? | 137 // Why only check for done_ (instead of "aborted_ || done_")? |
138 // | 138 // |
139 // If aborted_ && !done_, it means the logic for aborting still | 139 // If aborted_ && !done_, it means the logic for aborting still |
140 // needs to be executed (because busy_ must have been true when | 140 // needs to be executed (because busy_ must have been true when |
141 // Abort() was previously called). | 141 // Abort() was previously called). |
142 if (done_) | 142 if (done_) |
143 return; | 143 return; |
144 aborted_ = true; | 144 aborted_ = true; |
145 if (!busy_) { | 145 if (!busy_) { |
146 done_ = true; | 146 done_ = true; |
147 blocked_ = true; | 147 blocked_ = true; |
148 error_ = true; | 148 error_ = true; |
149 | 149 |
150 // "done_" is set before calling "Stop()" to ensure that this code | 150 // "done_" is set before calling "Stop()" to ensure that this code |
151 // doesn't execute more than once (recursively) for the same task. | 151 // doesn't execute more than once (recursively) for the same task. |
152 Stop(); | 152 Stop(); |
153 #ifdef _DEBUG | 153 #if !defined(NDEBUG) |
154 // verify that stop removed this from its parent | 154 // verify that stop removed this from its parent |
155 ASSERT(!parent()->IsChildTask(this)); | 155 ASSERT(!parent()->IsChildTask(this)); |
156 #endif | 156 #endif |
157 if (!nowake) { | 157 if (!nowake) { |
158 // WakeTasks to self-delete. | 158 // WakeTasks to self-delete. |
159 // Don't call Wake() because it is a no-op after "done_" is set. | 159 // Don't call Wake() because it is a no-op after "done_" is set. |
160 // Even if Wake() did run, it clears "blocked_" which isn't desireable. | 160 // Even if Wake() did run, it clears "blocked_" which isn't desireable. |
161 GetRunner()->WakeTasks(); | 161 GetRunner()->WakeTasks(); |
162 } | 162 } |
163 } | 163 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 ResetTimeout(); | 272 ResetTimeout(); |
273 } | 273 } |
274 } | 274 } |
275 | 275 |
276 int Task::OnTimeout() { | 276 int Task::OnTimeout() { |
277 // by default, we are finished after timing out | 277 // by default, we are finished after timing out |
278 return STATE_DONE; | 278 return STATE_DONE; |
279 } | 279 } |
280 | 280 |
281 } // namespace rtc | 281 } // namespace rtc |
OLD | NEW |