Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/compositorworker/CompositorWorkerThread.h" | 5 #include "modules/compositorworker/CompositorWorkerThread.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/V8GCController.h" | 7 #include "bindings/core/v8/V8GCController.h" |
| 8 #include "bindings/core/v8/V8Initializer.h" | 8 #include "bindings/core/v8/V8Initializer.h" |
| 9 #include "core/workers/InProcessWorkerObjectProxy.h" | 9 #include "core/workers/InProcessWorkerObjectProxy.h" |
| 10 #include "core/workers/WorkerBackingThread.h" | 10 #include "core/workers/WorkerBackingThread.h" |
| 11 #include "core/workers/WorkerThreadStartupData.h" | 11 #include "core/workers/WorkerThreadStartupData.h" |
| 12 #include "modules/compositorworker/CompositorWorkerGlobalScope.h" | 12 #include "modules/compositorworker/CompositorWorkerGlobalScope.h" |
| 13 #include "platform/ThreadSafeFunctional.h" | 13 #include "platform/ThreadSafeFunctional.h" |
| 14 #include "platform/TraceEvent.h" | 14 #include "platform/TraceEvent.h" |
| 15 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
| 16 | 16 |
| 17 namespace blink { | 17 namespace blink { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // Tracks whether we have instantiated a BackingThreadHolder. | |
| 22 static bool s_hasBackingThreadHolder = false; | |
| 23 | |
| 21 // This is a singleton class holding the compositor worker thread in this | 24 // This is a singleton class holding the compositor worker thread in this |
| 22 // renderrer process. BackingThreadHolst::m_thread will never be cleared, | 25 // renderrer process. BackingThreadHolst::m_thread is cleared by |
|
haraken
2016/05/09 02:00:53
renderer
flackr
2016/05/10 18:07:39
Done.
| |
| 23 // but Oilpan and V8 are detached from the thread when the last compositor | 26 // ModulesInitializer::shutdown. |
| 24 // worker thread is gone. | |
| 25 // See WorkerThread::terminateAndWaitForAllWorkers for the process shutdown | 27 // See WorkerThread::terminateAndWaitForAllWorkers for the process shutdown |
| 26 // case. | 28 // case. |
| 27 class BackingThreadHolder { | 29 class BackingThreadHolder { |
| 28 public: | 30 public: |
| 29 static BackingThreadHolder& instance() | 31 static BackingThreadHolder& instance() |
| 30 { | 32 { |
| 31 DEFINE_THREAD_SAFE_STATIC_LOCAL(BackingThreadHolder, holder, new Backing ThreadHolder); | 33 DEFINE_THREAD_SAFE_STATIC_LOCAL(BackingThreadHolder, holder, new Backing ThreadHolder); |
| 34 s_hasBackingThreadHolder = true; | |
| 32 return holder; | 35 return holder; |
| 33 } | 36 } |
| 34 | 37 |
| 35 WorkerBackingThread* thread() { return m_thread.get(); } | 38 WorkerBackingThread* thread() { return m_thread.get(); } |
| 39 static void clear() | |
| 40 { | |
| 41 // Calling instance() if it has not already been called would create | |
| 42 // a backing thread so check if we have an instance first. | |
| 43 if (s_hasBackingThreadHolder) | |
|
haraken
2016/05/09 02:00:53
Just to confirm: The access to s_hasBackingThreadH
flackr
2016/05/10 18:07:39
Right.
| |
| 44 instance().m_thread = nullptr; | |
| 45 } | |
| 36 void resetForTest() | 46 void resetForTest() |
| 37 { | 47 { |
| 38 ASSERT(!m_thread || (m_thread->workerScriptCount() == 0)); | 48 ASSERT(!m_thread || (m_thread->workerScriptCount() == 0)); |
| 39 m_thread = nullptr; | 49 m_thread = nullptr; |
| 40 m_thread = WorkerBackingThread::createForTest(Platform::current()->compo sitorThread()); | 50 m_thread = WorkerBackingThread::createForTest(Platform::current()->compo sitorThread()); |
| 41 } | 51 } |
| 42 | 52 |
| 43 private: | 53 private: |
| 44 BackingThreadHolder() : m_thread(WorkerBackingThread::create(Platform::curre nt()->compositorThread())) {} | 54 BackingThreadHolder() : m_thread(WorkerBackingThread::create(Platform::curre nt()->compositorThread())) {} |
| 45 | 55 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 70 { | 80 { |
| 71 return *BackingThreadHolder::instance().thread(); | 81 return *BackingThreadHolder::instance().thread(); |
| 72 } | 82 } |
| 73 | 83 |
| 74 WorkerGlobalScope*CompositorWorkerThread::createWorkerGlobalScope(PassOwnPtr<Wor kerThreadStartupData> startupData) | 84 WorkerGlobalScope*CompositorWorkerThread::createWorkerGlobalScope(PassOwnPtr<Wor kerThreadStartupData> startupData) |
| 75 { | 85 { |
| 76 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork erThread::createWorkerGlobalScope"); | 86 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork erThread::createWorkerGlobalScope"); |
| 77 return CompositorWorkerGlobalScope::create(this, std::move(startupData), m_t imeOrigin); | 87 return CompositorWorkerGlobalScope::create(this, std::move(startupData), m_t imeOrigin); |
| 78 } | 88 } |
| 79 | 89 |
| 90 void CompositorWorkerThread::ensureSharedBackingThread() | |
| 91 { | |
| 92 BackingThreadHolder::instance(); | |
| 93 } | |
| 94 | |
| 95 void CompositorWorkerThread::clearSharedBackingThread() | |
| 96 { | |
| 97 BackingThreadHolder::clear(); | |
| 98 } | |
| 99 | |
| 80 void CompositorWorkerThread::resetSharedBackingThreadForTest() | 100 void CompositorWorkerThread::resetSharedBackingThreadForTest() |
| 81 { | 101 { |
| 82 BackingThreadHolder::instance().resetForTest(); | 102 BackingThreadHolder::instance().resetForTest(); |
| 83 } | 103 } |
| 84 | 104 |
| 85 } // namespace blink | 105 } // namespace blink |
| OLD | NEW |