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