Add thread check to ModuleProcessThread::DeRegisterModule and remove all unnecessary locking that was there due to one implementation calling from a different thread.

The only thing that was holding us back was the indeterministic teardown of voe::Channel(), but it turned out that fixing it wasn't that hard :)

BUG=webrtc:4508

Review-Url: https://codereview.webrtc.org/2755273004
Cr-Commit-Position: refs/heads/master@{#17315}
This commit is contained in:
tommi
2017-03-21 02:31:51 -07:00
committed by Commit bot
parent 3257b16156
commit 0a2391f74c
4 changed files with 73 additions and 71 deletions

View File

@ -67,15 +67,8 @@ void ProcessThreadImpl::Start() {
RTC_DCHECK(!stop_);
{
// 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);
}
for (ModuleCallback& m : modules_)
m.module->ProcessThreadAttached(this);
thread_.reset(
new rtc::PlatformThread(&ProcessThreadImpl::Run, this, thread_name_));
@ -97,13 +90,6 @@ void ProcessThreadImpl::Stop() {
thread_->Stop();
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.
// Since DeRegisterModule also checks thread_, we also need to hold the
// lock for the .reset() operation.
// Once we've cleaned up those places, we can remove this lock.
rtc::CritScope lock(&lock_);
thread_.reset();
for (ModuleCallback& m : modules_)
m.module->ProcessThreadAttached(nullptr);
@ -162,8 +148,7 @@ void ProcessThreadImpl::RegisterModule(Module* module,
}
void ProcessThreadImpl::DeRegisterModule(Module* module) {
// Allowed to be called on any thread.
// TODO(tommi): Disallow this ^^^
RTC_DCHECK(thread_checker_.CalledOnValidThread());
RTC_DCHECK(module);
{
@ -171,18 +156,10 @@ void ProcessThreadImpl::DeRegisterModule(Module* module) {
modules_.remove_if([&module](const ModuleCallback& m) {
return m.module == module;
});
// TODO(tommi): we currently need to hold the lock while calling out to
// ProcessThreadAttached. This is to make sure that the thread hasn't been
// destroyed while we attach the module. Once we can make sure
// DeRegisterModule isn't being called on arbitrary threads, we can move the
// |if (thread_.get())| check and ProcessThreadAttached() call outside the
// lock scope.
// Notify the module that it's been detached.
if (thread_.get())
module->ProcessThreadAttached(nullptr);
}
// Notify the module that it's been detached.
module->ProcessThreadAttached(nullptr);
}
// static