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

Unified Diff: third_party/WebKit/Source/modules/compositorworker/CompositorWorkerThread.cpp

Issue 1733353004: Introduce WorkerBackingThread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
Index: third_party/WebKit/Source/modules/compositorworker/CompositorWorkerThread.cpp
diff --git a/third_party/WebKit/Source/modules/compositorworker/CompositorWorkerThread.cpp b/third_party/WebKit/Source/modules/compositorworker/CompositorWorkerThread.cpp
index 0a20181a55c497ae829248ceb61d33b05173b6b1..6dcc9fcb4f08c25ca2338ef18f239136a04e10c7 100644
--- a/third_party/WebKit/Source/modules/compositorworker/CompositorWorkerThread.cpp
+++ b/third_party/WebKit/Source/modules/compositorworker/CompositorWorkerThread.cpp
@@ -6,6 +6,7 @@
#include "bindings/core/v8/V8GCController.h"
#include "bindings/core/v8/V8Initializer.h"
+#include "core/workers/WorkerBackingThread.h"
#include "core/workers/WorkerObjectProxy.h"
#include "core/workers/WorkerThreadStartupData.h"
#include "modules/compositorworker/CompositorWorkerGlobalScope.h"
@@ -17,122 +18,30 @@ namespace blink {
namespace {
-void destroyThread(WebThreadSupportingGC* thread)
-{
- ASSERT(isMainThread());
- // The destructor for |thread| will block until all tasks have completed.
- // This guarantees that shutdown will finish before the thread is destroyed.
- delete thread;
-}
-
-class CompositorWorkerSharedState {
+class BackingThreadHolder {
public:
- static CompositorWorkerSharedState& instance()
- {
- DEFINE_THREAD_SAFE_STATIC_LOCAL(CompositorWorkerSharedState, compositorWorkerSharedState, (new CompositorWorkerSharedState()));
- return compositorWorkerSharedState;
- }
-
- WebThreadSupportingGC* compositorWorkerThread()
+ static BackingThreadHolder& instance()
{
- MutexLocker lock(m_mutex);
- if (!m_thread && isMainThread()) {
- ASSERT(!m_workerCount);
- WebThread* platformThread = Platform::current()->compositorThread();
- m_thread = WebThreadSupportingGC::createForThread(platformThread);
- }
- return m_thread.get();
+ DEFINE_THREAD_SAFE_STATIC_LOCAL(BackingThreadHolder, holder, new BackingThreadHolder);
+ return holder;
}
- void initializeBackingThread()
+ PassRefPtr<WorkerBackingThread> thread() { return m_thread; }
+ void clear() { m_thread = nullptr; }
+ void resetForTest()
{
- MutexLocker lock(m_mutex);
- ASSERT(m_thread->isCurrentThread());
- ++m_workerCount;
- if (m_workerCount > 1)
- return;
-
- m_thread->initialize();
-
- // Initialize the isolate at the same time.
- ASSERT(!m_isolate);
- m_isolate = V8PerIsolateData::initialize();
- V8Initializer::initializeWorker(m_isolate);
-
- OwnPtr<V8IsolateInterruptor> interruptor = adoptPtr(new V8IsolateInterruptor(m_isolate));
- ThreadState::current()->addInterruptor(interruptor.release());
- ThreadState::current()->registerTraceDOMWrappers(m_isolate, V8GCController::traceDOMWrappers);
+ ASSERT(!m_thread || (m_thread->workerScriptCount() == 0));
+ m_thread = WorkerBackingThread::createForTest(Platform::current()->compositorThread());
}
- void shutdownBackingThread()
- {
- MutexLocker lock(m_mutex);
- ASSERT(m_thread->isCurrentThread());
- ASSERT(m_workerCount > 0);
- --m_workerCount;
- if (m_workerCount == 0) {
- m_thread->shutdown();
- Platform::current()->mainThread()->getWebTaskRunner()->postTask(
- BLINK_FROM_HERE, threadSafeBind(destroyThread, AllowCrossThreadAccess(m_thread.leakPtr())));
- }
- }
-
- v8::Isolate* initializeIsolate()
- {
- MutexLocker lock(m_mutex);
- ASSERT(m_thread->isCurrentThread());
- ASSERT(m_isolate);
- // It is safe to use the existing isolate even if TerminateExecution() has been
- // called on it, without calling CancelTerminateExecution().
- return m_isolate;
- }
-
- void willDestroyIsolate()
- {
- MutexLocker lock(m_mutex);
- ASSERT(m_thread->isCurrentThread());
- if (m_workerCount == 1)
- V8PerIsolateData::willBeDestroyed(m_isolate);
- }
-
- void destroyIsolate()
- {
- MutexLocker lock(m_mutex);
- if (!m_thread) {
- ASSERT(m_workerCount == 0);
- V8PerIsolateData::destroy(m_isolate);
- m_isolate = nullptr;
- }
- }
-
- void terminateV8Execution()
- {
- MutexLocker lock(m_mutex);
- ASSERT(isMainThread() || m_thread->isCurrentThread());
- if (m_workerCount > 1)
- return;
-
- m_isolate->TerminateExecution();
- }
-
- bool hasThreadForTest()
- {
- return m_thread;
- }
-
- bool hasIsolateForTest()
+private:
+ BackingThreadHolder()
{
- return m_isolate;
+ ASSERT(!m_thread || (m_thread->workerScriptCount() == 0));
kinuko 2016/03/31 09:19:28 When we're in ctor do we need these assertions?
yhirano 2016/04/04 11:29:15 Done.
+ m_thread = WorkerBackingThread::create(Platform::current()->compositorThread());
}
-private:
- CompositorWorkerSharedState() {}
- ~CompositorWorkerSharedState() {}
-
- Mutex m_mutex;
- OwnPtr<WebThreadSupportingGC> m_thread;
- int m_workerCount = 0;
- v8::Isolate* m_isolate = nullptr;
+ RefPtr<WorkerBackingThread> m_thread;
};
} // namespace
@@ -145,7 +54,7 @@ PassOwnPtr<CompositorWorkerThread> CompositorWorkerThread::create(PassRefPtr<Wor
}
CompositorWorkerThread::CompositorWorkerThread(PassRefPtr<WorkerLoaderProxy> workerLoaderProxy, WorkerObjectProxy& workerObjectProxy, double timeOrigin)
- : WorkerThread(workerLoaderProxy, workerObjectProxy)
+ : WorkerThread(workerLoaderProxy, workerObjectProxy, BackingThreadHolder::instance().thread())
, m_workerObjectProxy(workerObjectProxy)
, m_timeOrigin(timeOrigin)
{
@@ -155,65 +64,20 @@ CompositorWorkerThread::~CompositorWorkerThread()
{
}
-WebThreadSupportingGC* CompositorWorkerThread::sharedBackingThread()
-{
- return CompositorWorkerSharedState::instance().compositorWorkerThread();
-}
-
PassRefPtrWillBeRawPtr<WorkerGlobalScope> CompositorWorkerThread::createWorkerGlobalScope(PassOwnPtr<WorkerThreadStartupData> startupData)
{
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWorkerThread::createWorkerGlobalScope");
return CompositorWorkerGlobalScope::create(this, startupData, m_timeOrigin);
}
-WebThreadSupportingGC& CompositorWorkerThread::backingThread()
-{
- return *CompositorWorkerSharedState::instance().compositorWorkerThread();
-}
-
-void CompositorWorkerThread::initializeBackingThread()
-{
- TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWorkerThread::initializeBackingThread");
- CompositorWorkerSharedState::instance().initializeBackingThread();
-}
-
-void CompositorWorkerThread::shutdownBackingThread()
-{
- TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWorkerThread::shutdownBackingThread");
- CompositorWorkerSharedState::instance().shutdownBackingThread();
-}
-
-v8::Isolate* CompositorWorkerThread::initializeIsolate()
-{
- return CompositorWorkerSharedState::instance().initializeIsolate();
-}
-
-void CompositorWorkerThread::willDestroyIsolate()
-{
- TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWorkerThread::willDestroyIsolate");
- CompositorWorkerSharedState::instance().willDestroyIsolate();
-}
-
-void CompositorWorkerThread::destroyIsolate()
-{
- TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWorkerThread::destroyIsolate");
- CompositorWorkerSharedState::instance().destroyIsolate();
-}
-
-void CompositorWorkerThread::terminateV8Execution()
-{
- TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWorkerThread::terminateV8Execution");
- CompositorWorkerSharedState::instance().terminateV8Execution();
-}
-
-bool CompositorWorkerThread::hasThreadForTest()
+void CompositorWorkerThread::clearSharedBackingThread()
{
- return CompositorWorkerSharedState::instance().hasThreadForTest();
+ BackingThreadHolder::instance().clear();
}
-bool CompositorWorkerThread::hasIsolateForTest()
+void CompositorWorkerThread::resetSharedBackingThreadForTest()
{
- return CompositorWorkerSharedState::instance().hasIsolateForTest();
+ BackingThreadHolder::instance().resetForTest();
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698