Commit 08db81c8 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

Worker: Remove unnecessary functions from worklet thread management

For evolution of worklet thread management there're some dead or duplicate
functions in worklet codebase. This CL removes them for cleanup.

Bug: n/a
Change-Id: I744146854e7f1cbcbb1a48cc60bac6cae34cad35
Reviewed-on: https://chromium-review.googlesource.com/c/1257475Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596194}
parent 1a620d46
...@@ -72,7 +72,7 @@ class ThreadedWorkletThreadForTest : public WorkerThread { ...@@ -72,7 +72,7 @@ class ThreadedWorkletThreadForTest : public WorkerThread {
static void EnsureSharedBackingThread() { static void EnsureSharedBackingThread() {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
WorkletThreadHolder<ThreadedWorkletThreadForTest>::CreateForTest( WorkletThreadHolder<ThreadedWorkletThreadForTest>::EnsureInstance(
WebThreadCreationParams(WebThreadType::kTestThread) WebThreadCreationParams(WebThreadType::kTestThread)
.SetThreadNameForTest("ThreadedWorkletThreadForTest")); .SetThreadNameForTest("ThreadedWorkletThreadForTest"));
} }
......
...@@ -61,12 +61,7 @@ void SetRAILModeOnWorkerThreadIsolates(v8::RAILMode rail_mode) { ...@@ -61,12 +61,7 @@ void SetRAILModeOnWorkerThreadIsolates(v8::RAILMode rail_mode) {
} }
WorkerBackingThread::WorkerBackingThread(const WebThreadCreationParams& params) WorkerBackingThread::WorkerBackingThread(const WebThreadCreationParams& params)
: backing_thread_(WebThreadSupportingGC::Create(params)), : backing_thread_(WebThreadSupportingGC::Create(params)) {}
is_owning_thread_(true) {}
WorkerBackingThread::WorkerBackingThread(WebThread* thread)
: backing_thread_(WebThreadSupportingGC::CreateForThread(thread)),
is_owning_thread_(false) {}
WorkerBackingThread::~WorkerBackingThread() = default; WorkerBackingThread::~WorkerBackingThread() = default;
...@@ -91,8 +86,7 @@ void WorkerBackingThread::InitializeOnBackingThread( ...@@ -91,8 +86,7 @@ void WorkerBackingThread::InitializeOnBackingThread(
isolate_, std::make_unique<V8IdleTaskRunner>( isolate_, std::make_unique<V8IdleTaskRunner>(
BackingThread().PlatformThread().Scheduler())); BackingThread().PlatformThread().Scheduler()));
} }
if (is_owning_thread_) Platform::Current()->DidStartWorkerThread();
Platform::Current()->DidStartWorkerThread();
V8PerIsolateData::From(isolate_)->SetThreadDebugger( V8PerIsolateData::From(isolate_)->SetThreadDebugger(
std::make_unique<WorkerThreadDebugger>(isolate_)); std::make_unique<WorkerThreadDebugger>(isolate_));
...@@ -111,8 +105,7 @@ void WorkerBackingThread::InitializeOnBackingThread( ...@@ -111,8 +105,7 @@ void WorkerBackingThread::InitializeOnBackingThread(
void WorkerBackingThread::ShutdownOnBackingThread() { void WorkerBackingThread::ShutdownOnBackingThread() {
DCHECK(backing_thread_->IsCurrentThread()); DCHECK(backing_thread_->IsCurrentThread());
if (is_owning_thread_) Platform::Current()->WillStopWorkerThread();
Platform::Current()->WillStopWorkerThread();
V8PerIsolateData::WillBeDestroyed(isolate_); V8PerIsolateData::WillBeDestroyed(isolate_);
V8GCController::ClearDOMWrappers(isolate_); V8GCController::ClearDOMWrappers(isolate_);
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
namespace blink { namespace blink {
class WebThread;
class WebThreadSupportingGC; class WebThreadSupportingGC;
struct WebThreadCreationParams; struct WebThreadCreationParams;
struct WorkerBackingThreadStartupData; struct WorkerBackingThreadStartupData;
...@@ -31,9 +30,6 @@ class CORE_EXPORT WorkerBackingThread final { ...@@ -31,9 +30,6 @@ class CORE_EXPORT WorkerBackingThread final {
const WebThreadCreationParams& params) { const WebThreadCreationParams& params) {
return base::WrapUnique(new WorkerBackingThread(params)); return base::WrapUnique(new WorkerBackingThread(params));
} }
static std::unique_ptr<WorkerBackingThread> Create(WebThread* thread) {
return base::WrapUnique(new WorkerBackingThread(thread));
}
~WorkerBackingThread(); ~WorkerBackingThread();
...@@ -58,11 +54,9 @@ class CORE_EXPORT WorkerBackingThread final { ...@@ -58,11 +54,9 @@ class CORE_EXPORT WorkerBackingThread final {
private: private:
explicit WorkerBackingThread(const WebThreadCreationParams&); explicit WorkerBackingThread(const WebThreadCreationParams&);
explicit WorkerBackingThread(WebThread*);
std::unique_ptr<WebThreadSupportingGC> backing_thread_; std::unique_ptr<WebThreadSupportingGC> backing_thread_;
v8::Isolate* isolate_ = nullptr; v8::Isolate* isolate_ = nullptr;
bool is_owning_thread_;
}; };
} // namespace blink } // namespace blink
......
...@@ -33,29 +33,6 @@ class WorkletThreadHolder { ...@@ -33,29 +33,6 @@ class WorkletThreadHolder {
thread_holder_instance_->Initialize(WorkerBackingThread::Create(params)); thread_holder_instance_->Initialize(WorkerBackingThread::Create(params));
} }
static void EnsureInstance(WebThread* thread) {
DCHECK(IsMainThread());
MutexLocker locker(HolderInstanceMutex());
if (thread_holder_instance_)
return;
thread_holder_instance_ = new WorkletThreadHolder<DerivedWorkletThread>;
thread_holder_instance_->Initialize(WorkerBackingThread::Create(thread));
}
static void CreateForTest(const WebThreadCreationParams& params) {
MutexLocker locker(HolderInstanceMutex());
DCHECK(!thread_holder_instance_);
thread_holder_instance_ = new WorkletThreadHolder<DerivedWorkletThread>;
thread_holder_instance_->Initialize(WorkerBackingThread::Create(params));
}
static void CreateForTest(WebThread* thread) {
MutexLocker locker(HolderInstanceMutex());
DCHECK(!thread_holder_instance_);
thread_holder_instance_ = new WorkletThreadHolder<DerivedWorkletThread>;
thread_holder_instance_->Initialize(WorkerBackingThread::Create(thread));
}
static void ClearInstance() { static void ClearInstance() {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
MutexLocker locker(HolderInstanceMutex()); MutexLocker locker(HolderInstanceMutex());
...@@ -87,10 +64,8 @@ class WorkletThreadHolder { ...@@ -87,10 +64,8 @@ class WorkletThreadHolder {
void InitializeOnWorkletThread() { void InitializeOnWorkletThread() {
MutexLocker locker(HolderInstanceMutex()); MutexLocker locker(HolderInstanceMutex());
DCHECK(!initialized_);
thread_->InitializeOnBackingThread( thread_->InitializeOnBackingThread(
WorkerBackingThreadStartupData::CreateDefault()); WorkerBackingThreadStartupData::CreateDefault());
initialized_ = true;
} }
void ShutdownAndWait() { void ShutdownAndWait() {
...@@ -110,7 +85,6 @@ class WorkletThreadHolder { ...@@ -110,7 +85,6 @@ class WorkletThreadHolder {
} }
std::unique_ptr<WorkerBackingThread> thread_; std::unique_ptr<WorkerBackingThread> thread_;
bool initialized_ = false;
static WorkletThreadHolder<DerivedWorkletThread>* thread_holder_instance_; static WorkletThreadHolder<DerivedWorkletThread>* thread_holder_instance_;
}; };
......
...@@ -57,7 +57,7 @@ class AnimationWorkletGlobalScopeTest : public PageTestBase { ...@@ -57,7 +57,7 @@ class AnimationWorkletGlobalScopeTest : public PageTestBase {
AnimationWorkletGlobalScopeTest() = default; AnimationWorkletGlobalScopeTest() = default;
void SetUp() override { void SetUp() override {
AnimationWorkletThread::CreateSharedBackingThreadForTest(); AnimationWorkletThread::EnsureSharedBackingThread();
PageTestBase::SetUp(IntSize()); PageTestBase::SetUp(IntSize());
Document* document = &GetDocument(); Document* document = &GetDocument();
document->SetURL(KURL("https://example.com/")); document->SetURL(KURL("https://example.com/"));
......
...@@ -31,12 +31,6 @@ AnimationWorkletThread::AnimationWorkletThread( ...@@ -31,12 +31,6 @@ AnimationWorkletThread::AnimationWorkletThread(
AnimationWorkletThread::~AnimationWorkletThread() = default; AnimationWorkletThread::~AnimationWorkletThread() = default;
WebThread* AnimationWorkletThread::GetSharedBackingThread() {
auto* instance = WorkletThreadHolder<AnimationWorkletThread>::GetInstance();
DCHECK(instance);
return &(instance->GetThread()->BackingThread().PlatformThread());
}
WorkerBackingThread& AnimationWorkletThread::GetWorkerBackingThread() { WorkerBackingThread& AnimationWorkletThread::GetWorkerBackingThread() {
return *WorkletThreadHolder<AnimationWorkletThread>::GetInstance() return *WorkletThreadHolder<AnimationWorkletThread>::GetInstance()
->GetThread(); ->GetThread();
...@@ -68,11 +62,6 @@ void AnimationWorkletThread::ClearSharedBackingThread() { ...@@ -68,11 +62,6 @@ void AnimationWorkletThread::ClearSharedBackingThread() {
WorkletThreadHolder<AnimationWorkletThread>::ClearInstance(); WorkletThreadHolder<AnimationWorkletThread>::ClearInstance();
} }
void AnimationWorkletThread::CreateSharedBackingThreadForTest() {
WorkletThreadHolder<AnimationWorkletThread>::CreateForTest(
WebThreadCreationParams(WebThreadType::kAnimationWorkletThread));
}
WorkerOrWorkletGlobalScope* AnimationWorkletThread::CreateWorkerGlobalScope( WorkerOrWorkletGlobalScope* AnimationWorkletThread::CreateWorkerGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params) { std::unique_ptr<GlobalScopeCreationParams> creation_params) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("animation-worklet"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("animation-worklet"),
......
...@@ -32,13 +32,6 @@ class MODULES_EXPORT AnimationWorkletThread final : public WorkerThread { ...@@ -32,13 +32,6 @@ class MODULES_EXPORT AnimationWorkletThread final : public WorkerThread {
static void EnsureSharedBackingThread(); static void EnsureSharedBackingThread();
static void ClearSharedBackingThread(); static void ClearSharedBackingThread();
static void CreateSharedBackingThreadForTest();
// This only can be called after EnsureSharedBackingThread() is performed.
// Currently AnimationWorkletThread owns only one thread and it is shared
// by all the customers.
static WebThread* GetSharedBackingThread();
private: private:
explicit AnimationWorkletThread(WorkerReportingProxy&); explicit AnimationWorkletThread(WorkerReportingProxy&);
......
...@@ -48,7 +48,7 @@ class TestAnimationWorkletProxyClient : public AnimationWorkletProxyClient { ...@@ -48,7 +48,7 @@ class TestAnimationWorkletProxyClient : public AnimationWorkletProxyClient {
class AnimationWorkletThreadTest : public PageTestBase { class AnimationWorkletThreadTest : public PageTestBase {
public: public:
void SetUp() override { void SetUp() override {
AnimationWorkletThread::CreateSharedBackingThreadForTest(); AnimationWorkletThread::EnsureSharedBackingThread();
PageTestBase::SetUp(IntSize()); PageTestBase::SetUp(IntSize());
Document* document = &GetDocument(); Document* document = &GetDocument();
document->SetURL(KURL("https://example.com/")); document->SetURL(KURL("https://example.com/"));
......
...@@ -55,7 +55,7 @@ static const size_t kRenderQuantumFrames = 128; ...@@ -55,7 +55,7 @@ static const size_t kRenderQuantumFrames = 128;
class AudioWorkletGlobalScopeTest : public PageTestBase { class AudioWorkletGlobalScopeTest : public PageTestBase {
public: public:
void SetUp() override { void SetUp() override {
AudioWorkletThread::CreateSharedBackingThreadForTest(); AudioWorkletThread::EnsureSharedBackingThread();
PageTestBase::SetUp(IntSize()); PageTestBase::SetUp(IntSize());
Document* document = &GetDocument(); Document* document = &GetDocument();
document->SetURL(KURL("https://example.com/")); document->SetURL(KURL("https://example.com/"));
......
...@@ -82,18 +82,6 @@ void AudioWorkletThread::ClearSharedBackingThread() { ...@@ -82,18 +82,6 @@ void AudioWorkletThread::ClearSharedBackingThread() {
WorkletThreadHolder<AudioWorkletThread>::ClearInstance(); WorkletThreadHolder<AudioWorkletThread>::ClearInstance();
} }
WebThread* AudioWorkletThread::GetSharedBackingThread() {
DCHECK(IsMainThread());
WorkletThreadHolder<AudioWorkletThread>* instance =
WorkletThreadHolder<AudioWorkletThread>::GetInstance();
return &(instance->GetThread()->BackingThread().PlatformThread());
}
void AudioWorkletThread::CreateSharedBackingThreadForTest() {
WorkletThreadHolder<AudioWorkletThread>::CreateForTest(
WebThreadCreationParams(blink::WebThreadType::kWebAudioThread));
}
WorkerOrWorkletGlobalScope* AudioWorkletThread::CreateWorkerGlobalScope( WorkerOrWorkletGlobalScope* AudioWorkletThread::CreateWorkerGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params) { std::unique_ptr<GlobalScopeCreationParams> creation_params) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("audio-worklet"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("audio-worklet"),
......
...@@ -34,13 +34,6 @@ class MODULES_EXPORT AudioWorkletThread final : public WorkerThread { ...@@ -34,13 +34,6 @@ class MODULES_EXPORT AudioWorkletThread final : public WorkerThread {
static void EnsureSharedBackingThread(); static void EnsureSharedBackingThread();
static void ClearSharedBackingThread(); static void ClearSharedBackingThread();
static void CreateSharedBackingThreadForTest();
// This only can be called after EnsureSharedBackingThread() is performed.
// Currently AudioWorkletThread owns only one thread and it is shared by all
// the customers.
static WebThread* GetSharedBackingThread();
private: private:
explicit AudioWorkletThread(WorkerReportingProxy&); explicit AudioWorkletThread(WorkerReportingProxy&);
......
...@@ -39,7 +39,7 @@ namespace blink { ...@@ -39,7 +39,7 @@ namespace blink {
class AudioWorkletThreadTest : public PageTestBase { class AudioWorkletThreadTest : public PageTestBase {
public: public:
void SetUp() override { void SetUp() override {
AudioWorkletThread::CreateSharedBackingThreadForTest(); AudioWorkletThread::EnsureSharedBackingThread();
PageTestBase::SetUp(IntSize()); PageTestBase::SetUp(IntSize());
Document* document = &GetDocument(); Document* document = &GetDocument();
document->SetURL(KURL("https://example.com/")); document->SetURL(KURL("https://example.com/"));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment