aboutsummaryrefslogtreecommitdiff
path: root/modules/utility/source/process_thread_impl.cc
diff options
context:
space:
mode:
Diffstat (limited to 'modules/utility/source/process_thread_impl.cc')
-rw-r--r--modules/utility/source/process_thread_impl.cc34
1 files changed, 14 insertions, 20 deletions
diff --git a/modules/utility/source/process_thread_impl.cc b/modules/utility/source/process_thread_impl.cc
index dc2a0066e9..73fc23400b 100644
--- a/modules/utility/source/process_thread_impl.cc
+++ b/modules/utility/source/process_thread_impl.cc
@@ -48,7 +48,6 @@ ProcessThreadImpl::ProcessThreadImpl(const char* thread_name)
ProcessThreadImpl::~ProcessThreadImpl() {
RTC_DCHECK(thread_checker_.IsCurrent());
- RTC_DCHECK(!thread_.get());
RTC_DCHECK(!stop_);
while (!delayed_tasks_.empty()) {
@@ -72,8 +71,8 @@ void ProcessThreadImpl::Delete() {
// Doesn't need locking, because the contending thread isn't running.
void ProcessThreadImpl::Start() RTC_NO_THREAD_SAFETY_ANALYSIS {
RTC_DCHECK(thread_checker_.IsCurrent());
- RTC_DCHECK(!thread_.get());
- if (thread_.get())
+ RTC_DCHECK(thread_.empty());
+ if (!thread_.empty())
return;
RTC_DCHECK(!stop_);
@@ -81,14 +80,18 @@ void ProcessThreadImpl::Start() RTC_NO_THREAD_SAFETY_ANALYSIS {
for (ModuleCallback& m : modules_)
m.module->ProcessThreadAttached(this);
- thread_.reset(
- new rtc::PlatformThread(&ProcessThreadImpl::Run, this, thread_name_));
- thread_->Start();
+ thread_ = rtc::PlatformThread::SpawnJoinable(
+ [this] {
+ CurrentTaskQueueSetter set_current(this);
+ while (Process()) {
+ }
+ },
+ thread_name_);
}
void ProcessThreadImpl::Stop() {
RTC_DCHECK(thread_checker_.IsCurrent());
- if (!thread_.get())
+ if (thread_.empty())
return;
{
@@ -98,9 +101,7 @@ void ProcessThreadImpl::Stop() {
}
wake_up_.Set();
-
- thread_->Stop();
- thread_.reset();
+ thread_.Finalize();
StopNoLocks();
}
@@ -108,7 +109,7 @@ void ProcessThreadImpl::Stop() {
// No locking needed, since this is called after the contending thread is
// stopped.
void ProcessThreadImpl::StopNoLocks() RTC_NO_THREAD_SAFETY_ANALYSIS {
- RTC_DCHECK(!thread_);
+ RTC_DCHECK(thread_.empty());
stop_ = false;
for (ModuleCallback& m : modules_)
@@ -179,6 +180,7 @@ void ProcessThreadImpl::PostDelayedTask(std::unique_ptr<QueuedTask> task,
void ProcessThreadImpl::RegisterModule(Module* module,
const rtc::Location& from) {
+ TRACE_EVENT0("webrtc", "ProcessThreadImpl::RegisterModule");
RTC_DCHECK(thread_checker_.IsCurrent());
RTC_DCHECK(module) << from.ToString();
@@ -199,7 +201,7 @@ void ProcessThreadImpl::RegisterModule(Module* module,
// Now that we know the module isn't in the list, we'll call out to notify
// the module that it's attached to the worker thread. We don't hold
// the lock while we make this call.
- if (thread_.get())
+ if (!thread_.empty())
module->ProcessThreadAttached(this);
{
@@ -227,14 +229,6 @@ void ProcessThreadImpl::DeRegisterModule(Module* module) {
module->ProcessThreadAttached(nullptr);
}
-// static
-void ProcessThreadImpl::Run(void* obj) {
- ProcessThreadImpl* impl = static_cast<ProcessThreadImpl*>(obj);
- CurrentTaskQueueSetter set_current(impl);
- while (impl->Process()) {
- }
-}
-
bool ProcessThreadImpl::Process() {
TRACE_EVENT1("webrtc", "ProcessThreadImpl", "name", thread_name_);
int64_t now = rtc::TimeMillis();