OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
11 #include "webrtc/modules/utility/source/process_thread_impl.h" | 11 #include "webrtc/modules/utility/source/process_thread_impl.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/base/task_queue.h" |
14 #include "webrtc/base/timeutils.h" | 15 #include "webrtc/base/timeutils.h" |
15 #include "webrtc/modules/include/module.h" | 16 #include "webrtc/modules/include/module.h" |
16 #include "webrtc/system_wrappers/include/logging.h" | 17 #include "webrtc/system_wrappers/include/logging.h" |
17 | 18 |
18 namespace webrtc { | 19 namespace webrtc { |
19 namespace { | 20 namespace { |
20 | 21 |
21 // We use this constant internally to signal that a module has requested | 22 // We use this constant internally to signal that a module has requested |
22 // a callback right away. When this is set, no call to TimeUntilNextProcess | 23 // a callback right away. When this is set, no call to TimeUntilNextProcess |
23 // should be made, but Process() should be called directly. | 24 // should be made, but Process() should be called directly. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 { | 113 { |
113 rtc::CritScope lock(&lock_); | 114 rtc::CritScope lock(&lock_); |
114 for (ModuleCallback& m : modules_) { | 115 for (ModuleCallback& m : modules_) { |
115 if (m.module == module) | 116 if (m.module == module) |
116 m.next_callback = kCallProcessImmediately; | 117 m.next_callback = kCallProcessImmediately; |
117 } | 118 } |
118 } | 119 } |
119 wake_up_->Set(); | 120 wake_up_->Set(); |
120 } | 121 } |
121 | 122 |
122 void ProcessThreadImpl::PostTask(std::unique_ptr<ProcessTask> task) { | 123 void ProcessThreadImpl::PostTask(std::unique_ptr<rtc::QueuedTask> task) { |
123 // Allowed to be called on any thread. | 124 // Allowed to be called on any thread. |
124 { | 125 { |
125 rtc::CritScope lock(&lock_); | 126 rtc::CritScope lock(&lock_); |
126 queue_.push(task.release()); | 127 queue_.push(task.release()); |
127 } | 128 } |
128 wake_up_->Set(); | 129 wake_up_->Set(); |
129 } | 130 } |
130 | 131 |
131 void ProcessThreadImpl::RegisterModule(Module* module) { | 132 void ProcessThreadImpl::RegisterModule(Module* module) { |
132 RTC_DCHECK(thread_checker_.CalledOnValidThread()); | 133 RTC_DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 // of calculating how long we should wait, to reduce variance. | 212 // of calculating how long we should wait, to reduce variance. |
212 int64_t new_now = rtc::TimeMillis(); | 213 int64_t new_now = rtc::TimeMillis(); |
213 m.next_callback = GetNextCallbackTime(m.module, new_now); | 214 m.next_callback = GetNextCallbackTime(m.module, new_now); |
214 } | 215 } |
215 | 216 |
216 if (m.next_callback < next_checkpoint) | 217 if (m.next_callback < next_checkpoint) |
217 next_checkpoint = m.next_callback; | 218 next_checkpoint = m.next_callback; |
218 } | 219 } |
219 | 220 |
220 while (!queue_.empty()) { | 221 while (!queue_.empty()) { |
221 ProcessTask* task = queue_.front(); | 222 rtc::QueuedTask* task = queue_.front(); |
222 queue_.pop(); | 223 queue_.pop(); |
223 lock_.Leave(); | 224 lock_.Leave(); |
224 task->Run(); | 225 task->Run(); |
225 delete task; | 226 delete task; |
226 lock_.Enter(); | 227 lock_.Enter(); |
227 } | 228 } |
228 } | 229 } |
229 | 230 |
230 int64_t time_to_wait = next_checkpoint - rtc::TimeMillis(); | 231 int64_t time_to_wait = next_checkpoint - rtc::TimeMillis(); |
231 if (time_to_wait > 0) | 232 if (time_to_wait > 0) |
232 wake_up_->Wait(static_cast<unsigned long>(time_to_wait)); | 233 wake_up_->Wait(static_cast<unsigned long>(time_to_wait)); |
233 | 234 |
234 return true; | 235 return true; |
235 } | 236 } |
236 } // namespace webrtc | 237 } // namespace webrtc |
OLD | NEW |