Add locks to Start(), Stop() methods in ProcessThread.
This is necessary unfortunately since there are a few places where DeRegisterModule does not reliably occur on the same thread.
BUG=4473
R=pbos@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/42979004
Cr-Commit-Position: refs/heads/master@{#8891}
diff --git a/webrtc/modules/utility/source/process_thread_impl.cc b/webrtc/modules/utility/source/process_thread_impl.cc
index 5b50539..6ebf4a2 100644
--- a/webrtc/modules/utility/source/process_thread_impl.cc
+++ b/webrtc/modules/utility/source/process_thread_impl.cc
@@ -66,8 +66,15 @@
DCHECK(!stop_);
- for (ModuleCallback& m : modules_)
- m.module->ProcessThreadAttached(this);
+ {
+ // TODO(tommi): Since DeRegisterModule is currently being called from
+ // different threads in some cases (ChannelOwner), we need to lock access to
+ // the modules_ collection even on the controller thread.
+ // Once we've cleaned up those places, we can remove this lock.
+ rtc::CritScope lock(&lock_);
+ for (ModuleCallback& m : modules_)
+ m.module->ProcessThreadAttached(this);
+ }
thread_ = ThreadWrapper::CreateThread(
&ProcessThreadImpl::Run, this, "ProcessThread");
@@ -90,12 +97,18 @@
thread_.reset();
stop_ = false;
+ // TODO(tommi): Since DeRegisterModule is currently being called from
+ // different threads in some cases (ChannelOwner), we need to lock access to
+ // the modules_ collection even on the controller thread.
+ // Once we've cleaned up those places, we can remove this lock.
+ rtc::CritScope lock(&lock_);
for (ModuleCallback& m : modules_)
m.module->ProcessThreadAttached(nullptr);
}
void ProcessThreadImpl::WakeUp(Module* module) {
// Allowed to be called on any thread.
+ // TODO(tommi): Disallow this ^^^
{
rtc::CritScope lock(&lock_);
for (ModuleCallback& m : modules_) {
@@ -108,6 +121,7 @@
void ProcessThreadImpl::PostTask(rtc::scoped_ptr<ProcessTask> task) {
// Allowed to be called on any thread.
+ // TODO(tommi): Disallow this ^^^
{
rtc::CritScope lock(&lock_);
queue_.push(task.release());