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

Side by Side Diff: webrtc/modules/utility/source/process_thread_impl.cc

Issue 1335923002: Add RTC_ prefix to (D)CHECKs and related macros. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase. Created 5 years, 3 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 /* 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
(...skipping 30 matching lines...) Expand all
41 return rtc::scoped_ptr<ProcessThread>(new ProcessThreadImpl(thread_name)) 41 return rtc::scoped_ptr<ProcessThread>(new ProcessThreadImpl(thread_name))
42 .Pass(); 42 .Pass();
43 } 43 }
44 44
45 ProcessThreadImpl::ProcessThreadImpl(const char* thread_name) 45 ProcessThreadImpl::ProcessThreadImpl(const char* thread_name)
46 : wake_up_(EventWrapper::Create()), 46 : wake_up_(EventWrapper::Create()),
47 stop_(false), 47 stop_(false),
48 thread_name_(thread_name) {} 48 thread_name_(thread_name) {}
49 49
50 ProcessThreadImpl::~ProcessThreadImpl() { 50 ProcessThreadImpl::~ProcessThreadImpl() {
51 DCHECK(thread_checker_.CalledOnValidThread()); 51 RTC_DCHECK(thread_checker_.CalledOnValidThread());
52 DCHECK(!thread_.get()); 52 RTC_DCHECK(!thread_.get());
53 DCHECK(!stop_); 53 RTC_DCHECK(!stop_);
54 54
55 while (!queue_.empty()) { 55 while (!queue_.empty()) {
56 delete queue_.front(); 56 delete queue_.front();
57 queue_.pop(); 57 queue_.pop();
58 } 58 }
59 } 59 }
60 60
61 void ProcessThreadImpl::Start() { 61 void ProcessThreadImpl::Start() {
62 DCHECK(thread_checker_.CalledOnValidThread()); 62 RTC_DCHECK(thread_checker_.CalledOnValidThread());
63 DCHECK(!thread_.get()); 63 RTC_DCHECK(!thread_.get());
64 if (thread_.get()) 64 if (thread_.get())
65 return; 65 return;
66 66
67 DCHECK(!stop_); 67 RTC_DCHECK(!stop_);
68 68
69 { 69 {
70 // TODO(tommi): Since DeRegisterModule is currently being called from 70 // TODO(tommi): Since DeRegisterModule is currently being called from
71 // different threads in some cases (ChannelOwner), we need to lock access to 71 // different threads in some cases (ChannelOwner), we need to lock access to
72 // the modules_ collection even on the controller thread. 72 // the modules_ collection even on the controller thread.
73 // Once we've cleaned up those places, we can remove this lock. 73 // Once we've cleaned up those places, we can remove this lock.
74 rtc::CritScope lock(&lock_); 74 rtc::CritScope lock(&lock_);
75 for (ModuleCallback& m : modules_) 75 for (ModuleCallback& m : modules_)
76 m.module->ProcessThreadAttached(this); 76 m.module->ProcessThreadAttached(this);
77 } 77 }
78 78
79 thread_ = ThreadWrapper::CreateThread(&ProcessThreadImpl::Run, this, 79 thread_ = ThreadWrapper::CreateThread(&ProcessThreadImpl::Run, this,
80 thread_name_); 80 thread_name_);
81 CHECK(thread_->Start()); 81 RTC_CHECK(thread_->Start());
82 } 82 }
83 83
84 void ProcessThreadImpl::Stop() { 84 void ProcessThreadImpl::Stop() {
85 DCHECK(thread_checker_.CalledOnValidThread()); 85 RTC_DCHECK(thread_checker_.CalledOnValidThread());
86 if(!thread_.get()) 86 if(!thread_.get())
87 return; 87 return;
88 88
89 { 89 {
90 rtc::CritScope lock(&lock_); 90 rtc::CritScope lock(&lock_);
91 stop_ = true; 91 stop_ = true;
92 } 92 }
93 93
94 wake_up_->Set(); 94 wake_up_->Set();
95 95
96 CHECK(thread_->Stop()); 96 RTC_CHECK(thread_->Stop());
97 stop_ = false; 97 stop_ = false;
98 98
99 // TODO(tommi): Since DeRegisterModule is currently being called from 99 // TODO(tommi): Since DeRegisterModule is currently being called from
100 // different threads in some cases (ChannelOwner), we need to lock access to 100 // different threads in some cases (ChannelOwner), we need to lock access to
101 // the modules_ collection even on the controller thread. 101 // the modules_ collection even on the controller thread.
102 // Since DeRegisterModule also checks thread_, we also need to hold the 102 // Since DeRegisterModule also checks thread_, we also need to hold the
103 // lock for the .reset() operation. 103 // lock for the .reset() operation.
104 // Once we've cleaned up those places, we can remove this lock. 104 // Once we've cleaned up those places, we can remove this lock.
105 rtc::CritScope lock(&lock_); 105 rtc::CritScope lock(&lock_);
106 thread_.reset(); 106 thread_.reset();
(...skipping 16 matching lines...) Expand all
123 void ProcessThreadImpl::PostTask(rtc::scoped_ptr<ProcessTask> task) { 123 void ProcessThreadImpl::PostTask(rtc::scoped_ptr<ProcessTask> task) {
124 // Allowed to be called on any thread. 124 // Allowed to be called on any thread.
125 { 125 {
126 rtc::CritScope lock(&lock_); 126 rtc::CritScope lock(&lock_);
127 queue_.push(task.release()); 127 queue_.push(task.release());
128 } 128 }
129 wake_up_->Set(); 129 wake_up_->Set();
130 } 130 }
131 131
132 void ProcessThreadImpl::RegisterModule(Module* module) { 132 void ProcessThreadImpl::RegisterModule(Module* module) {
133 DCHECK(thread_checker_.CalledOnValidThread()); 133 RTC_DCHECK(thread_checker_.CalledOnValidThread());
134 DCHECK(module); 134 RTC_DCHECK(module);
135 135
136 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)) 136 #if (!defined(NDEBUG) || defined(DCHECK_ALWAYS_ON))
137 { 137 {
138 // Catch programmer error. 138 // Catch programmer error.
139 rtc::CritScope lock(&lock_); 139 rtc::CritScope lock(&lock_);
140 for (const ModuleCallback& mc : modules_) 140 for (const ModuleCallback& mc : modules_)
141 DCHECK(mc.module != module); 141 RTC_DCHECK(mc.module != module);
142 } 142 }
143 #endif 143 #endif
144 144
145 // Now that we know the module isn't in the list, we'll call out to notify 145 // Now that we know the module isn't in the list, we'll call out to notify
146 // the module that it's attached to the worker thread. We don't hold 146 // the module that it's attached to the worker thread. We don't hold
147 // the lock while we make this call. 147 // the lock while we make this call.
148 if (thread_.get()) 148 if (thread_.get())
149 module->ProcessThreadAttached(this); 149 module->ProcessThreadAttached(this);
150 150
151 { 151 {
152 rtc::CritScope lock(&lock_); 152 rtc::CritScope lock(&lock_);
153 modules_.push_back(ModuleCallback(module)); 153 modules_.push_back(ModuleCallback(module));
154 } 154 }
155 155
156 // Wake the thread calling ProcessThreadImpl::Process() to update the 156 // Wake the thread calling ProcessThreadImpl::Process() to update the
157 // waiting time. The waiting time for the just registered module may be 157 // waiting time. The waiting time for the just registered module may be
158 // shorter than all other registered modules. 158 // shorter than all other registered modules.
159 wake_up_->Set(); 159 wake_up_->Set();
160 } 160 }
161 161
162 void ProcessThreadImpl::DeRegisterModule(Module* module) { 162 void ProcessThreadImpl::DeRegisterModule(Module* module) {
163 // Allowed to be called on any thread. 163 // Allowed to be called on any thread.
164 // TODO(tommi): Disallow this ^^^ 164 // TODO(tommi): Disallow this ^^^
165 DCHECK(module); 165 RTC_DCHECK(module);
166 166
167 { 167 {
168 rtc::CritScope lock(&lock_); 168 rtc::CritScope lock(&lock_);
169 modules_.remove_if([&module](const ModuleCallback& m) { 169 modules_.remove_if([&module](const ModuleCallback& m) {
170 return m.module == module; 170 return m.module == module;
171 }); 171 });
172 172
173 // TODO(tommi): we currently need to hold the lock while calling out to 173 // TODO(tommi): we currently need to hold the lock while calling out to
174 // ProcessThreadAttached. This is to make sure that the thread hasn't been 174 // ProcessThreadAttached. This is to make sure that the thread hasn't been
175 // destroyed while we attach the module. Once we can make sure 175 // destroyed while we attach the module. Once we can make sure
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 228 }
229 } 229 }
230 230
231 int64_t time_to_wait = next_checkpoint - TickTime::MillisecondTimestamp(); 231 int64_t time_to_wait = next_checkpoint - TickTime::MillisecondTimestamp();
232 if (time_to_wait > 0) 232 if (time_to_wait > 0)
233 wake_up_->Wait(static_cast<unsigned long>(time_to_wait)); 233 wake_up_->Wait(static_cast<unsigned long>(time_to_wait));
234 234
235 return true; 235 return true;
236 } 236 }
237 } // namespace webrtc 237 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/utility/source/jvm_android.cc ('k') | webrtc/modules/video_capture/ensure_initialized.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698