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

Unified Diff: third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp

Issue 2432543002: Refactoring WorkletThreadBackingHolder with template pattern (Closed)
Patch Set: Fixing typos Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp b/third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp
index f59c7373237c228e98fdabb450050777484a7da2..d14a93743972e2cf3dbe0c668a40615c2f89ed56 100644
--- a/third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.cpp
@@ -6,7 +6,6 @@
#include "core/workers/WorkerBackingThread.h"
#include "core/workers/WorkerThreadStartupData.h"
-#include "core/workers/WorkletBackingThreadHolder.h"
#include "modules/webaudio/AudioWorkletGlobalScope.h"
#include "platform/CrossThreadFunctional.h"
#include "platform/WaitableEvent.h"
@@ -20,66 +19,7 @@
namespace blink {
-namespace {
-
-// TODO(hongchan): consider refactoring static methods in this class into
-// a template class.
-class AudioWorkletThreadHolder final : public WorkletBackingThreadHolder {
- public:
- static AudioWorkletThreadHolder* instance() {
- MutexLocker locker(holderInstanceMutex());
- return s_instance;
- }
-
- static void ensureInstance() {
- if (!s_instance)
- s_instance = new AudioWorkletThreadHolder;
- }
-
- static void clear() {
- MutexLocker locker(holderInstanceMutex());
- if (s_instance) {
- s_instance->shutdownAndWait();
- delete s_instance;
- s_instance = nullptr;
- }
- }
-
- static void createForTest() {
- MutexLocker locker(holderInstanceMutex());
- DCHECK_EQ(nullptr, s_instance);
- s_instance =
- new AudioWorkletThreadHolder(WorkerBackingThread::createForTest(
- "AudioWorkletThread", BlinkGC::PerThreadHeapMode));
- }
-
- private:
- AudioWorkletThreadHolder(
- std::unique_ptr<WorkerBackingThread> backingThread = nullptr)
- : WorkletBackingThreadHolder(
- backingThread
- ? std::move(backingThread)
- : WorkerBackingThread::create("AudioWorkletThread",
- BlinkGC::PerThreadHeapMode)) {}
-
- static Mutex& holderInstanceMutex() {
- DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, holderMutex, new Mutex);
- return holderMutex;
- }
-
- void initializeOnThread() {
- MutexLocker locker(holderInstanceMutex());
- DCHECK(!m_initialized);
- m_thread->initialize();
- m_initialized = true;
- }
-
- static AudioWorkletThreadHolder* s_instance;
-};
-
-AudioWorkletThreadHolder* AudioWorkletThreadHolder::s_instance = nullptr;
-
-} // namespace
+template class WorkletThreadHolder<AudioWorkletThread>;
std::unique_ptr<AudioWorkletThread> AudioWorkletThread::create(
PassRefPtr<WorkerLoaderProxy> workerLoaderProxy,
@@ -99,7 +39,8 @@ AudioWorkletThread::AudioWorkletThread(
AudioWorkletThread::~AudioWorkletThread() {}
WorkerBackingThread& AudioWorkletThread::workerBackingThread() {
- return *AudioWorkletThreadHolder::instance()->thread();
+ return *WorkletThreadHolder<AudioWorkletThread>::threadHolderInstance()
+ ->thread();
}
void collectAllGarbageOnAudioWorkletThread(WaitableEvent* doneEvent) {
@@ -110,10 +51,11 @@ void collectAllGarbageOnAudioWorkletThread(WaitableEvent* doneEvent) {
void AudioWorkletThread::collectAllGarbage() {
DCHECK(isMainThread());
WaitableEvent doneEvent;
- AudioWorkletThreadHolder* instance = AudioWorkletThreadHolder::instance();
- if (!instance)
+ WorkletThreadHolder<AudioWorkletThread>* threadHolderInstance =
+ WorkletThreadHolder<AudioWorkletThread>::threadHolderInstance();
+ if (!threadHolderInstance)
return;
- instance->thread()->backingThread().postTask(
+ threadHolderInstance->thread()->backingThread().postTask(
BLINK_FROM_HERE, crossThreadBind(&collectAllGarbageOnAudioWorkletThread,
crossThreadUnretained(&doneEvent)));
doneEvent.wait();
@@ -121,16 +63,18 @@ void AudioWorkletThread::collectAllGarbage() {
void AudioWorkletThread::ensureSharedBackingThread() {
DCHECK(isMainThread());
- AudioWorkletThreadHolder::ensureInstance();
+ WorkletThreadHolder<AudioWorkletThread>::ensureInstance(
+ "AudioWorkletThread", BlinkGC::PerThreadHeapMode);
}
void AudioWorkletThread::clearSharedBackingThread() {
DCHECK(isMainThread());
- AudioWorkletThreadHolder::clear();
+ WorkletThreadHolder<AudioWorkletThread>::clearInstance();
}
void AudioWorkletThread::createSharedBackingThreadForTest() {
- AudioWorkletThreadHolder::createForTest();
+ WorkletThreadHolder<AudioWorkletThread>::createForTest(
+ "AudioWorkletThread", BlinkGC::PerThreadHeapMode);
}
WorkerOrWorkletGlobalScope* AudioWorkletThread::createWorkerGlobalScope(
« no previous file with comments | « third_party/WebKit/Source/modules/webaudio/AudioWorkletThread.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698